* [PATCH net v2] udp: clear skb->dev before running a sockmap verdict
2026-06-03 12:26 [PATCH net] " Sechang Lim
@ 2026-06-03 16:21 ` Sechang Lim
0 siblings, 0 replies; 3+ messages in thread
From: Sechang Lim @ 2026-06-03 16:21 UTC (permalink / raw)
To: willemdebruijn.kernel, davem, edumazet, kuba, pabeni
Cc: horms, daniel, john.fastabend, jakub, aleksander.lobakin, netdev,
bpf, linux-kernel, stable
On the UDP receive path skb->dev is repurposed as dev_scratch (the
truesize/state cache set by udp_set_dev_scratch()), through the
union { struct net_device *dev; unsigned long dev_scratch; } in sk_buff.
When a UDP socket is in a sockmap, sk_data_ready is
sk_psock_verdict_data_ready(), which calls udp_read_skb() -> recv_actor()
(sk_psock_verdict_recv) to run the attached SK_SKB verdict program in softirq.
If that program calls a socket-lookup helper (bpf_sk_lookup_tcp/udp,
bpf_skc_lookup_tcp), bpf_skc_lookup() does:
if (skb->dev)
caller_net = dev_net(skb->dev);
skb->dev still holds the dev_scratch value (a non-NULL integer), so dev_net()
dereferences it as a struct net_device * and the kernel takes a general
protection fault on a non-canonical address in softirq:
Oops: general protection fault, probably for non-canonical address 0x1010000800004a0
CPU: 1 UID: 0 PID: 1406 Comm: syz.2.19 Not tainted 7.1.0-rc6 #1 PREEMPT(full)
RIP: 0010:bpf_skc_lookup net/core/filter.c:7033 [inline]
RIP: 0010:bpf_sk_lookup+0x45/0x160 net/core/filter.c:7047
Call Trace:
<IRQ>
bpf_prog_4675cb904b7071f8+0x12e/0x14e
bpf_prog_run_pin_on_cpu+0xc6/0x1f0
sk_psock_verdict_recv+0x1ba/0x350
udp_read_skb+0x31a/0x370
sk_psock_verdict_data_ready+0x2e3/0x600
__udp_enqueue_schedule_skb+0x4c8/0x650
udpv6_queue_rcv_one_skb+0x3ec/0x740
udp6_unicast_rcv_skb+0x11d/0x140
ip6_protocol_deliver_rcu+0x61e/0x950
ip6_input_finish+0xa9/0x150
NF_HOOK+0x286/0x2f0
ip6_input+0x117/0x220
NF_HOOK+0x286/0x2f0
__netif_receive_skb+0x85/0x200
process_backlog+0x374/0x9a0
__napi_poll+0x4f/0x1c0
net_rx_action+0x3b0/0x770
handle_softirqs+0x15a/0x460
do_softirq+0x57/0x80
</IRQ>
The rmem charge that dev_scratch accounted for is released by skb_recv_udp() on
dequeue, just above, so the scratch is dead by the time recv_actor() runs. Clear
skb->dev so bpf_skc_lookup() falls back to sock_net(skb->sk), which
skb_set_owner_sk_safe() set just above.
Fixes: 965b57b469a5 ("net: Introduce a new proto_ops ->read_skb()")
Cc: stable@vger.kernel.org
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
v2:
- add blank lines around the added codes (Olek)
- use generic block comment style (Olek)
- Cc: stable
net/ipv4/udp.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 0ac2bf4f8759..70f6cbd4ef73 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2011,6 +2011,14 @@ int udp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
}
WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk));
+
+ /*
+ * skb->dev still aliases the UDP rx dev_scratch (its charge was freed
+ * on dequeue above); a sockmap verdict program may deref it via
+ * bpf_sk_lookup_*(), so clear it -> bpf_skc_lookup() uses skb->sk
+ */
+ skb->dev = NULL;
+
return recv_actor(sk, skb);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH net v2] udp: clear skb->dev before running a sockmap verdict
@ 2026-06-03 16:27 Sechang Lim
2026-06-04 1:49 ` Jiayuan Chen
0 siblings, 1 reply; 3+ messages in thread
From: Sechang Lim @ 2026-06-03 16:27 UTC (permalink / raw)
To: willemdebruijn.kernel, davem, edumazet, kuba, pabeni
Cc: horms, daniel, john.fastabend, jakub, aleksander.lobakin, netdev,
bpf, linux-kernel, stable
On the UDP receive path skb->dev is repurposed as dev_scratch (the
truesize/state cache set by udp_set_dev_scratch()), through the
union { struct net_device *dev; unsigned long dev_scratch; } in sk_buff.
When a UDP socket is in a sockmap, sk_data_ready is
sk_psock_verdict_data_ready(), which calls udp_read_skb() -> recv_actor()
(sk_psock_verdict_recv) to run the attached SK_SKB verdict program in softirq.
If that program calls a socket-lookup helper (bpf_sk_lookup_tcp/udp,
bpf_skc_lookup_tcp), bpf_skc_lookup() does:
if (skb->dev)
caller_net = dev_net(skb->dev);
skb->dev still holds the dev_scratch value (a non-NULL integer), so dev_net()
dereferences it as a struct net_device * and the kernel takes a general
protection fault on a non-canonical address in softirq:
Oops: general protection fault, probably for non-canonical address 0x1010000800004a0
CPU: 1 UID: 0 PID: 1406 Comm: syz.2.19 Not tainted 7.1.0-rc6 #1 PREEMPT(full)
RIP: 0010:bpf_skc_lookup net/core/filter.c:7033 [inline]
RIP: 0010:bpf_sk_lookup+0x45/0x160 net/core/filter.c:7047
Call Trace:
<IRQ>
bpf_prog_4675cb904b7071f8+0x12e/0x14e
bpf_prog_run_pin_on_cpu+0xc6/0x1f0
sk_psock_verdict_recv+0x1ba/0x350
udp_read_skb+0x31a/0x370
sk_psock_verdict_data_ready+0x2e3/0x600
__udp_enqueue_schedule_skb+0x4c8/0x650
udpv6_queue_rcv_one_skb+0x3ec/0x740
udp6_unicast_rcv_skb+0x11d/0x140
ip6_protocol_deliver_rcu+0x61e/0x950
ip6_input_finish+0xa9/0x150
NF_HOOK+0x286/0x2f0
ip6_input+0x117/0x220
NF_HOOK+0x286/0x2f0
__netif_receive_skb+0x85/0x200
process_backlog+0x374/0x9a0
__napi_poll+0x4f/0x1c0
net_rx_action+0x3b0/0x770
handle_softirqs+0x15a/0x460
do_softirq+0x57/0x80
</IRQ>
The rmem charge that dev_scratch accounted for is released by skb_recv_udp() on
dequeue, just above, so the scratch is dead by the time recv_actor() runs. Clear
skb->dev so bpf_skc_lookup() falls back to sock_net(skb->sk), which
skb_set_owner_sk_safe() set just above.
Fixes: 965b57b469a5 ("net: Introduce a new proto_ops ->read_skb()")
Cc: stable@vger.kernel.org
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
v2:
- add blank lines around the added codes (Olek)
- use generic block comment style (Olek)
- Cc: stable
net/ipv4/udp.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 0ac2bf4f8759..70f6cbd4ef73 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2011,6 +2011,14 @@ int udp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
}
WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk));
+
+ /*
+ * skb->dev still aliases the UDP rx dev_scratch (its charge was freed
+ * on dequeue above); a sockmap verdict program may deref it via
+ * bpf_sk_lookup_*(), so clear it -> bpf_skc_lookup() uses skb->sk
+ */
+ skb->dev = NULL;
+
return recv_actor(sk, skb);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] udp: clear skb->dev before running a sockmap verdict
2026-06-03 16:27 [PATCH net v2] udp: clear skb->dev before running a sockmap verdict Sechang Lim
@ 2026-06-04 1:49 ` Jiayuan Chen
0 siblings, 0 replies; 3+ messages in thread
From: Jiayuan Chen @ 2026-06-04 1:49 UTC (permalink / raw)
To: Sechang Lim, willemdebruijn.kernel, davem, edumazet, kuba, pabeni
Cc: horms, daniel, john.fastabend, jakub, aleksander.lobakin, netdev,
bpf, linux-kernel, stable
On 6/4/26 12:27 AM, Sechang Lim wrote:
> On the UDP receive path skb->dev is repurposed as dev_scratch (the
> truesize/state cache set by udp_set_dev_scratch()), through the
> union { struct net_device *dev; unsigned long dev_scratch; } in sk_buff.
>
> When a UDP socket is in a sockmap, sk_data_ready is
> sk_psock_verdict_data_ready(), which calls udp_read_skb() -> recv_actor()
> (sk_psock_verdict_recv) to run the attached SK_SKB verdict program in softirq.
> If that program calls a socket-lookup helper (bpf_sk_lookup_tcp/udp,
> bpf_skc_lookup_tcp), bpf_skc_lookup() does:
>
> if (skb->dev)
> caller_net = dev_net(skb->dev);
>
> skb->dev still holds the dev_scratch value (a non-NULL integer), so dev_net()
> dereferences it as a struct net_device * and the kernel takes a general
> protection fault on a non-canonical address in softirq:
>
> Oops: general protection fault, probably for non-canonical address 0x1010000800004a0
> CPU: 1 UID: 0 PID: 1406 Comm: syz.2.19 Not tainted 7.1.0-rc6 #1 PREEMPT(full)
> RIP: 0010:bpf_skc_lookup net/core/filter.c:7033 [inline]
> RIP: 0010:bpf_sk_lookup+0x45/0x160 net/core/filter.c:7047
> Call Trace:
> <IRQ>
> bpf_prog_4675cb904b7071f8+0x12e/0x14e
> bpf_prog_run_pin_on_cpu+0xc6/0x1f0
> sk_psock_verdict_recv+0x1ba/0x350
> udp_read_skb+0x31a/0x370
> sk_psock_verdict_data_ready+0x2e3/0x600
> __udp_enqueue_schedule_skb+0x4c8/0x650
> udpv6_queue_rcv_one_skb+0x3ec/0x740
> udp6_unicast_rcv_skb+0x11d/0x140
> ip6_protocol_deliver_rcu+0x61e/0x950
> ip6_input_finish+0xa9/0x150
> NF_HOOK+0x286/0x2f0
> ip6_input+0x117/0x220
> NF_HOOK+0x286/0x2f0
> __netif_receive_skb+0x85/0x200
> process_backlog+0x374/0x9a0
> __napi_poll+0x4f/0x1c0
> net_rx_action+0x3b0/0x770
> handle_softirqs+0x15a/0x460
> do_softirq+0x57/0x80
> </IRQ>
>
> The rmem charge that dev_scratch accounted for is released by skb_recv_udp() on
> dequeue, just above, so the scratch is dead by the time recv_actor() runs. Clear
> skb->dev so bpf_skc_lookup() falls back to sock_net(skb->sk), which
> skb_set_owner_sk_safe() set just above.
>
> Fixes: 965b57b469a5 ("net: Introduce a new proto_ops ->read_skb()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-04 1:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 16:27 [PATCH net v2] udp: clear skb->dev before running a sockmap verdict Sechang Lim
2026-06-04 1:49 ` Jiayuan Chen
-- strict thread matches above, loose matches on Subject: below --
2026-06-03 12:26 [PATCH net] " Sechang Lim
2026-06-03 16:21 ` [PATCH net v2] " Sechang Lim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox