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 --- 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