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=RNvkAwMzpnA0XFYGuUSb+a7K3jayk345PQw4BzX10Z6W5W1gfRhH/wYHFhkd+MZ1c7nw TPnQ5wf2Y8z3F8y/rB7bQoOEP0WOlBJ6uzAwS3M8QAg0zMM3oERrXN3vk16urvOTk8SX7 BMdJOQarb9Zpi2Q10O+9tOf8YwycygOLIHWlEOl+KStbuEJHNr731Av1+eVc9LZginR3T sTXu3p3huQypuptPYtpHy+or6qDZCDoZkg1g1ljIdK7bLNYJzRH/Mmdy6qwF45Mr/O777 /D/W7scvQMBLMlKhdhVqnYFkfYEXkAr7RwEGkbGwdMd5EKrdk5EY8i+EbyrHoal9p9Q== 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=daoM2zWWcDdUA0wLzAzum6RwKqrkXLv2uoLt26XrQMQ3dwwcEvrbfts9PqQHjaYI2sFj LH0IQyvMjw9Aps/rLB89zxLU0+tEVw6yfm2Zpy2GJ1AqCiG3zvxpb9YaJ+OiNuNOOasPg xy6EtHQVWhN/VNM9ffEbK3EayuHXXcLQSsaUl0UPiXDpNowx+RMHZckikrtoAY42okHzl kcrsea+JxVxPldGi8NwzkLvGfUA/za9kYhcKqQvnK8G7P/2qEbw/OUGBZqn5lanZomacp NvisTXzU82ZL8UeLjXH7PSCLi/uiW9NwGzTj/hpYEh3+duRrnApdIzl0M+6MhmG25Lg== 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 E5132606A323 for ; Sun, 29 Nov 2026 17:41:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E5132606A323 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, unprotected) 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-92104826f9bso178227636d6.1 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=GJi7eb86kq2rFrnzw/fsRSEc6yq8v+W2TsrxZauAJgeb0tUlA54+Nk4S0DenZh7U95 FNVuKBvkoO6RWdvvOPq4qePme5hsgZUFZjQnOHqtIwxRcnPVffmlkQ6UxKFGPGFVyuW/ AN0MONNV6OWblX9ij1b/e+UqRyq3rbgZ5pbBglas8Meqwfa8QpXqEaG8qJzo1k5g4KD+ tLkus3UEQPJeeFXdQpOEEhcaw5DuUVXt9J+8gercgDtBUsY2hRf4kOUUtTOG0bzTRu6X g6MJEr/SdaIwJerQGPeKfu7ggd9eLOtQ2CS/8GV7z+bs6S0r+WrDb6HHQanV0ilrj0Og j5UQ== X-Forwarded-Encrypted: i=1; AL+hErEffkZtEY0zQclGMlL/AOpDwgAHIwEnA1R/WlhjMeea5pv1HwCPvWr7hLx1DtWM3AahKp8tSpY=@vger.kernel.org X-Gm-Message-State: APuU4Z+VQeumJHK8yDOYqJm94BjaM9k666bn4QSwb88CHG45JJys8SY1 O2Yc1ie9VR4DJ3HSEpfif49mJVSMsTlNjTaIAvyfvSVTFUsJAyd+3gKRqg5/wHF8V5TPGYCi0Y6 /xK9fO/7HWQ== 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: netdev@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().