Skip to contentSkip to conversation

bpf, sockmap: Restrict iter-context sockmap updates to sockmap iterators

PATCH Applied Michal Luczaj 5 participants 17 messages Nov 7 – Nov 15

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

v3 cover bpf, sockmap: Restrict iter-context sockmap updates to sockmap iterators

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/[email protected]
[2]: https://msgid.link/[email protected]

---
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/[email protected]

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/[email protected]

To: Alexei Starovoitov <[email protected]>
To: Daniel Borkmann <[email protected]>
To: Andrii Nakryiko <[email protected]>
To: Eduard Zingerman <[email protected]>
To: Kumar Kartikeya Dwivedi <[email protected]>
To: Martin KaFai Lau <[email protected]>
To: Song Liu <[email protected]>
To: Yonghong Song <[email protected]>
To: Jiri Olsa <[email protected]>
To: Emil Tsalapatis <[email protected]>
To: Ihor Solodrai <[email protected]>
To: Shuah Khan <[email protected]>
To: John Fastabend <[email protected]>
To: Eric Dumazet <[email protected]>
To: Kuniyuki Iwashima <[email protected]>
To: Paolo Abeni <[email protected]>
To: Willem de Bruijn <[email protected]>
To: Jakub Sitnicki <[email protected]>
To: Jiayuan Chen <[email protected]>
To: "David S. Miller" <[email protected]>
To: Jakub Kicinski <[email protected]>
To: Simon Horman <[email protected]>
To: Jonathan Corbet <[email protected]>
To: Shuah Khan <[email protected]>
To: Randy Dunlap <[email protected]>
To: Stanislav Fomichev <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

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

Signature · 1 line
Michal Luczaj <[email protected]>
#1 lore raw

PATCH v3 1/8 selftests/bpf: Remove sockmap update from bpf_iter_unix

BPF iterator programs that can update sockmaps will be limited to iter/sockmap. Remove the update from the unix selftest.

This reverts commit 997b8483d44c ("selftests/bpf: Extend bpf_iter_unix to attempt deadlocking").

---
 tools/testing/selftests/bpf/progs/bpf_iter_unix.c | 10 ----------
 1 file changed, 10 deletions(-)
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +0 -10
index 3061b148f338..90beada0386d 100644
@@ -7,13 +7,6 @@
 
 char _license[] SEC("license") = "GPL";
 
-SEC(".maps") struct {
-	__uint(type, BPF_MAP_TYPE_SOCKMAP);
-	__uint(max_entries, 1);
-	__type(key, __u32);
-	__type(value, __u64);
-} sockmap;
-
 static long sock_i_ino(const struct sock *sk)
 {
 	const struct socket *sk_socket = sk->sk_socket;
@@ -82,8 +75,5 @@ int dump_unix(struct bpf_iter__unix *ctx)
 
 	BPF_SEQ_PRINTF(seq, "\n");
 
-	/* Test for deadlock. */
-	bpf_map_update_elem(&sockmap, &(int){0}, sk, 0);
-
 	return 0;
 }
Signature · 1 line
2.56.0
maintainer Reviewed-by on v3 1/8
#2 lore raw

Re: [PATCH bpf-next v3 1/8] selftests/bpf: Remove sockmap update from bpf_iter_unix

Quoted 7 lines · Michal Luczaj

BPF iterator programs that can update sockmaps will be limited to iter/sockmap. Remove the update from the unix selftest.

This reverts commit 997b8483d44c ("selftests/bpf: Extend bpf_iter_unix to attempt deadlocking").

Quoted 32 lines
---
 tools/testing/selftests/bpf/progs/bpf_iter_unix.c | 10 ----------
 1 file changed, 10 deletions(-)
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +0 -10
index 3061b148f338..90beada0386d 100644
@@ -7,13 +7,6 @@
 
 char _license[] SEC("license") = "GPL";
 
