Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bitfield width in ngx_http_conf_addr_t, keep CAP_NET_BIND_SERVICE #1905

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

iczero
Copy link

@iczero iczero commented Dec 18, 2023

In src/http/ngx_http.c function ngx_http_add_addresses, the following code is present:

#if (NGX_HTTP_SSL)
        ssl = lsopt->ssl || addr[i].opt.ssl;
        protocols |= lsopt->ssl << 1;
        protocols_prev |= addr[i].opt.ssl << 1;
#endif
#if (NGX_HTTP_V2)
        http2 = lsopt->http2 || addr[i].opt.http2;
        protocols |= lsopt->http2 << 2;
        protocols_prev |= addr[i].opt.http2 << 2;
#endif
#if (T_NGX_XQUIC)
        xquic = lsopt->xquic || addr[i].opt.xquic;
        protocols |= lsopt->xquic << 3;
        protocols_prev |= addr[i].opt.xquic << 3;
#endif
#if (T_NGX_HAVE_XUDP)
        xudp = lsopt->xudp || addr[i].opt.xudp || port->xudp;
        protocols |= lsopt->xudp << 4;
        protocols_prev |= addr[i].opt.xudp << 4;
#endif
#if (T_NGX_HTTPS_ALLOW_HTTP)
        https_allow_http = lsopt->https_allow_http || addr[i].opt.https_allow_http;
#endif

// ...

            addr[i].protocols = protocols;
            addr[i].protocols_set = 1;

This assumes the protocols field has width 5 but it is only width 3. This corrupts the next field and causes strange errors. This is fixed by increasing the width to 5 bits.

@CLAassistant
Copy link

CLAassistant commented Dec 18, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@iczero iczero changed the title Fix bitfield width in ngx_http_conf_addr_t Fix bitfield width in ngx_http_conf_addr_t, keep CAP_NET_BIND_SERVICE Dec 18, 2023
@iczero
Copy link
Author

iczero commented Dec 18, 2023

XQUIC requires privileged bind() to low ports from worker processes. It will error after setuid() if not running as user root. This will keep the CAP_NET_BIND_SERVICE capability so it can bind without issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants