From: Adethya Srinivasan <adethyasrinivasan@outlook.com>
To: bpf@vger.kernel.org
Cc: Adethya Srinivasan <adethyasrinivasan@outlook.com>,
yonghong.song@linux.dev, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
martin.lau@linux.dev, song@kernel.org, jolsa@kernel.org,
emil@etsalapatis.com, ihor.solodrai@linux.dev, shuah@kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH bpf v2 1/2] bpf: Reject writable map iterators on read-only maps
Date: Thu, 12 Nov 2026 15:54:06 +0000 [thread overview]
Message-ID: <LO2P302MB019721D7E507DFA1C707F102BC702@LO2P302MB0197.GBRP302.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <LO2P302MB0197C0434BCC2A9031E99A18BC702@LO2P302MB0197.GBRP302.PROD.OUTLOOK.COM>
With CAP_BPF and CAP_PERFMON, an iterator program can write into a
frozen BPF_F_RDONLY_PROG array. The verifier treats the contents of
such an array as constants.
Reject writable map iterators on maps with BPF_F_RDONLY_PROG set.
Keep allowing read-only iterators.
Fixes: d3cc2ab546ad ("bpf: Implement bpf iterator for array maps")
Fixes: d6c4503cc296 ("bpf: Implement bpf iterator for hash maps")
Signed-off-by: Adethya Srinivasan <adethyasrinivasan@outlook.com>
---
kernel/bpf/map_iter.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/kernel/bpf/map_iter.c b/kernel/bpf/map_iter.c
index a58c14869..7a769e5f5 100644
--- a/kernel/bpf/map_iter.c
+++ b/kernel/bpf/map_iter.c
@@ -99,8 +99,8 @@ static struct bpf_iter_reg bpf_map_reg_info = {
/*
* For an iterator that hands the live map value to the program as a writable
- * buffer: the verifier knows nothing of the map, so the special fields of the
- * value have to lie outside of what the program may write.
+ * buffer: the verifier knows nothing of the map, so read-only maps
+ * and special fields of the value have to be protected from writes.
*/
int bpf_iter_map_check_value_write(const struct bpf_prog *prog,
const struct bpf_map *map)
@@ -109,7 +109,13 @@ int bpf_iter_map_check_value_write(const struct bpf_prog *prog,
const struct btf_field *field;
u32 i;
- if (IS_ERR_OR_NULL(rec) || !prog->aux->max_rdwr_write)
+ if (!prog->aux->max_rdwr_write)
+ return 0;
+
+ if (map->map_flags & BPF_F_RDONLY_PROG)
+ return -EACCES;
+
+ if (IS_ERR_OR_NULL(rec))
return 0;
for (i = 0; i < rec->cnt; i++) {
next prev parent reply other threads:[~2026-11-12 15:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 15:54 [PATCH bpf v2 0/2] " Adethya Srinivasan
2026-11-12 15:54 ` Adethya Srinivasan [this message]
2026-11-12 15:54 ` [PATCH bpf v2 2/2] selftests/bpf: Check writable iterator attach to a read-only array Adethya Srinivasan
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=LO2P302MB019721D7E507DFA1C707F102BC702@LO2P302MB0197.GBRP302.PROD.OUTLOOK.COM \
--to=adethyasrinivasan@outlook.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--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®