[PATCH RFC v2 0/4] bpf, sockmap: Restrict iter-context sockmap updates to sockmap iterators

From: Michal Luczaj

Date: Sun Nov 01 2026 - 20:22:09 EST


Follow-up to Sashiko's report [1] and the decision to restrict which
iterator may perform sockmap updates [2].

Short series: remove about-to-be-stale test, restrict updates, add a
negative test. Related bonus: mark bpf_iter__sockmap::sk as PTR_TRUSTED.

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

Signed-off-by: Michal Luczaj <mhal@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: Andrii Nakryiko <andrii@xxxxxxxxxx>
To: Eduard Zingerman <eddyz87@xxxxxxxxx>
To: Ihor Solodrai <ihor.solodrai@xxxxxxxxx>
To: Alexei Starovoitov <ast@xxxxxxxxxx>
To: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
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: 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>
Cc: bpf@xxxxxxxxxxxxxxx
Cc: linux-kselftest@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: netdev@xxxxxxxxxxxxxxx

---
Michal Luczaj (4):
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: Mark bpf_iter__sockmap::sk as PTR_TRUSTED

kernel/bpf/verifier.c | 4 +++-
net/core/sock_map.c | 2 +-
tools/testing/selftests/bpf/progs/bpf_iter_unix.c | 10 ----------
.../testing/selftests/bpf/progs/verifier_sockmap_mutate.c | 14 ++++++++++++++
4 files changed, 18 insertions(+), 12 deletions(-)
---
base-commit: a30c772627b2ef4bc715332b1b04938a914556cd
change-id: 20261008-sockmap-update-limit-iter-d03ea25f9775

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