else
r = bpf_program_add_instructions(prog, insn, ELEMENTSOF(insn));
if (r < 0)
- log_error_errno(r, "Extending device control BPF program failed: %m");
+ return log_error_errno(r, "Extending device control BPF program failed: %m");
- return r;
+ return 1; /* return 1 → we did something */
}
static int bpf_prog_allow_list_major(
else
r = bpf_program_add_instructions(prog, insn, ELEMENTSOF(insn));
if (r < 0)
- log_error_errno(r, "Extending device control BPF program failed: %m");
+ return log_error_errno(r, "Extending device control BPF program failed: %m");
- return r;
+ return 1; /* return 1 → we did something */
}
static int bpf_prog_allow_list_class(
else
r = bpf_program_add_instructions(prog, insn, ELEMENTSOF(insn));
if (r < 0)
- log_error_errno(r, "Extending device control BPF program failed: %m");
+ return log_error_errno(r, "Extending device control BPF program failed: %m");
- return r;
+ return 1; /* return 1 → we did something */
}
int bpf_devices_cgroup_init(
assert(ret);
- if (policy == CGROUP_DEVICE_POLICY_AUTO && !allow_list)
+ if (policy == CGROUP_DEVICE_POLICY_AUTO && !allow_list) {
+ *ret = NULL;
return 0;
+ }
r = bpf_program_new(BPF_PROG_TYPE_CGROUP_DEVICE, "sd_devices", &prog);
if (r < 0)
}
*ret = TAKE_PTR(prog);
-
- return 0;
+ return 1;
}
int bpf_devices_apply_policy(
if (fnmatch(name, w, 0) != 0)
continue;
- any = true;
- (void) allow_list_device_pattern(prog, path, type, major, /* minor= */ UINT_MAX, permissions);
+ if (allow_list_device_pattern(prog, path, type, major, /* minor= */ UINT_MAX, permissions) > 0)
+ any = true;
}
if (!any)
return log_debug_errno(SYNTHETIC_ERRNO(ENOENT),
"Device allow list pattern \"%s\" did not match anything.", name);
- return 0;
+ return any;
}
int bpf_devices_allow_list_static(
NULSTR_FOREACH_PAIR(node, acc, auto_devices) {
k = bpf_devices_allow_list_device(prog, path, node, cgroup_device_permissions_from_string(acc));
- if (r >= 0 && k < 0)
+ if ((r >= 0 && k < 0) || (r >= 0 && k > 0))
r = k;
}
/* PTS (/dev/pts) devices may not be duplicated, but accessed */
k = bpf_devices_allow_list_major(prog, path, "pts", 'c', CGROUP_DEVICE_READ|CGROUP_DEVICE_WRITE);
- if (r >= 0 && k < 0)
+ if ((r >= 0 && k < 0) || (r >= 0 && k > 0))
r = k;
return r;
bool allow_list_static = policy == CGROUP_DEVICE_POLICY_CLOSED ||
(policy == CGROUP_DEVICE_POLICY_AUTO && c->device_allow);
- if (allow_list_static)
- (void) bpf_devices_allow_list_static(prog, path);
- bool any = allow_list_static;
+ bool any = false;
+ if (allow_list_static) {
+ r = bpf_devices_allow_list_static(prog, path);
+ if (r > 0)
+ any = true;
+ }
+
LIST_FOREACH(device_allow, a, c->device_allow) {
const char *val;
continue;
}
- if (r >= 0)
+ if (r > 0)
any = true;
}