[PATCH bpf-next v3 0/8] bpf, sockmap: Restrict iter-context sockmap updates to sockmap iterators

From: Michal Luczaj

Date: Sat Nov 07 2026 - 13:04:11 EST


Follow-up to Sashiko's report [1] and the decision to restrict which
iterator may perform sockmap updates [2]. Series started short: remove
about-to-be-stale test, restrict updates, add a negative test. Then it
expanded: mark bpf_iter__sockmap::sk as PTR_TRUSTED, restrict
bpf_sock_destroy() callers to iter/{tcp,udp}, few little tweaks.

[1]: https://msgid.link/20260626205814.BAC3C1F000E9@xxxxxxxxxxxxxxx
[2]: https://msgid.link/87echn2fhd.fsf@xxxxxxxxxxxxxx

Signed-off-by: Michal Luczaj <mhal@xxxxxxx>
---
Changes in v3:
- Drop RFC prefix
- Update bpf_iter_reg::feature docs
- Fix tcp_request_sock BTF build error
- Restrict allowed callers of bpf_sock_destroy() to iter/{tcp,udp} (Alexei)
- Link to v2: https://patch.msgid.link/20261102-sockmap-update-limit-iter-v2-0-e96a63c43b39@xxxxxxx

Changes in v2:
- Commit 7cc639dc45c5 ("bpf: Don't take an extension for an iterator
program") and commit b83bacf2161d ("bpf: Don't take a program with a
target program for an iterator") landed. Drop the redundant
env->prog->type check.
- Mark bpf_iter__sockmap::sk as PTR_TRUSTED (Alexei)
- Link to v1: https://patch.msgid.link/20261016-sockmap-update-limit-iter-v1-0-23fa946db59e@xxxxxxx

To: Alexei Starovoitov <ast@xxxxxxxxxx>
To: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
To: Andrii Nakryiko <andrii@xxxxxxxxxx>
To: Eduard Zingerman <eddyz87@xxxxxxxxx>
To: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
To: Martin KaFai Lau <martin.lau@xxxxxxxxx>
To: Song Liu <song@xxxxxxxxxx>
To: Yonghong Song <yonghong.song@xxxxxxxxx>
To: Jiri Olsa <jolsa@xxxxxxxxxx>
To: Emil Tsalapatis <emil@xxxxxxxxxxxxxxx>
To: Ihor Solodrai <ihor.solodrai@xxxxxxxxx>
To: Shuah Khan <shuah@xxxxxxxxxx>
To: John Fastabend <john.fastabend@xxxxxxxxx>
To: Eric Dumazet <edumazet@xxxxxxxxxx>
To: Kuniyuki Iwashima <kuniyu@xxxxxxxxxx>
To: Paolo Abeni <pabeni@xxxxxxxxxx>
To: Willem de Bruijn <willemb@xxxxxxxxxx>
To: Jakub Sitnicki <jakub@xxxxxxxxxxxxxx>
To: Jiayuan Chen <jiayuan.chen@xxxxxxxxx>
To: "David S. Miller" <davem@xxxxxxxxxxxxx>
To: Jakub Kicinski <kuba@xxxxxxxxxx>
To: Simon Horman <horms@xxxxxxxxxx>
To: Jonathan Corbet <corbet@xxxxxxx>
To: Shuah Khan <skhan@xxxxxxxxxxxxxxxxxxx>
To: Randy Dunlap <rdunlap@xxxxxxxxxxxxx>
To: Stanislav Fomichev <sdf@xxxxxxxxxxx>
Cc: bpf@xxxxxxxxxxxxxxx
Cc: linux-kselftest@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: netdev@xxxxxxxxxxxxxxx
Cc: linux-doc@xxxxxxxxxxxxxxx

---
Michal Luczaj (8):
selftests/bpf: Remove sockmap update from bpf_iter_unix
bpf, sockmap: Restrict iter-context sockmap updates to iter/sockmap
selftests/bpf: Add negative test for sockmap update from non-sockmap iter
bpf, docs: Document BPF_ITER_NOSLEEP
bpf: Restrict bpf_sock_destroy() to iter/{tcp,udp}
bpf: Mark bpf_iter__sockmap::sk as PTR_TRUSTED
selftests/bpf: Add iter/sockmap bpf_sock_destroy() negative test
bpf: Fix "unresolved symbol tcp_request_sock" build error

Documentation/bpf/bpf_iterators.rst | 12 +++++++++---
kernel/bpf/verifier.c | 4 +++-
net/core/filter.c | 15 ++++++++++++++-
net/core/sock_map.c | 2 +-
tools/testing/selftests/bpf/progs/bpf_iter_unix.c | 10 ----------
.../testing/selftests/bpf/progs/sock_destroy_prog_fail.c | 11 +++++++++++
.../testing/selftests/bpf/progs/verifier_sockmap_mutate.c | 14 ++++++++++++++
7 files changed, 52 insertions(+), 16 deletions(-)
---
base-commit: 2d0b457611c06304138754a05e0873cc18acfb7e
change-id: 20261008-sockmap-update-limit-iter-d03ea25f9775

Best regards,
--
Michal Luczaj <mhal@xxxxxxx>