From: sashiko-bot@kernel.org
To: "Daniel Borkmann" <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/4] bpf: Reject exclusive maps for bpf_map_elem iterators
Date: Tue, 02 Jun 2026 13:49:47 +0000 [thread overview]
Message-ID: <20260602134948.3F8EA1F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260602133052.423725-2-daniel@iogearbox.net>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Generic BPF map iterators bypass BPF_F_RDONLY_PROG and map->frozen protections.
- [High] Incomplete fix for exclusive map security bypass via dynamic attach points
--
commit 9a17d32567844f5c82567e8f969e7dc780b8275c
Author: Daniel Borkmann <daniel@iogearbox.net>
bpf: Reject exclusive maps for bpf_map_elem iterators
Exclusive maps are meant to be reachable only from the single program whose
hash matches. This patch adds a check in bpf_iter_attach_map() to reject
exclusive maps when binding to a bpf_map_elem iterator.
> diff --git a/kernel/bpf/map_iter.c b/kernel/bpf/map_iter.c
> index 261a03ea73d34..ae0741a09c6de 100644
> --- a/kernel/bpf/map_iter.c
> +++ b/kernel/bpf/map_iter.c
> @@ -112,6 +112,10 @@ static int bpf_iter_attach_map(struct bpf_prog *prog,
> map = bpf_map_get_with_uref(linfo->map.map_fd);
> if (IS_ERR(map))
> return PTR_ERR(map);
> + if (map->excl_prog_sha) {
> + err = -EPERM;
> + goto put_map;
> + }
[Severity: High]
This isn't a bug introduced by this patch, but while enforcing the
excl_prog_sha restriction here, are there other dynamic attach points that
still miss this check?
For example, looking at bpf_iter_attach_map() in net/core/bpf_sk_storage.c,
it binds a map to an sk_storage iterator without checking map->excl_prog_sha:
net/core/bpf_sk_storage.c:bpf_iter_attach_map() {
...
map = bpf_map_get_with_uref(linfo->map.map_fd);
if (IS_ERR(map))
return PTR_ERR(map);
...
}
Similarly, sock_map_iter_attach_target(), sock_map_link_create(), and
sock_map_get_from_fd() in net/core/sock_map.c dynamically attach BPF programs
or iterators to sockmaps but do not appear to check map->excl_prog_sha.
Could these missing checks allow the attachment of an untrusted program or
iterator to an exclusive sk_storage or sockmap, bypassing the exclusivity
constraint?
[Severity: Critical]
This is also a pre-existing issue, but does this function properly enforce
read-only constraints on maps?
Later in this same function, the code checks if the iterator program's
max_rdwr_access exceeds the map's value_size:
kernel/bpf/map_iter.c:bpf_iter_attach_map() {
...
key_acc_size = prog->aux->max_rdonly_access;
value_acc_size = prog->aux->max_rdwr_access;
...
if (key_acc_size > key_size || value_acc_size > value_size) {
err = -EACCES;
goto put_map;
}
...
}
However, it does not appear to check if the target map has the
BPF_F_RDONLY_PROG flag or if map->frozen is set.
Since the BPF verifier defines the bpf_map_elem iterator program argument
ctx->value as PTR_TO_BUF (without MEM_RDONLY), it allows the iterator program
to write to the map element.
If an iterator is attached to a read-only or frozen map (like a .rodata array
map), can it bypass these protections and modify the contents dynamically?
Because the verifier assumes these maps are immutable and optimizes bounds
checks based on their contents, could this lead to out-of-bounds memory
accesses in previously verified BPF programs?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260602133052.423725-1-daniel@iogearbox.net?part=1
next prev parent reply other threads:[~2026-06-02 13:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 13:30 [PATCH bpf-next 0/4] More gen_loader fixes #2 Daniel Borkmann
2026-06-02 13:30 ` [PATCH bpf-next 1/4] bpf: Reject exclusive maps for bpf_map_elem iterators Daniel Borkmann
2026-06-02 13:49 ` sashiko-bot [this message]
2026-06-02 15:38 ` Daniel Borkmann
2026-06-02 13:30 ` [PATCH bpf-next 2/4] libbpf: Guard add_data() against size overflow Daniel Borkmann
2026-06-02 13:30 ` [PATCH bpf-next 3/4] selftests/bpf: Keep verifier_map_ptr exercising ops pointer access Daniel Borkmann
2026-06-02 14:15 ` sashiko-bot
2026-06-02 13:30 ` [PATCH bpf-next 4/4] selftests/bpf: Test that exclusive maps are rejected as iter targets Daniel Borkmann
2026-06-02 16:50 ` [PATCH bpf-next 0/4] More gen_loader fixes #2 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=20260602134948.3F8EA1F00898@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=sashiko-reviews@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.