Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Kyuwon Cho
Mon, 30 Nov 2026 05:56
[PATCH net v3 0/1] netdevsim: fix the inverted queue count check in flow control
Author: Kyuwon Cho
Date: Mon, 30 Nov 2026 05:56
Date: Mon, 30 Nov 2026 05:56
27 lines
11993 bytes
11993 bytes
nsim_start_peer_tx_queue() can wake a TX queue past the end of the
peer's TX queue array after the device is relinked to a peer with fewer
TX queues; KASAN reports a slab-out-of-bounds read in nsim_poll(). The
cause is that the queue count checks in nsim_start_peer_tx_queue() and
nsim_stop_tx_queue() compare the RX device's TX queues with the TX
device's RX queues. The patch compares the right pair, which also keeps
the woken queue inside the peer's TX queue array.
v3: fix the comparison in both functions instead of bounding the index
(Willem). Jiayuan's Reviewed-by is dropped because the fix changed.
v2: https://lore.kernel.org/netdev/179528809256.2009509.5007624677973207521@gmail.com/
send the patch inline instead of as an attachment (Jakub).
v1: https://lore.kernel.org/netdev/179505710275.3511681.13434978152402269948@gmail.com/
The issue was found by an LLM-guided test generator that we are
developing as a research prototype. With the patch, the reproducer from
v1 no longer triggers the KASAN report. Tested on net e2fb9368a416.
Kyuwon Cho (1):
netdevsim: fix the inverted queue count check in flow control
drivers/net/netdevsim/netdev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--
2.43.0
[PATCH net v3 1/1] netdevsim: fix the inverted queue count check in flow control
Author: Kyuwon Cho
Date: Mon, 30 Nov 2026 05:56
Date: Mon, 30 Nov 2026 05:56
61 lines
13581 bytes
13581 bytes
nsim_start_xmit() maps the TX queues of the sending device onto the RX
queues of its peer, and flow control relies on one TX queue per RX
queue: nsim_stop_tx_queue() stops TX queue N when RX queue N is full,
and nsim_start_peer_tx_queue() wakes TX queue N after polling RX queue
N. Both skip this unless the queue counts match, but they compare the
wrong pair, the RX device's real_num_tx_queues with the TX device's
num_rx_queues.
A device with 8 queues whose channels were reduced to 1 with ethtool -L
passes this check once it is relinked to a peer with a single queue. If
one of its upper RX queues still holds traffic from the old peer,
nsim_start_peer_tx_queue() wakes a TX queue that the peer does not have:
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)
Compare the TX device's real_num_tx_queues with the RX device's
num_rx_queues in both places. The polled RX queue index is below the RX
device's num_rx_queues, so the queue woken is then always inside the
peer's TX queue array. nsim_set_channels() can change
real_num_tx_queues of the other device at the same time, so read it
with READ_ONCE().
Fixes: ff2ac4df58ad ("netdevsim: implement peer queue flow control")
Suggested-by: Willem de Bruijn <willemb@google.com>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
drivers/net/netdevsim/netdev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index eebc02ccc4a9..b0c4c00577e9 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -53,7 +53,7 @@ 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 (READ_ONCE(peer_dev->real_num_tx_queues) != dev->num_rx_queues)
goto out;
txq = netdev_get_tx_queue(peer_dev, idx);
@@ -73,7 +73,7 @@ static void nsim_stop_tx_queue(struct net_device *tx_dev,
/* If different queues size, do not stop, since it is not
* easy to find which TX queue is mapped here
*/
- if (rx_dev->real_num_tx_queues != tx_dev->num_rx_queues)
+ if (READ_ONCE(tx_dev->real_num_tx_queues) != rx_dev->num_rx_queues)
return;
/* rq is the queue on the receive side */
--
2.43.0
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads