Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: serialize netif_running() check in enqueue_to_backlog()
@ 2026-06-16 14:13 Eric Dumazet
  2026-06-16 21:39 ` Kuniyuki Iwashima
  2026-06-16 22:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2026-06-16 14:13 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Kuniyuki Iwashima, netdev, eric.dumazet,
	Eric Dumazet, syzbot+965506b59a2de0b6905c, Julian Anastasov

Syzbot reported a KASAN slab-use-after-free in fib_rules_lookup().

The root cause is a race condition where packets can escape the backlog
flushing during device unregistration (e.g., during netns exit).

Commit e9e4dd3267d0 ("net: do not process device backlog during unregistration")
introduced a lockless netif_running() check in enqueue_to_backlog() to
prevent queuing packets to an unregistering device.

However, this creates a TOCTOU race window.

A lockless transmitter (like veth_xmit) can pass
the check before dev_close() clears IFF_UP. If the transmitter is then
delayed, flush_all_backlogs() can run and finish before the transmitter
grabs the backlog lock and queues the packet. The packet then escapes
the flush and triggers UAF later when processed.

Fix this by moving the netif_running() check inside the backlog lock.
This serializes the check with the flush work (which also grabs the lock).
We then either queue the packet before the flush runs (so it gets flushed),
or check netif_running() after the flush/close completes (so it gets dropped).

Fixes: e9e4dd3267d0 ("net: do not process device backlog during unregistration")
Reported-by: syzbot+965506b59a2de0b6905c@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/6a315824.b0403584.28d0ff.0000.GAE@google.com/T/#u
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Julian Anastasov <ja@ssi.bg>
---
 net/core/dev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 731e661d7be6574d5eca4a600e0a5623be4c2485..f81ce83fb3250d591ffa5eeb4c3067f8b75a54ca 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5381,8 +5381,6 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
 	u32 tail;
 
 	reason = SKB_DROP_REASON_DEV_READY;
-	if (unlikely(!netif_running(skb->dev)))
-		goto bad_dev;
 
 	sd = &per_cpu(softnet_data, cpu);
 
@@ -5394,6 +5392,10 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
 	backlog_lock_irq_save(sd, &flags);
 	qlen = skb_queue_len(&sd->input_pkt_queue);
 	if (likely(qlen <= max_backlog)) {
+		if (unlikely(!netif_running(skb->dev))) {
+			backlog_unlock_irq_restore(sd, flags);
+			goto bad_dev;
+		}
 		if (!qlen) {
 			/* Schedule NAPI for backlog device. We can use
 			 * non atomic operation as we own the queue lock.
-- 
2.54.0.1189.g8c84645362-goog


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

* Re: [PATCH net] net: serialize netif_running() check in enqueue_to_backlog()
  2026-06-16 14:13 [PATCH net] net: serialize netif_running() check in enqueue_to_backlog() Eric Dumazet
@ 2026-06-16 21:39 ` Kuniyuki Iwashima
  2026-06-16 22:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Kuniyuki Iwashima @ 2026-06-16 21:39 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	netdev, eric.dumazet, syzbot+965506b59a2de0b6905c,
	Julian Anastasov

On Tue, Jun 16, 2026 at 7:13 AM Eric Dumazet <edumazet@google.com> wrote:
>
> Syzbot reported a KASAN slab-use-after-free in fib_rules_lookup().
>
> The root cause is a race condition where packets can escape the backlog
> flushing during device unregistration (e.g., during netns exit).
>
> Commit e9e4dd3267d0 ("net: do not process device backlog during unregistration")
> introduced a lockless netif_running() check in enqueue_to_backlog() to
> prevent queuing packets to an unregistering device.
>
> However, this creates a TOCTOU race window.
>
> A lockless transmitter (like veth_xmit) can pass
> the check before dev_close() clears IFF_UP. If the transmitter is then
> delayed, flush_all_backlogs() can run and finish before the transmitter
> grabs the backlog lock and queues the packet. The packet then escapes
> the flush and triggers UAF later when processed.
>
> Fix this by moving the netif_running() check inside the backlog lock.
> This serializes the check with the flush work (which also grabs the lock).
> We then either queue the packet before the flush runs (so it gets flushed),
> or check netif_running() after the flush/close completes (so it gets dropped).
>
> Fixes: e9e4dd3267d0 ("net: do not process device backlog during unregistration")
> Reported-by: syzbot+965506b59a2de0b6905c@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/netdev/6a315824.b0403584.28d0ff.0000.GAE@google.com/T/#u
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>

Thanks for catching this !

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

* Re: [PATCH net] net: serialize netif_running() check in enqueue_to_backlog()
  2026-06-16 14:13 [PATCH net] net: serialize netif_running() check in enqueue_to_backlog() Eric Dumazet
  2026-06-16 21:39 ` Kuniyuki Iwashima
@ 2026-06-16 22:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-06-16 22:50 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: davem, kuba, pabeni, horms, kuniyu, netdev, eric.dumazet,
	syzbot+965506b59a2de0b6905c, ja

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 16 Jun 2026 14:13:17 +0000 you wrote:
> Syzbot reported a KASAN slab-use-after-free in fib_rules_lookup().
> 
> The root cause is a race condition where packets can escape the backlog
> flushing during device unregistration (e.g., during netns exit).
> 
> Commit e9e4dd3267d0 ("net: do not process device backlog during unregistration")
> introduced a lockless netif_running() check in enqueue_to_backlog() to
> prevent queuing packets to an unregistering device.
> 
> [...]

Here is the summary with links:
  - [net] net: serialize netif_running() check in enqueue_to_backlog()
    https://git.kernel.org/netdev/net-next/c/46762cefe7f4

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-06-16 22:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-16 14:13 [PATCH net] net: serialize netif_running() check in enqueue_to_backlog() Eric Dumazet
2026-06-16 21:39 ` Kuniyuki Iwashima
2026-06-16 22: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