From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795974062; b=qZmrUtuaaGLMrUrZmMXQ9M3KZX3j5N5RCczBv4A12Aj1SIPzzZLi2tKIZZcmXoCq02es ZyPfPSad4RmpXsWtgPdAmYVY66CRgNAO4LZcYnzh5f1VZgxeSbtFLTs52RIb46rU2m/4T LPVaUtJgory9N0mwyP8Qds1caUj7u476vmfLEAoadu26wrRCl63k56P8Pk0j1AiFlZDFJ rHv3oM9qV00OxwbsVgr7HygFWYSK4T69L+Ivqa7+faEWJ3QtECDfizfx2IRt83Hu63Xsg MbPVdjw8SWq3G7FZvm8TM+hxQYdkAWHrz6bO1Nm+Y3in27tBWKAPvpS5MlJRjDyK7sA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795974062; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=vf1DaxtUaMZ4/7Xv9I6aNQuOiak9+taI6k/haS/lbXs=; b=UlB58R9zQEJybvGiQ4Z3WDLDhtCmd4xtOnb4BFlzt2OigN8NMSbagP0IK9FyNOay/ZOn zM0trX58UPR6L5vCFdj6QYqcnOQMYX6ax0YzD9gE960GIW98FIXMpXNs7fAgotFdFZ2yP mCHBK6GCNKSPc8E7T+lEFSwXsoRwXe1zGZ7Lj/5PPFiy6/Vhx3mpbwI8KvQMMuRJZCQ5n 8QBLIiggbsuj5flZDeUuFe4YFqId03Lt/xgbLolVaHNgylcKnVpqbRNmkr683DHwARYUd tXbCR5h5r4xZ9E3GFgg7yUdCsSgogj9KhwkupyaVmgO1QQFGLfLmDyJJ4HX+odgqZrQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=jP1aZc9+; arc=none smtp.remote-ip=209.85.219.70 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5070606A31C for ; Sun, 29 Nov 2026 17:41:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E5070606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=jP1aZc9+ Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-9210a12765eso159210826d6.0 for ; Sun, 29 Nov 2026 09:41:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795974061; x=1796578861; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=vf1DaxtUaMZ4/7Xv9I6aNQuOiak9+taI6k/haS/lbXs=; b=jP1aZc9+xPwK7ATWjwhIfVUbctyqyA7eNcNL8bZ4uEx6TA6M+qzdNsdbBmGkLFitfe 5vgoByXBgQrQl84EaKSXv5XDqRC8ir8WUHyL5QBbxch/5HUSQNsIZt0So4Eha5j8vkte +//NUFvUsfJpKBCU6A8I3He97haSw9oYCmmVrHsiiq05kbHd2PS3OzkuDP9oiWO7cl3l L3PgFEiFvdSZDEvazTaBdjLH+h6lBdzo/xEwqAQr5s0mclFlLWU0pveDUZ/h5LzvPdf1 qlYKO/2quItt3wBNqdpQ0cwC04DBNHTozH2qnnaozUy3HFkez6sgoV/g5bZaGdnE6lJh dtQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795974061; x=1796578861; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=vf1DaxtUaMZ4/7Xv9I6aNQuOiak9+taI6k/haS/lbXs=; b=vwEWt7xxHonlWMvok/Fhm4RmZbehE9FWcEqGnOhbihDzACAGS8LcPVblh5txWtvAnI HTrmtEfpwB4fiapa8ztBhRWqsIJuJIboQxzSavgIMFZ9KR6ed9Acij4LQ+WO2UbRM240 sPK47wyAaxJx6GFNcAD1X1oe4iuwOIk6e/ICIZ5O9oKo3J+PEusbxnp/Bc8KCaCcE3JX F6d+VdnQVRh+vMyaRIabGlpURl1f8KfTZjy/Ve2c5mqLsykPwuveWapRnW9wSm6bjbcD 1auWomiXBV4Dkfj5LdA9Gr6VpeE9yyZmTJjPU1EspSRe4Ot22RA1dwZ5Fy/Vu5cNgu78 m/kA== X-Forwarded-Encrypted: i=1; AL+hErFdMj8ZteKlAU3g0yx8zI5Jd29ak6U/q2ChP8D5J1TJ9yfSLScwDAb08xMrbMWXmj/VGqRtwiWDgLGfanc=@vger.kernel.org X-Gm-Message-State: APuU4Z/q9GHOmFjjFko3zKdS2a+Utc8rJSekpPyMwhSsK+2TWTu/1fye eF6n6spiRIzXJAg2iMaRw44aAKz1WWYjibPUiEnBV6JBcfP9xfBvci3B+5RGTIagXrbKAqiuN52 Jwg72xuwIfQ== X-Received: from qvbcv7.prod.google.com ([2002:ad4:4d87:0:b0:921:7ad4:8617]) (user=willemb job=prod-delivery.src-stubby-dispatcher) by 2002:ad4:5949:0:b0:921:3153:f1ea with SMTP id 6a1803df08f44-921349de29amr615777036d6.3.1795974060656; Sun, 29 Nov 2026 09:41:00 -0800 (PST) Date: Sun, 29 Nov 2026 12:41:00 -0500 In-Reply-To: <179528810243.2011658.9050974542546209152@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <179528809256.2009509.5007624677973207521@gmail.com> <179528810243.2011658.9050974542546209152@gmail.com> Message-ID: Subject: Re: [PATCH net v2 1/1] netdevsim: bound the peer TX queue index in nsim_start_peer_tx_queue() From: willemb@google.com To: Kyuwon Cho , Jakub Kicinski Cc: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes 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: > > 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 > --- > 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().