From: Shihuang Liu <shlomojune6@gmail.com>
To: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev,
song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
emil@etsalapatis.com, ihor.solodrai@linux.dev, kuba@kernel.org,
qmo@kernel.org, Shihuang Liu <shlomojune6@gmail.com>
Subject: [PATCH bpf-next v2 2/2] bpf: Reject maps without iter_seq_info in bpf_iter_attach_map
Date: Thu, 19 Nov 2026 00:16:32 +0800 [thread overview]
Message-ID: <20261118161632.177820-2-shlomojune6@gmail.com> (raw)
In-Reply-To: <20261118161632.177820-1-shlomojune6@gmail.com>
bpf_iter_attach_map() checks map_type only, so an offloaded ARRAY/HASH
map can be attached to a bpf_map_elem iterator. Offloaded maps have no
iter_seq_info, so __get_seq_info() falls back to the target's seq_info,
which is NULL for bpf_map_elem, and prepare_seq_file() dereferences it
when the iterator is opened.
Reject maps without ops->iter_seq_info. All map types accepted here
provide it.
Fixes: d6c4503cc296 ("bpf: Implement bpf iterator for hash maps")
Link: https://lore.kernel.org/all/20261112105620.57520-1-shlomojune6@gmail.com/
Signed-off-by: Shihuang Liu <shlomojune6@gmail.com>
---
kernel/bpf/map_iter.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/bpf/map_iter.c b/kernel/bpf/map_iter.c
index a58c148692e6c3..9e459a2d34c3aa 100644
--- a/kernel/bpf/map_iter.c
+++ b/kernel/bpf/map_iter.c
@@ -176,6 +176,10 @@ static int bpf_iter_attach_map(struct bpf_prog *prog,
map->map_type != BPF_MAP_TYPE_RHASH)
goto put_map;
+ /* An offloaded map has the map_type of a host map and its own ops */
+ if (!map->ops->iter_seq_info)
+ goto put_map;
+
aux->map = map;
err = bpf_iter_map_check_prog(prog, aux);
if (err)
--
2.43.0
prev parent reply other threads:[~2026-11-18 16:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 16:16 [PATCH bpf-next v2 1/2] bpf: Reject offloaded maps as map-in-map inner maps Shihuang Liu
2026-11-18 16:16 ` Shihuang Liu [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=20261118161632.177820-2-shlomojune6@gmail.com \
--to=shlomojune6@gmail.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=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=qmo@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