Netdev List
 help / color / mirror / Atom feed
From: Zhang Cen <rollkingzzc@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	zerocling0077@gmail.com, 2045gemini@gmail.com,
	Zhang Cen <rollkingzzc@gmail.com>
Subject: [PATCH] netpoll: normalize skb->dev to the netpoll device
Date: Fri, 15 May 2026 13:05:11 +0800	[thread overview]
Message-ID: <20260515050511.106309-1-rollkingzzc@gmail.com> (raw)

__netpoll_send_skb() always transmits through np->dev and queues busy
packets on np->dev->npinfo->txq, but it leaves skb->dev unchanged.
Stacked callers such as DSA and macvlan can reach netpoll with skb->dev
still naming the upper device while np->dev is the lower device that
owns the netpoll state.

If the skb has to be deferred, queue_process() later dequeues it from
the lower device's txq but retries it through skb->dev. That can
re-enter the upper ndo_start_xmit path on an already transformed skb,
and if the upper device disappears before the lower txq drains the
workqueue can dereference a stale skb->dev pointer.

The buggy scenario involves two paths, with each column showing the
order within that path:

path A label: netpoll enqueue path   path B label: upper-device teardown
1. A stacked ndo_start_xmit calls    1. Another task unregisters the
   netpoll_send_skb() on a lower        upper stacked net_device while
   device netpoll instance.            the lower npinfo stays alive.
2. __netpoll_send_skb() uses        2. free_netdev() releases the upper
   np->dev and queues the skb on       device.
   np->dev->npinfo->txq.
3. The queued skb still keeps       3. The lower txq still owns the
   skb->dev pointing at the upper      deferred skb.
   device.
4. queue_process() later dequeues   4. queue_process() dereferences
   from the lower txq and retries      that stale upper skb->dev.
   via skb->dev.

Normalize skb->dev to np->dev before the direct transmit attempt and
before any fallback enqueue. This keeps both the immediate and deferred
netpoll paths in the same device and queue domain that already owns
npinfo->txq.

Sanitizer validation reported:
KASAN slab-use-after-free in queue_process()
Read of size 8
Call trace:
  dump_stack_lvl() (?:?)
  print_report() (?:?)
  srso_alias_return_thunk() (arch/x86/include/asm/nospec-branch.h:375)
  __virt_addr_valid() (?:?)
  kasan_complete_mode_report_info() (?:?)
  kasan_report() (?:?)
  queue_process() (net/core/netpoll.c:88)
  kasan_check_range() (?:?)
  __kasan_check_read() (?:?)
  process_one_work() (kernel/workqueue.c:3200)
  assign_work() (kernel/workqueue.c:1201)
  worker_thread() (?:?)
  kthread() (?:?)
  ret_from_fork() (?:?)
  __switch_to() (?:?)
  __switch_to_asm() (arch/x86/include/asm/switch_to.h:9)
  ret_from_fork_asm() (?:?)
  kasan_save_stack() (mm/kasan/common.c:52)
  kasan_save_track() (mm/kasan/common.c:74)
  kasan_save_free_info() (?:?)
  __kasan_slab_free() (?:?)
  kfree() (?:?)
  kvfree() (mm/slub.c:6876)
  netdev_release() (net/core/net-sysfs.c:2227)
  device_release() (?:?)
  kobject_put() (lib/kobject.c:730)
  put_device() (drivers/base/core.c:3810)
  free_netdev() (net/core/dev.c:12164)
  full_proxy_write() (?:?)
  vfs_write() (fs/read_write.c:668)
  ksys_write() (fs/read_write.c:729)
  __x64_sys_write() (?:?)
  x64_sys_call() (arch/x86/entry/syscall_64.c:35)
  do_syscall_64() (arch/x86/entry/syscall_64.c:87)
  entry_SYSCALL_64_after_hwframe() (?:?)

Signed-off-by: Zhang Cen <rollkingzzc@gmail.com>

---
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -319,6 +319,8 @@
 	lockdep_assert_irqs_disabled();
 
 	dev = np->dev;
+	/* npinfo->txq belongs to np->dev, so retries must stay bound to it. */
+	skb->dev = dev;
 	rcu_read_lock();
 	npinfo = rcu_dereference_bh(dev->npinfo);
 

                 reply	other threads:[~2026-05-15  5:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260515050511.106309-1-rollkingzzc@gmail.com \
    --to=rollkingzzc@gmail.com \
    --cc=2045gemini@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=zerocling0077@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox