core/cgroup: foreign bpf programs needs to pass bpf_program_supported()

As CONFIG_CGROUP_BPF may be disabled on the kernel or we are running on
sanitizers. See comments in bpf_program_supported().

Follow-up for 3fcb98cbff.
This commit is contained in:
Yu Watanabe
2025-05-10 00:17:52 +09:00
parent 71be1f3875
commit 22e2f06428
2 changed files with 6 additions and 4 deletions
+3 -2
View File
@@ -3273,8 +3273,9 @@ static int cg_bpf_mask_supported(CGroupMask *ret) {
if (r > 0)
mask |= CGROUP_MASK_BPF_DEVICES;
/* BPF pinned prog (always supported by cgroup v2) */
mask |= CGROUP_MASK_BPF_FOREIGN;
/* BPF pinned prog */
if (bpf_program_supported() > 0)
mask |= CGROUP_MASK_BPF_FOREIGN;
/* BPF-based bind{4|6} hooks */
r = bpf_socket_bind_supported();
+3 -2
View File
@@ -279,8 +279,9 @@ int main(int argc, char *argv[]) {
if (detect_container() > 0)
return log_tests_skipped("test-bpf fails inside LXC and Docker containers: https://github.com/systemd/systemd/issues/9666");
if (getuid() != 0)
return log_tests_skipped("not running as root");
r = bpf_program_supported();
if (r < 0)
return log_tests_skipped_errno(r, "not running as root");
ASSERT_OK(getrlimit(RLIMIT_MEMLOCK, &rl));
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);