-SEC(".maps") struct {
-	__uint(type, BPF_MAP_TYPE_SOCKMAP);
-	__uint(max_entries, 1);
-	__type(key, __u32);
-	__type(value, __u64);
-} sockmap;
-
 static long sock_i_ino(const struct sock *sk)
 {
 	const struct socket *sk_socket = sk->sk_socket;
@@ -82,8 +75,5 @@ int dump_unix(struct bpf_iter__unix *ctx)
 
 	BPF_SEQ_PRINTF(seq, "\n");
 
-	/* Test for deadlock. */
-	bpf_map_update_elem(&sockmap, &(int){0}, sk, 0);
-
 	return 0;
 }
#3 lore raw

PATCH v3 2/8 bpf, sockmap: Restrict iter-context sockmap updates to iter/sockmap

In reply to Michal Luczaj

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/[email protected]
[4]: https://msgid.link/akRZ_e7DJh2aP-2i@john-p8

---
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(-)
kernel/bpf/verifier.c +3 -1
index 09a44723bb2e..e784e4a1e5f2 100644
@@ -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:
Signature · 1 line
2.56.0
maintainer Reviewed-by on v3 2/8
#4 lore raw

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

Quoted 10 lines · Michal Luczaj

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/[email protected]
[4]: https://msgid.link/akRZ_e7DJh2aP-2i@john-p8

Quoted 4 lines
#5 lore raw

PATCH v3 3/8 selftests/bpf: Add negative test for sockmap update from non-sockmap iter

In reply to Michal Luczaj

Iterator-context sockmap updates are now restricted to iter/sockmap. Add a test that attempts an update from iter/unix and expects it to fail.

---
 .../testing/selftests/bpf/progs/verifier_sockmap_mutate.c  | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tools/testing/selftests/bpf/progs/verifier_sockmap_mutate.c +14 -0
index 20332a731d4e..1516fe1524bb 100644
@@ -19,6 +19,12 @@ struct bpf_iter__sockmap {
 	};
 } __attribute__((preserve_access_index));
 
+struct bpf_iter__unix {
+	union {
+		struct sock *unix_sk;
+	};
+} __attribute__((preserve_access_index));
+
 struct {
 	__uint(type, BPF_MAP_TYPE_SOCKHASH);
 	__uint(max_entries, 1);
@@ -113,6 +119,14 @@ int test_trace_iter(struct bpf_iter__sockmap *ctx)
 	return 0;
 }
 
+SEC("iter/unix")
+__failure __msg("cannot update sockmap in this context")
+int test_trace_iter_unix(struct bpf_iter__unix *ctx)
+{
+	test_sockmap_mutate(ctx->unix_sk);
+	return 0;
+}
+
 SEC("raw_tp/kfree")
 __failure __msg("cannot update sockmap in this context")
 int test_raw_tp_delete(const void *ctx __always_unused)
Signature · 1 line
2.56.0
#6 lore raw

PATCH v3 4/8 bpf, docs: Document BPF_ITER_NOSLEEP

In reply to Michal Luczaj

Commit dfcd17659112 ("bpf: Reject sleepable programs for task_vma iterator") introduced BPF_ITER_NOSLEEP, but did not update the docs. Mention the flag in bpf_iterators.rst.

---
 Documentation/bpf/bpf_iterators.rst | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Documentation/bpf/bpf_iterators.rst +9 -3
index 72435e32ffa1..c534215f05de 100644
@@ -351,9 +351,15 @@ The following is the breakdown for each field in struct ``bpf_iter_reg``.
        the bpf iterator.
    * - feature
      - Specifies certain action requests in the kernel BPF iterator
-       infrastructure. Currently, only BPF_ITER_RESCHED is supported. This means
-       that the kernel function cond_resched() is called to avoid other kernel
-       subsystem (e.g., rcu) misbehaving.
+       infrastructure.
+
+       BPF_ITER_RESCHED
+           the kernel function cond_resched() is called to avoid other kernel
+           subsystem (e.g., rcu) misbehaving
+
+       BPF_ITER_NOSLEEP
+           ``seq_operations::show()`` cannot run sleepable programs
+
    * - seq_info
      - Specifies the set of seq operations for the BPF iterator and helpers to
        initialize/free the private data for the corresponding ``seq_file``.
