Netdev List
 help / color / mirror / Atom feed
* [PATCH bpf] bpf, sockmap: Clear the redirect target after the stream parser runs
@ 2026-11-26 10:19 Sechang Lim
  2026-11-26 11:46 ` Jiayuan Chen
  2026-11-26 20:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Sechang Lim @ 2026-11-26 10:19 UTC (permalink / raw)
  To: bpf
  Cc: netdev, john.fastabend, jakub, jiayuan.chen, davem, edumazet,
	kuba, pabeni, horms, ast, cwang

A stream parser can call bpf_sk_redirect_{map,hash}(), which store the
target socket in skb->_sk_redir. sk_psock_strp_parse() never clears it,
and it shares storage with skb->_skb_refdst, so skb_dst_drop() later
passes the socket to dst_release():

  KASAN: null-ptr-deref in range [0x0000000000000128-0x000000000000012f]
  RIP: 0010:percpu_counter_add_batch+0x24/0x220
  Call Trace:
   dst_release.part.0+0xc9/0x180
   skb_release_head_state+0x1cc/0x2f0
   sk_skb_reason_drop+0xbc/0x420
   strp_done+0xcf/0x150
   sk_psock_destroy+0x85e/0xb10

Drop the dst before the parser runs, as the verdict paths do, and clear
the redirect after it. The parser's redirect was never used.

Fixes: e3526bb92a20 ("skmsg: Move sk_redir from TCP_SKB_CB to skb")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
 net/core/skmsg.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index 005e09121f00..4089901a9581 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -1131,7 +1131,9 @@ static int sk_psock_strp_parse(struct strparser *strp, struct sk_buff *skb)
 	prog = READ_ONCE(psock->progs.stream_parser);
 	if (likely(prog)) {
 		skb->sk = psock->sk;
+		skb_dst_drop(skb);
 		ret = bpf_prog_run_pin_on_cpu(prog, skb);
+		skb_bpf_redirect_clear(skb);
 		skb->sk = NULL;
 	}
 	rcu_read_unlock();
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpf, sockmap: Clear the redirect target after the stream parser runs
  2026-11-26 10:19 [PATCH bpf] bpf, sockmap: Clear the redirect target after the stream parser runs Sechang Lim
@ 2026-11-26 11:46 ` Jiayuan Chen
  2026-11-26 20:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jiayuan Chen @ 2026-11-26 11:46 UTC (permalink / raw)
  To: Sechang Lim, bpf
  Cc: netdev, john.fastabend, jakub, davem, edumazet, kuba, pabeni,
	horms, ast, cwang



On 11/26/26 6:19 PM, Sechang Lim wrote:
> A stream parser can call bpf_sk_redirect_{map,hash}(), which store the
> target socket in skb->_sk_redir. sk_psock_strp_parse() never clears it,
> and it shares storage with skb->_skb_refdst, so skb_dst_drop() later
> passes the socket to dst_release():
> 
>   KASAN: null-ptr-deref in range [0x0000000000000128-0x000000000000012f]
>   RIP: 0010:percpu_counter_add_batch+0x24/0x220
>   Call Trace:
>    dst_release.part.0+0xc9/0x180
>    skb_release_head_state+0x1cc/0x2f0
>    sk_skb_reason_drop+0xbc/0x420
>    strp_done+0xcf/0x150
>    sk_psock_destroy+0x85e/0xb10
> 
> Drop the dst before the parser runs, as the verdict paths do, and clear
> the redirect after it. The parser's redirect was never used.
> 
> Fixes: e3526bb92a20 ("skmsg: Move sk_redir from TCP_SKB_CB to skb")
> Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
> ---
>  net/core/skmsg.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> index 005e09121f00..4089901a9581 100644
> --- a/net/core/skmsg.c
> +++ b/net/core/skmsg.c
> @@ -1131,7 +1131,9 @@ static int sk_psock_strp_parse(struct strparser *strp, struct sk_buff *skb)
>  	prog = READ_ONCE(psock->progs.stream_parser);
>  	if (likely(prog)) {
>  		skb->sk = psock->sk;
> +		skb_dst_drop(skb);
>  		ret = bpf_prog_run_pin_on_cpu(prog, skb);
> +		skb_bpf_redirect_clear(skb);
>  		skb->sk = NULL;
>  	}
>  	rcu_read_unlock();


Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>


Theoretically‌, we should reject calling bpf_sk_redirect_{map,hash} in SEC("sk_skb/stream_parser").

Putting helpers into bpf_helper_changes_pkt_data may help but it is weird.

Both "sk_skb/stream_parser" and "sk_skb/stream_verdict" share the same prog type 'BPF_PROG_TYPE_SK_SKB'
otherwise it would have been rejected natively.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpf, sockmap: Clear the redirect target after the stream parser runs
  2026-11-26 10:19 [PATCH bpf] bpf, sockmap: Clear the redirect target after the stream parser runs Sechang Lim
  2026-11-26 11:46 ` Jiayuan Chen
@ 2026-11-26 20:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-26 20:50 UTC (permalink / raw)
  To: Sechang Lim
  Cc: bpf, netdev, john.fastabend, jakub, jiayuan.chen, davem, edumazet,
	kuba, pabeni, horms, ast, cwang

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Thu, 26 Nov 2026 10:19:41 +0000 you wrote:
> A stream parser can call bpf_sk_redirect_{map,hash}(), which store the
> target socket in skb->_sk_redir. sk_psock_strp_parse() never clears it,
> and it shares storage with skb->_skb_refdst, so skb_dst_drop() later
> passes the socket to dst_release():
> 
>   KASAN: null-ptr-deref in range [0x0000000000000128-0x000000000000012f]
>   RIP: 0010:percpu_counter_add_batch+0x24/0x220
>   Call Trace:
>    dst_release.part.0+0xc9/0x180
>    skb_release_head_state+0x1cc/0x2f0
>    sk_skb_reason_drop+0xbc/0x420
>    strp_done+0xcf/0x150
>    sk_psock_destroy+0x85e/0xb10
> 
> [...]

Here is the summary with links:
  - [bpf] bpf, sockmap: Clear the redirect target after the stream parser runs
    https://git.kernel.org/bpf/bpf/c/14f6b10422d6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-26 20:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 10:19 [PATCH bpf] bpf, sockmap: Clear the redirect target after the stream parser runs Sechang Lim
2026-11-26 11:46 ` Jiayuan Chen
2026-11-26 20:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox