Re: [PATCH net] pfcp: drop packets until the device is initialised

From: Simon Horman

Date: Sat Nov 28 2026 - 09:16:14 EST


On Thu, Nov 19, 2026 at 01:29:46PM +0100, Andrey Misiurov wrote:
> 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@xxxxxxxxxxxxxx>
> ---
> 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.

Reviewed-by: Simon Horman <horms@xxxxxxxxxx>