Signature · 1 line
2.56.0
#7 lore raw

PATCH v3 5/8 bpf: Restrict bpf_sock_destroy() to iter/{tcp,udp}

In reply to Michal Luczaj

A subsequent patch will mark bpf_iter__sockmap::sk as PTR_TRUSTED, making bpf_sock_destroy() callable from the iter/sockmap. Unlike iter/{tcp,udp}, the sockmap iterator does not run progs with the socket lock held, so destroying a socket from that context is unsafe. Restrict the allowed callers of bpf_sock_destroy() to iter/{tcp,udp}.

---
 net/core/filter.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
net/core/filter.c +10 -1
index 9245009d9f1e..6a67bc2a0c4b 100644
@@ -13072,11 +13072,20 @@ BTF_KFUNCS_START(bpf_sk_iter_kfunc_ids)
 BTF_ID_FLAGS(func, bpf_sock_destroy)
 BTF_KFUNCS_END(bpf_sk_iter_kfunc_ids)
 
+BTF_SET_START(bpf_sk_iter_locked_ids)
+#if defined(CONFIG_INET) && defined(CONFIG_PROC_FS)
+BTF_ID(func, bpf_iter_tcp)
+BTF_ID(func, bpf_iter_udp)
+#endif
+BTF_SET_END(bpf_sk_iter_locked_ids)
+
 static int tracing_iter_filter(const struct bpf_prog *prog, u32 kfunc_id)
 {
 	if (btf_id_set8_contains(&bpf_sk_iter_kfunc_ids, kfunc_id) &&
-	    prog->expected_attach_type != BPF_TRACE_ITER)
+	    (prog->expected_attach_type != BPF_TRACE_ITER ||
+	     !btf_id_set_contains(&bpf_sk_iter_locked_ids, prog->aux->attach_btf_id)))
 		return -EACCES;
+
 	return 0;
 }
 
Signature · 1 line
2.56.0
#8 lore raw

PATCH v3 6/8 bpf: Mark bpf_iter__sockmap::sk as PTR_TRUSTED

In reply to Michal Luczaj

In preparation for plain-PTR_TO_BTF_ID removal: allow calling bpf helpers with sk provided by iter/sockmap.

---
 net/core/sock_map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock_map.c +1 -1
index efe49551caba..1a8478b03c24 100644
@@ -1993,7 +1993,7 @@ static struct bpf_iter_reg sock_map_iter_reg = {
 		{ offsetof(struct bpf_iter__sockmap, key),
 		  PTR_TO_BUF | PTR_MAYBE_NULL | MEM_RDONLY },
 		{ offsetof(struct bpf_iter__sockmap, sk),
-		  PTR_TO_BTF_ID_OR_NULL },
+		  PTR_TO_BTF_ID_OR_NULL | PTR_TRUSTED },
 	},
 };
 
Signature · 1 line
2.56.0
#9 lore raw

PATCH v3 7/8 selftests/bpf: Add iter/sockmap bpf_sock_destroy() negative test

In reply to Michal Luczaj

bpf_sock_destroy() is restricted to socket-locked iters, TCP and UDP. Fail attempting it from iter/sockmap.

---
 tools/testing/selftests/bpf/progs/sock_destroy_prog_fail.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/testing/selftests/bpf/progs/sock_destroy_prog_fail.c +11 -0
index dd6850b58e25..7b9f5779a184 100644
@@ -20,3 +20,14 @@ int BPF_PROG(trace_tcp_destroy_sock, struct sock *sk)
 	return 0;
 }
 
+SEC("iter/sockmap")
+__failure __msg("calling kernel function bpf_sock_destroy is not allowed")
+int iter_sockmap_destroy(struct bpf_iter__sockmap *ctx)
+{
+	struct sock *sk = ctx->sk;
+
+	if (sk)
+		bpf_sock_destroy((struct sock_common *)sk);
+
+	return 0;
+}
Signature · 1 line
2.56.0
#10 lore raw

