mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] pfcp: drop packets until the device is initialised
@ 2026-11-19 12:29 Andrey Misiurov
  0 siblings, 0 replies; only message in thread
From: Andrey Misiurov @ 2026-11-19 12:29 UTC (permalink / raw)
  To: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Wojciech Drewek, Simon Horman, netdev, linux-kernel, Andrey Misiurov

pfcp_newlink() creates the PFCP UDP socket (port 8805) and publishes it
(sk_user_data = pfcp, encap_rcv = pfcp_encap_recv) before
register_netdevice() runs ndo_init, which is where pfcp->dev is set. A
datagram that arrives in that window passes the "pfcp != NULL" check in
pfcp_encap_recv() and then dereferences a NULL pfcp->dev:

  BUG: kernel NULL pointer dereference, address: 0000000000000108
  #PF: supervisor read access in kernel mode
  Oops: 0000 [#1] SMP PTI
  CPU: 0 PID: 26516 Comm: pfcp_race
  RIP: 0010:pfcp_encap_recv+0xeb/0x1d0 [pfcp]
  Call Trace:
   <IRQ>
   udp_queue_rcv_one_skb+0x24a/0x560
   udp_queue_rcv_skb+0x4f/0x80
   udp_unicast_rcv_skb+0x78/0xa0
   __udp4_lib_rcv+0x519/0x5f0
   udp_rcv+0x25/0x40
   ip_protocol_deliver_rcu+0xd4/0x210
   ip_local_deliver_finish+0x86/0x110
   ip_local_deliver+0x65/0x110
   ip_rcv+0x17d/0x190
   __netif_receive_skb_one_core+0x8d/0xa0

The window is wide when register_netdevice() fails before ndo_init (e.g. an
invalid name): the socket stays live until pfcp_del_sock() on the error
path. A narrower window also exists on the normal success path.

Drop the packet while pfcp->dev is not yet set or the device is not
running.

Fixes: 76c8764ef36a ("pfcp: add PFCP module")
Signed-off-by: Andrey Misiurov <amisiurov@cloudlinux.com>
---
Found during a backport review.

Reproduced on ubuntu-resolute 7.0.0-42: flood UDP :8805 while creating a
pfcp link with an invalid name (register_netdevice() fails before ndo_init)
-> the NULL-deref above (kdump vmcore). With the fix the same run stays clean.

 drivers/net/pfcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/pfcp.c b/drivers/net/pfcp.c
--- a/drivers/net/pfcp.c
+++ b/drivers/net/pfcp.c
@@ -61,7 +61,7 @@
 		goto drop;

 	pfcp = rcu_dereference_sk_user_data(sk);
-	if (unlikely(!pfcp))
+	if (unlikely(!pfcp || !pfcp->dev || !netif_running(pfcp->dev)))
 		goto drop;
 
 	unparsed = pfcp_hdr(skb);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19 12:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 12:29 [PATCH net] pfcp: drop packets until the device is initialised Andrey Misiurov

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

all inboxes | Powered by JetHome®