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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/http/ngx_http_core_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ typedef struct {
typedef struct {
ngx_http_listen_opt_t opt;

unsigned protocols:3;
unsigned protocols:5;
unsigned protocols_set:1;
unsigned protocols_changed:1;

Expand Down
22 changes: 16 additions & 6 deletions src/os/unix/ngx_process_cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,17 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
}

#if (NGX_HAVE_PR_SET_KEEPCAPS && NGX_HAVE_CAPABILITIES)
unsigned int cap_mask = 0;

if (ccf->transparent && ccf->user) {
cap_mask |= CAP_TO_MASK(CAP_NET_RAW);
}

#if (T_NGX_XQUIC)
cap_mask |= CAP_TO_MASK(CAP_NET_BIND_SERVICE);
#endif

if (cap_mask) {
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"prctl(PR_SET_KEEPCAPS, 1) failed");
Expand All @@ -906,17 +916,17 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
exit(2);
}

#if (NGX_HAVE_CAPABILITIES)
if (ccf->transparent && ccf->user) {
struct __user_cap_data_struct data;
struct __user_cap_header_struct header;
#if (NGX_HAVE_PR_SET_KEEPCAPS && NGX_HAVE_CAPABILITIES)
struct __user_cap_data_struct data;
struct __user_cap_header_struct header;

if (cap_mask) {
ngx_memzero(&header, sizeof(struct __user_cap_header_struct));
ngx_memzero(&data, sizeof(struct __user_cap_data_struct));

header.version = _LINUX_CAPABILITY_VERSION_1;
data.effective = CAP_TO_MASK(CAP_NET_RAW);
data.permitted = data.effective;
data.effective = cap_mask;
data.permitted = cap_mask;

if (syscall(SYS_capset, &header, &data) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
Expand Down