PATCH v3 8/8 bpf: Fix "unresolved symbol tcp_request_sock" build error

In reply to Michal Luczaj

CONFIG_WERROR=y CONFIG_NET=y CONFIG_INET=n build fails:

WARN: resolve_btfids: unresolved symbol tcp_request_sock Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF
make[2]: *** [scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1 make[1]: *** [.../Makefile:1379: vmlinux] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Handle it in the style of commit d82a532a6115 ("bpf: Fix "unresolved symbol" build error with resolve_btfids"): force BTF generation.

---
Technically, since tcp_request_sock embedds inet_request_sock there's no need to explicitly emit for inet_.

---
 net/core/filter.c | 4 ++++
 1 file changed, 4 insertions(+)
net/core/filter.c +4 -0
index 6a67bc2a0c4b..b86529dead65 100644
@@ -12391,6 +12391,10 @@ const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto = {
 
 BPF_CALL_1(bpf_skc_to_tcp_request_sock, struct sock *, sk)
 {
+	/* Ensure BTF for the structs exists even with CONFIG_INET=n. */
+	BTF_TYPE_EMIT(struct inet_request_sock);
+	BTF_TYPE_EMIT(struct tcp_request_sock);
+
 #ifdef CONFIG_INET
 	if (sk && sk->sk_prot == &tcp_prot && sk->sk_state == TCP_NEW_SYN_RECV)
 		return (unsigned long)sk;
Signature · 1 line
2.56.0
#11 lore raw

Re: [PATCH bpf-next v3 8/8] bpf: Fix "unresolved symbol tcp_request_sock" build error

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] bpf: missing Fixes: trailer for tcp_request_sock BTF build fix --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] bpf: missing Fixes: trailer for tcp_request_sock BTF build fix --

commit 96ec9bcc071c52f5537149bdc9a41b81773ef3e6
Author: Michal Luczaj <[email protected]>

Quoted 11 lines

bpf: Fix "unresolved symbol tcp_request_sock" build error

CONFIG_WERROR=y CONFIG_NET=y CONFIG_INET=n build fails:

WARN: resolve_btfids: unresolved symbol tcp_request_sock Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF
make[2]: *** [scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1 make[1]: *** [.../Makefile:1379: vmlinux] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Quoted 4 lines

Handle it in the style of commit d82a532a6115 ("bpf: Fix "unresolved symbol" build error with resolve_btfids"): force BTF generation.

[Severity: Low]
Commit fce557bcef11 ("bpf: Make btf_sock_ids global") exposed btf_sock_ids to resolve_btfids under CONFIG_NET=y, and commit a90765c6f603 ("tcp: move reqsk_fastopen_remove to net/ipv4/tcp_fastopen.c") moved the last CONFIG_NET=y user of struct tcp_request_sock into a file built only under CONFIG_INET=y.

Should this include a Fixes: tag?

Fixes a90765c6f603 ("tcp: move reqsk_fastopen_remove to net/ipv4/tcp_fastopen.c")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#12 lore raw

Re: [PATCH bpf-next v3 8/8] bpf: Fix "unresolved symbol tcp_request_sock" build error

Quoted 31 lines · On 11/7/26 19:14, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] bpf: missing Fixes: trailer for tcp_request_sock BTF build fix --

commit 96ec9bcc071c52f5537149bdc9a41b81773ef3e6
Author: Michal Luczaj <[email protected]>

Quoted 11 lines

bpf: Fix "unresolved symbol tcp_request_sock" build error

CONFIG_WERROR=y CONFIG_NET=y CONFIG_INET=n build fails:

WARN: resolve_btfids: unresolved symbol tcp_request_sock Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF
make[2]: *** [scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1 make[1]: *** [.../Makefile:1379: vmlinux] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Quoted 4 lines

Handle it in the style of commit d82a532a6115 ("bpf: Fix "unresolved symbol" build error with resolve_btfids"): force BTF generation.

[Severity: Low]
Commit fce557bcef11 ("bpf: Make btf_sock_ids global") exposed btf_sock_ids to resolve_btfids under CONFIG_NET=y, and commit a90765c6f603 ("tcp: move reqsk_fastopen_remove to net/ipv4/tcp_fastopen.c") moved the last CONFIG_NET=y user of struct tcp_request_sock into a file built only under CONFIG_INET=y.

Quoted 4 lines

Should this include a Fixes: tag?

Fixes a90765c6f603 ("tcp: move reqsk_fastopen_remove to net/ipv4/tcp_fastopen.c")

Right, that makes sense.

thanks,
Michal

#13 lore raw
In reply to Michal Luczaj
Quoted 9 lines · Michal Luczaj

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/[email protected]
[2]: https://msgid.link/[email protected]

Quoted 8 lines

---
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/[email protected]

Sorry for the delay. Applied.

#14 lore raw
Quoted 19 lines · Alexei Starovoitov
Quoted 9 lines · Michal Luczaj

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/[email protected]
[2]: https://msgid.link/[email protected]

Quoted 8 lines

---
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/[email protected]

Quoted 1 line

Sorry for the delay. Applied.

No problem, thanks.

To follow up on bpf_iter__unix::unix_sk, looks like there's a single helper that will become unusable from iter/unix (once plain-PTR_TO_BTF_ID is gone): bpf_get_socket_cookie(). PTR_TRUSTED then?

Michal

#15 lore raw
Quoted 20 lines · Michal Luczaj
Quoted 19 lines · Alexei Starovoitov
Quoted 17 lines · Michal Luczaj

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/[email protected]
[2]: https://msgid.link/[email protected]

---
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/[email protected]

Quoted 7 lines
Quoted 1 line

Sorry for the delay. Applied.

No problem, thanks.

To follow up on bpf_iter__unix::unix_sk, looks like there's a single helper that will become unusable from iter/unix (once plain-PTR_TO_BTF_ID is gone): bpf_get_socket_cookie(). PTR_TRUSTED then?

I have a patch that 'forks' bpf_get_socket_cookie() into two helpers. One for trusted and one for untrusted.

Also have a patch set that removes legacy ptr_to_btf_id for good. Hopefully will send today or tomorrow.

#16 lore raw
In reply to Michal Luczaj
This series was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This series was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:

Quoted 10 lines · On Sat, 07 Nov 2026 18:58:22 +0100 you wrote:

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/[email protected]
[2]: https://msgid.link/[email protected]

[...]

Here is the summary with links:
- [bpf-next,v3,1/8] selftests/bpf: Remove sockmap update from bpf_iter_unix

    https://git.kernel.org/bpf/bpf/c/271e7fdce958
  - [bpf-next,v3,2/8] bpf, sockmap: Restrict iter-context sockmap updates to iter/sockmap
    https://git.kernel.org/bpf/bpf/c/18f6c47d1097
  - [bpf-next,v3,3/8] selftests/bpf: Add negative test for sockmap update from non-sockmap iter
    https://git.kernel.org/bpf/bpf/c/e16c83fa764f
  - [bpf-next,v3,4/8] bpf, docs: Document BPF_ITER_NOSLEEP
    https://git.kernel.org/bpf/bpf/c/c8d1abec6472
  - [bpf-next,v3,5/8] bpf: Restrict bpf_sock_destroy() to iter/{tcp,udp}
    https://git.kernel.org/bpf/bpf/c/3164b25576aa
  - [bpf-next,v3,6/8] bpf: Mark bpf_iter__sockmap::sk as PTR_TRUSTED
    https://git.kernel.org/bpf/bpf/c/dd6e63efc2be
  - [bpf-next,v3,7/8] selftests/bpf: Add iter/sockmap bpf_sock_destroy() negative test
    https://git.kernel.org/bpf/bpf/c/b7f6028a7bc3
  - [bpf-next,v3,8/8] bpf: Fix "unresolved symbol tcp_request_sock" build error
    https://git.kernel.org/bpf/bpf/c/22bc1ef8ac82

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html