From: willemb@google.com
To: Kyuwon Cho <kyuwoncho18@gmail.com>, Jakub Kicinski <kuba@kernel.org>
Cc: Breno Leitao <leitao@debian.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2 1/1] netdevsim: bound the peer TX queue index in nsim_start_peer_tx_queue()
Date: Sun, 29 Nov 2026 12:41:00 -0500 [thread overview]
Message-ID: <willemb.d4e907f6400@google.com> (raw)
In-Reply-To: <179528810243.2011658.9050974542546209152@gmail.com>
Kyuwon Cho wrote:
> nsim_start_peer_tx_queue() wakes the peer's TX queue with the index of
> the RX queue being polled, and only compares this device's TX queue
> count with the peer's RX queue count. When the device is relinked to a
> peer with fewer TX queues while its RX queues still hold traffic from
> the old peer, the index is past the peer's TX queue array:
> BUG: KASAN: slab-out-of-bounds in nsim_poll
> (include/linux/netdevice.h:3834 drivers/net/netdevsim/netdev.c:60)
> Read of size 8
> Call Trace:
> <IRQ>
> nsim_poll (drivers/net/netdevsim/netdev.c:409)
> __napi_poll.constprop.0 (net/core/dev.c:7997)
> net_rx_action (net/core/dev.c:8217)
> Skip the wake-up when the index is not a TX queue of the peer.
> Fixes: ff2ac4df58ad ("netdevsim: implement peer queue flow control")
> Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
> ---
> drivers/net/netdevsim/netdev.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
> diff --git a/drivers/net/netdevsim/netdev.c
> b/drivers/net/netdevsim/netdev.c
> index eebc02ccc4a9..6e287ae692a8 100644
> --- a/drivers/net/netdevsim/netdev.c
> +++ b/drivers/net/netdevsim/netdev.c
> @@ -53,7 +53,8 @@ static void nsim_start_peer_tx_queue(struct net_device
> *dev, struct nsim_rq *rq)
> /* TX device */
> peer_dev = peer_ns->netdev;
> - if (dev->real_num_tx_queues != peer_dev->num_rx_queues)
> + if (dev->real_num_tx_queues != peer_dev->num_rx_queues ||
> + idx >= peer_dev->real_num_tx_queues)
> goto out;
This works around the out-of-bounds access without fixing why the guard
failed in the first place. Here dev is the RX device and peer_dev is the
TX device, so comparing dev->real_num_tx_queues with
peer_dev->num_rx_queues checks the opposite direction from the packet
flow (nsim_start_xmit() maps tx_dev's real_num_tx_queues onto rx_dev's
num_rx_queues).
The exact same devices-swapped bug exists in nsim_stop_tx_queue() right
below:
if (rx_dev->real_num_tx_queues != tx_dev->num_rx_queues)
return;
Fixing the comparison in both places to check the TX device's
real_num_tx_queues against the RX device's num_rx_queues:
- nsim_start_peer_tx_queue():
if (READ_ONCE(peer_dev->real_num_tx_queues) != dev->num_rx_queues)
- nsim_stop_tx_queue():
if (READ_ONCE(tx_dev->real_num_tx_queues) !=
rx_dev->num_rx_queues)
both fixes the inverted flow-control check (e.g. when a peer lowers its
channels via ethtool -L) and eliminates the OOB access by construction:
rq->napi.index is always < dev->num_rx_queues (allocated in
nsim_init_napi()), and peer_dev->real_num_tx_queues <=
peer_dev->num_tx_queues (where num_tx_queues and num_rx_queues are
immutable after alloc_netdev_mq()), so peer_dev->_tx[idx] is guaranteed
in-bounds even if ethtool -L concurrently reduces
peer_dev->real_num_tx_queues.
Note that READ_ONCE() also avoids a lockless read race against
netif_set_real_num_tx_queues() from nsim_set_channels().
next prev parent reply other threads:[~2026-11-29 17:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 19:32 [PATCH net v2 0/1] netdevsim: bound the peer TX queue index in nsim_start_peer_tx_queue() Kyuwon Cho
2026-11-21 19:32 ` [PATCH net v2 1/1] " Kyuwon Cho
2026-11-27 9:20 ` Jiayuan Chen
2026-11-29 17:41 ` willemb [this message]
2026-11-21 19:38 ` [PATCH net v2 0/1] " netdev-bot+sinfo
2026-11-21 20:00 ` Kyuwon Cho
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=willemb.d4e907f6400@google.com \
--to=willemb@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=kyuwoncho18@gmail.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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