bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
	<martin.lau@kernel.org>
Cc: <andrii@kernel.org>, <kernel-team@meta.com>
Subject: [PATCH bpf-next 2/3] bpf: don't require CAP_SYS_ADMIN for getting NEXT_ID
Date: Wed, 24 May 2023 15:54:20 -0700	[thread overview]
Message-ID: <20230524225421.1587859-3-andrii@kernel.org> (raw)
In-Reply-To: <20230524225421.1587859-1-andrii@kernel.org>

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@kernel.org>
---
 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


  parent reply	other threads:[~2023-05-24 22:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24 22:54 [PATCH bpf-next 0/3] Relax checks for unprivileged bpf() commands Andrii Nakryiko
2023-05-24 22:54 ` [PATCH bpf-next 1/3] bpf: drop unnecessary bpf_capable() check in BPF_MAP_FREEZE command Andrii Nakryiko
2023-05-24 22:54 ` Andrii Nakryiko [this message]
2023-05-25  3:22   ` [PATCH bpf-next 2/3] bpf: don't require CAP_SYS_ADMIN for getting NEXT_ID Alexei Starovoitov
2023-05-25 17:04     ` Andrii Nakryiko
2023-05-25 17:11       ` Alexei Starovoitov
2023-05-25 17:30         ` Andrii Nakryiko
2023-05-24 22:54 ` [PATCH bpf-next 3/3] bpf: don't require bpf_capable() for GET_INFO_BY_FD Andrii Nakryiko
2023-05-25 13:13   ` Daniel Borkmann
2023-05-25 17:20     ` Andrii Nakryiko
2023-05-25 19:49       ` Daniel Borkmann
2023-05-25 17:20 ` [PATCH bpf-next 0/3] Relax checks for unprivileged bpf() commands patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230524225421.1587859-3-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).