From: Quentin Monnet <qmo@kernel.org>
To: Slava Imameev <slava.imameev@crowdstrike.com>,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
shuah@kernel.org, bpf@vger.kernel.org
Cc: martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
yonghong.song@linux.dev, john.fastabend@gmail.com,
kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
jolsa@kernel.org, mykolal@fb.com,
justin.deschamp@crowdstrike.com, mark.fontana@crowdstrike.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 1/2] bpftool: Use appropriate permissions for map access
Date: Mon, 16 Jun 2025 15:06:04 +0100 [thread overview]
Message-ID: <544524c2-e913-4181-b43a-07b029ff75e4@kernel.org> (raw)
In-Reply-To: <20250611221816.54510-1-slava.imameev@crowdstrike.com>
2025-06-12 08:18 UTC+1000 ~ Slava Imameev <slava.imameev@crowdstrike.com>
> Modify several functions in tools/bpf/bpftool/common.c to allow
> specification of requested access for file descriptors, such as
> read-only access.
>
> Update bpftool to request only read access for maps when write
> access is not required. This fixes errors when reading from maps
> that are protected from modification via security_bpf_map.
>
> Signed-off-by: Slava Imameev <slava.imameev@crowdstrike.com>
> ---
> Changes in v2:
> - fix for a test compilation error: "conflicting types for 'bpf_fentry_test1'"
> Changes in v3:
> - Addressed review feedback
> - Converted the check for flags to an assert in map_parse_fds
> - Modified map_fd_by_name to keep an existing fd where possible
> - Fixed requested access for map delete command in do_delete
> - Changed requested access to RDONLY for inner map fd in do_create
> - Changed requested access to RDONLY for iterator fd in do_pin
> ---
> ---
> tools/bpf/bpftool/btf.c | 3 +-
> tools/bpf/bpftool/common.c | 58 ++++++++++++++++++++++---------
> tools/bpf/bpftool/iter.c | 2 +-
> tools/bpf/bpftool/link.c | 2 +-
> tools/bpf/bpftool/main.h | 13 ++++---
> tools/bpf/bpftool/map.c | 56 +++++++++++++++++------------
> tools/bpf/bpftool/map_perf_ring.c | 3 +-
> tools/bpf/bpftool/prog.c | 4 +--
> 8 files changed, 91 insertions(+), 50 deletions(-)
>
> diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
> index 6b14cbfa58aa..1ba27cb03348 100644
> --- a/tools/bpf/bpftool/btf.c
> +++ b/tools/bpf/bpftool/btf.c
> @@ -905,7 +905,8 @@ static int do_dump(int argc, char **argv)
> return -1;
> }
>
> - fd = map_parse_fd_and_info(&argc, &argv, &info, &len);
> + fd = map_parse_fd_and_info(&argc, &argv, &info, &len,
> + BPF_F_RDONLY);
> if (fd < 0)
> return -1;
>
> diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
> index ecfa790adc13..3bdc65112c0d 100644
> --- a/tools/bpf/bpftool/common.c
> +++ b/tools/bpf/bpftool/common.c
[...]
> @@ -1023,8 +1042,13 @@ static int map_fd_by_name(char *name, int **fds)
> return -1;
> }
>
> -int map_parse_fds(int *argc, char ***argv, int **fds)
> +int map_parse_fds(int *argc, char ***argv, int **fds, __u32 open_flags)
> {
> + LIBBPF_OPTS(bpf_get_fd_by_id_opts, opts);
> +
> + assert((open_flags & ~BPF_F_RDONLY) == 0);
Can you please "#include <assert.h>" at the top of the file? We don't
need it in the kernel repo, because the header is included from
tools/include/linux/kernel.h (from bpftool's main.h) if I remember
correctly. But the GitHub mirror uses a stripped-down version of
kernel.h which doesn't pull assert.h, so we need to include it
explicitly - I just remembered when seeing your v3, sorry.
Looks good to me otherwise, thanks!
Quentin
prev parent reply other threads:[~2025-06-16 14:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 22:18 Slava Imameev
2025-06-11 22:18 ` [PATCH bpf-next v3 2/2] selftests/bpf: Add test for bpftool access to read-only protected maps Slava Imameev
2025-06-16 14:06 ` Quentin Monnet
2025-06-16 14:06 ` Quentin Monnet [this message]
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=544524c2-e913-4181-b43a-07b029ff75e4@kernel.org \
--to=qmo@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=justin.deschamp@crowdstrike.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mark.fontana@crowdstrike.com \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=slava.imameev@crowdstrike.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®