From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794061860; b=qEDKnF3mRmZ2WlJH3H2qQ/iJl1a4zBWsCWQgwBljQ5xu3QH9WrfzY+xJTMSRO55YH6xx uVgHa52U+QvqKnx7GjitPDAij7b+8RlrBrWSIrWuXIXyiT8eG5CSdGp3W/Bbi456tBLdE EKFkommt7Cxj7K4ikv/0ErSe5C+9JQypznXhxPIawsUKMucTXIm+My5gSHLzbrALe+ucg W4kIMl+as8b5dqYsT3bvQU/XY00JcbOLoOleEYVZHDfaERsII0ntLGtNWxctu79Bh37qr KaXSEMwEWcm7VDhGnA59Ce+p/Qu9M/O0pjrQZgJHeFJfikqAlQT3O0HDrX6Wl+Ewayg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794061860; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=+VnnomsQnz72YXdOOHxbjqRMp0lP6WT5QPtSuVq3+mg=; b=jFyl31/biirXPyExokQtD7//sCoi4eQjr54aUiRXR66qDTc5Er90ARoNHrzfybXm65P4 /j4P6m5yDfhOa9H+k9DuSlSmVwaVUXMXQ0biMcUyDnRgBX2CtvQtR0KnuE4ay3DZOLFRY klZe0B1iETkum3luscSouxxBVYaujtldQ64Cu57fjKY9IMGfqApvjKz70mbh1xvtMlzeW DSU3uzDHihB+HgkcNnxf+FImGUXbLwuyW8gvz5jM71RDEMRAF7NzZzbD0UbNyMjWgECtM 12SCILgDMidl99WQIeQxHfcqH+E070mQ75fVLf8KDUr5b85Wr5GlkKBXIWVm3bq6+0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uDQ17vW7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF8FC606A32C; Sat, 7 Nov 2026 14:30:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uDQ17vW7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D7C91F0089F; Sat, 7 Nov 2026 14:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794061859; bh=+VnnomsQnz72YXdOOHxbjqRMp0lP6WT5QPtSuVq3+mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uDQ17vW7zw5WP2hGZqzHMPnJy5+xPYSg1R+zmePw4+ghIcNixk7neoQk65l80uUzt WXdcQOm/X0YaAaCxDmw0y3JxxG4tVACCx2PMih36YBHTK1L9OzfBdOpaS356iR1NB1 /3DIXXABbK2NGs4H0BJymDriisXSl5H6eZPh6oJI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, co+d17c2bc750a9cbbb@bugs.sh, Weiming Shi , Paolo Abeni , Sasha Levin Subject: [PATCH 6.12 0877/1536] virtio_net: atomically disable rx mode work Date: Sat, 7 Nov 2026 08:48:13 -0500 Message-ID: <20261107135022.179345387@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134957.653319350@linuxfoundation.org> References: <20261107134957.653319350@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Weiming Shi [ Upstream commit 1234707482053f1d1ac7c5756207d2c29057974c ] virtio-net uses a boolean to gate rx_mode_work during device teardown. The flag is changed under RTNL, but ndo_set_rx_mode checks it under the address-list lock. A callback can therefore pass the check and enqueue work after teardown has flushed it. The work is also enabled before late probe operations that can fail, allowing probe unwind to free the netdev with work still queued. KASAN reports the worker using a virtqueue that probe unwind already freed: BUG: KASAN: slab-use-after-free in virtqueue_add_split Workqueue: events virtnet_rx_mode_work Call Trace: virtqueue_add_split (drivers/virtio/virtio_ring.c:706) virtqueue_add_sgs (drivers/virtio/virtio_ring.c:2839) virtnet_send_command_reply (drivers/net/virtio_net.c:3565) virtnet_rx_mode_work (drivers/net/virtio_net.c:3833) process_one_work (kernel/workqueue.c:3322) worker_thread (kernel/workqueue.c:3405) Freed by task 119: kfree (mm/slub.c:6625) vp_del_vq.isra.0 (drivers/virtio/virtio_pci_common.c:259) vp_del_vqs (drivers/virtio/virtio_pci_common.c:285) virtnet_probe (drivers/net/virtio_net.c:7129) Use the workqueue disable mechanism to atomically reject new queue attempts and drain running work. Keep work disabled until probe succeeds or restore has reattached the netdev, then enable it and replay receive-mode state for a running interface. Disable it before resource teardown in freeze and remove. Fixes: b9f7425239a0 ("virtio-net: convert rx mode setting to use workqueue") Cc: stable@vger.kernel.org Reported-by: Assisted-by: LLM Signed-off-by: Weiming Shi Link: https://patch.msgid.link/20261017114237.2786302-2-bestswngs@gmail.com Signed-off-by: Paolo Abeni [ sashal: adjusted context to match the existing virtio-net device lifecycle code ] Signed-off-by: Sasha Levin --- drivers/net/virtio_net.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 2c62371666cd5..bf4f177417384 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -437,9 +437,6 @@ struct virtnet_info { /* Work struct for setting rx mode */ struct work_struct rx_mode_work; - /* OK to queue work setting RX mode? */ - bool rx_mode_work_enabled; - /* Does the affinity hint is set for virtqueues? */ bool affinity_hint_set; @@ -678,16 +675,13 @@ static void disable_delayed_refill(struct virtnet_info *vi) static void enable_rx_mode_work(struct virtnet_info *vi) { - rtnl_lock(); - vi->rx_mode_work_enabled = true; - rtnl_unlock(); + if (enable_work(&vi->rx_mode_work) && netif_running(vi->dev)) + schedule_work(&vi->rx_mode_work); } static void disable_rx_mode_work(struct virtnet_info *vi) { - rtnl_lock(); - vi->rx_mode_work_enabled = false; - rtnl_unlock(); + disable_work_sync(&vi->rx_mode_work); } static void virtqueue_napi_schedule(struct napi_struct *napi, @@ -3688,8 +3682,7 @@ static void virtnet_set_rx_mode(struct net_device *dev) { struct virtnet_info *vi = netdev_priv(dev); - if (vi->rx_mode_work_enabled) - schedule_work(&vi->rx_mode_work); + schedule_work(&vi->rx_mode_work); } static int virtnet_vlan_rx_add_vid(struct net_device *dev, @@ -5515,7 +5508,6 @@ static void virtnet_freeze_down(struct virtio_device *vdev) /* Make sure no work handler is accessing the device */ flush_work(&vi->config_work); disable_rx_mode_work(vi); - flush_work(&vi->rx_mode_work); netif_tx_lock_bh(vi->dev); netif_device_detach(vi->dev); @@ -5538,7 +5530,6 @@ static int virtnet_restore_up(struct virtio_device *vdev) virtio_device_ready(vdev); enable_delayed_refill(vi); - enable_rx_mode_work(vi); if (netif_running(vi->dev)) { err = virtnet_open(vi->dev); @@ -5549,6 +5540,8 @@ static int virtnet_restore_up(struct virtio_device *vdev) netif_tx_lock_bh(vi->dev); netif_device_attach(vi->dev); netif_tx_unlock_bh(vi->dev); + + enable_rx_mode_work(vi); return err; } @@ -6610,6 +6603,7 @@ static int virtnet_probe(struct virtio_device *vdev) INIT_WORK(&vi->config_work, virtnet_config_changed_work); INIT_WORK(&vi->rx_mode_work, virtnet_rx_mode_work); + disable_work(&vi->rx_mode_work); spin_lock_init(&vi->refill_lock); if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) { @@ -6752,8 +6746,6 @@ static int virtnet_probe(struct virtio_device *vdev) if (vi->has_rss || vi->has_rss_hash_report) virtnet_init_default_rss(vi); - enable_rx_mode_work(vi); - /* serialize netdev register + virtio_device_ready() with ndo_open() */ rtnl_lock(); @@ -6849,6 +6841,8 @@ static int virtnet_probe(struct virtio_device *vdev) goto free_unregister_netdev; } + enable_rx_mode_work(vi); + pr_debug("virtnet: registered device %s with %d RX and TX vq's\n", dev->name, max_queue_pairs); @@ -6900,7 +6894,6 @@ static void virtnet_remove(struct virtio_device *vdev) /* Make sure no work handler is accessing the device. */ flush_work(&vi->config_work); disable_rx_mode_work(vi); - flush_work(&vi->rx_mode_work); virtnet_free_irq_moder(vi); -- 2.53.0