Getting ID of map/prog/btf/link doesn't give any access to underlying BPF objects, so there is no point in requiring CAP_SYS_ADMIN for these commands. Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> --- kernel/bpf/syscall.c | 3 --- .../bpf/prog_tests/unpriv_bpf_disabled.c | 15 ++------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index c9a201e4c457..1d74c0a8d903 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3720,9 +3720,6 @@ static int bpf_obj_get_next_id(const union bpf_attr *attr, if (CHECK_ATTR(BPF_OBJ_GET_NEXT_ID) || next_id >= INT_MAX) return -EINVAL; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - next_id++; spin_lock_bh(lock); if (!idr_get_next(idr, &next_id)) diff --git a/tools/testing/selftests/bpf/prog_tests/unpriv_bpf_disabled.c b/tools/testing/selftests/bpf/prog_tests/unpriv_bpf_disabled.c index 8383a99f610f..154a957154e8 100644 --- a/tools/testing/selftests/bpf/prog_tests/unpriv_bpf_disabled.c +++ b/tools/testing/selftests/bpf/prog_tests/unpriv_bpf_disabled.c @@ -156,7 +156,6 @@ static void test_unpriv_bpf_disabled_negative(struct test_unpriv_bpf_disabled *s __u32 attach_flags = 0; __u32 prog_ids[3] = {}; __u32 prog_cnt = 3; - __u32 next; int i; /* Negative tests for unprivileged BPF disabled. Verify we cannot @@ -176,25 +175,15 @@ static void test_unpriv_bpf_disabled_negative(struct test_unpriv_bpf_disabled *s -EPERM, "map_create_fails"); ASSERT_EQ(bpf_prog_get_fd_by_id(prog_id), -EPERM, "prog_get_fd_by_id_fails"); - ASSERT_EQ(bpf_prog_get_next_id(prog_id, &next), -EPERM, "prog_get_next_id_fails"); - ASSERT_EQ(bpf_prog_get_next_id(0, &next), -EPERM, "prog_get_next_id_fails"); if (ASSERT_OK(bpf_map_get_info_by_fd(map_fds[0], &map_info, &map_info_len), - "obj_get_info_by_fd")) { + "obj_get_info_by_fd")) ASSERT_EQ(bpf_map_get_fd_by_id(map_info.id), -EPERM, "map_get_fd_by_id_fails"); - ASSERT_EQ(bpf_map_get_next_id(map_info.id, &next), -EPERM, - "map_get_next_id_fails"); - } - ASSERT_EQ(bpf_map_get_next_id(0, &next), -EPERM, "map_get_next_id_fails"); if (ASSERT_OK(bpf_link_get_info_by_fd(bpf_link__fd(skel->links.sys_nanosleep_enter), &link_info, &link_info_len), - "obj_get_info_by_fd")) { + "obj_get_info_by_fd")) ASSERT_EQ(bpf_link_get_fd_by_id(link_info.id), -EPERM, "link_get_fd_by_id_fails"); - ASSERT_EQ(bpf_link_get_next_id(link_info.id, &next), -EPERM, - "link_get_next_id_fails"); - } - ASSERT_EQ(bpf_link_get_next_id(0, &next), -EPERM, "link_get_next_id_fails"); ASSERT_EQ(bpf_prog_query(prog_fd, BPF_TRACE_FENTRY, 0, &attach_flags, prog_ids, &prog_cnt), -EPERM, "prog_query_fails"); -- 2.34.1