[PATCH bpf-next v3 2/8] bpf, sockmap: Restrict iter-context sockmap updates to iter/sockmap
From: Michal Luczaj
Date: Sat Nov 07 2026 - 13:04:10 EST
Among tracing progs, allow only iter/sockmap to update sockmaps and
sockhashes. Previously, any BPF_TRACE_ITER program could perform these
updates, which caused locking issues in specific scenarios [1][2][3]. This
tightening is part of the broader effort to lock down the BPF API [4].
[1]: commit 4d328dd69538 ("bpf, sockmap: Fix af_unix iter deadlock")
[2]: commit 64c2f93fc325 ("bpf, sockmap: Take state lock for af_unix iter")
[3]: https://msgid.link/87echn2fhd.fsf@xxxxxxxxxxxxxx
[4]: https://msgid.link/akRZ_e7DJh2aP-2i@john-p8
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://msgid.link/20260626205814.BAC3C1F000E9@xxxxxxxxxxxxxxx
Suggested-by: Jakub Sitnicki <jakub@xxxxxxxxxxxxxx>
Signed-off-by: Michal Luczaj <mhal@xxxxxxx>
---
I was tempted to define BTF_ID_LIST_SINGLE(bpf_iter_sockmap_id, func,
bpf_iter_sockmap) and just compare against env->prog->aux->attach_btf_id,
but a single line BTF_ID_LIST_SINGLE quickly turned into a 6-line
ifdef-CONFIG_NET-fery, so I've sticked with strcmp().
---
kernel/bpf/verifier.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 09a44723bb2e..e784e4a1e5f2 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -10543,6 +10543,7 @@ static bool may_update_sockmap(struct bpf_verifier_env *env, int func_id)
{
enum bpf_attach_type eatype = env->prog->expected_attach_type;
enum bpf_prog_type type = resolve_prog_type(env->prog);
+ const char *afname = env->prog->aux->attach_func_name;
if (func_id != BPF_FUNC_map_update_elem &&
func_id != BPF_FUNC_map_delete_elem)
@@ -10553,7 +10554,8 @@ static bool may_update_sockmap(struct bpf_verifier_env *env, int func_id)
*/
switch (type) {
case BPF_PROG_TYPE_TRACING:
- if (eatype == BPF_TRACE_ITER)
+ if (eatype == BPF_TRACE_ITER &&
+ !strcmp(afname + strlen(BPF_ITER_FUNC_PREFIX), "sockmap"))
return true;
break;
case BPF_PROG_TYPE_SOCK_OPS:
--
2.56.0