From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0F582E542C for ; Sat, 22 Aug 2026 16:46:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787417167; cv=none; b=tK6xhG60mCtI/OvdscPbZ2a6iZCmDBUOa4GDF3TNsLjCsTiPrt3Fgdj4DwJhLNgaUta1VUrOoq5MZZFC3DUIyIEGQhEw2IuY5WkF6IBc1awS3gEtPB9/z3+aaXJhA7RLAWPmZ+9eCkW7AsMatqpBbYxaC1mGP1mBXj3C1FKTq/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787417167; c=relaxed/simple; bh=RZnSBXG7H5IfVESK5dV+papTZf4bB2+5pFdMF6y80Cc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=V6XSyjufnDF3stjLCPrcHzwSu7uyUrYmvzETLKzsElgTGlk6EulwjpMyYqqfQcZBvtZEd5m3nys7+2kLJYC/Pj/EqJS2PY6HIEJGCaSfBu3gWb4Afxl+a+R0CytoKnQDOby2X8OlRqEo3EvP9TBZHOn8zB92S0hMQBMnH/xqzQM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=o50PTwrJ; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o50PTwrJ" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-c9d290216d0so176934a12.3 for ; Sat, 22 Aug 2026 09:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787417165; x=1788021965; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=zxjo65j0/PC8LNmS95fdZuou6hT1feMI3IHbQQyBjIE=; b=o50PTwrJBuwau13sNGF5h4O3fMo5o27/5Sy3+pjsyIesNKORDx6wwWGX0kKBL83BrD BsYaVVmDe0VuuL2boO8nOBgHnqTnEdua0MNVB3TzccDP0QAuj+qPb7Xrje2h+HJS0ZLv ofHR9qgWj564C/ap9pb13IqRfveb0K4H+d3xJ0sE1VMiE1y8Xre3g5ObJjvhjac7IqHZ dk240TvBQjk2PUZNlz97PlBdO3qF4kAFNJIGmWLpyeZMkoaxJ5gf2qbX7HaNVEJhiJIu Qot6JYoE6473NJg8I+1091cFGPiL1fDaz/Pt81NyEO0VKIE+zJqapI5Mxis4pT9IJwH4 5iCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787417165; x=1788021965; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zxjo65j0/PC8LNmS95fdZuou6hT1feMI3IHbQQyBjIE=; b=DEsvenh7UNzKgt0s+Cgj6wfEdDqUn3o+ZW/Jq6gyr5+1Xu20wGP7uWilbexhGVXtWE yBQ5oYvJ2rM77leAJlyi802o/BahuAsjJsrwJiqVqlfPFMSKm9GrdN+yDwDb64xgmows 4dj7/JvgpknbXNJh5s1PW7NucCAkR+yYwh4vtsw8L+Vm0V7BTMKaeLBuQpmiNKniUktO Naw4N7PH8U8K4o0G5yLfTNrwyJNiwf9jEPAxXybtZ+eX0o91kBwWFrPff4/ZgZZYFw/G 5QcnZPKHk95UNZ4OpOjqgkpTeZu+nQjxo4RB6eC75Z7U1BZPtHiDzqbEWhQBFPJtNd75 uv/A== X-Forwarded-Encrypted: i=1; AHgh+RorxNetvcsyTK/lfzTg4tbLm/dOUYgjTB2X1Haqk6jPkDxtF2KyDWyBFL4sm0DCUv5ps0rUb2BFQTdMdsw=@vger.kernel.org X-Gm-Message-State: AFuF++my9n/ai6rVrxyv3UB7n82600kMKzOXZYQ2Vy/XjL9GTE/0nmrw YtzveNPUtR+8VKgeb0jE7DaB5pSJnS733q8FAP2vc7UBrDd/Qf2rDyRa5NOiV4O/xVY= X-Gm-Gg: AR+sD132Xrgyfxv+t6x5hgXcy38uphC6IIrJ/xuBioV8Leex/3aH+erVjKMrLa3NXB/ VM981Muq4MTuhfNCdNR//LIFv+FxOKYiyChsddhHJcw5xVzZNChoWy6KZnTbXvKNHLgpO69YxPO lJZmOpFtd51n0PsE8NT3bL/4m2xpm2QBaBoVr8Jwn9ryNvThm7IFgQrcaKP1npTGgMIdB29ZmZZ ZCBxKms41xxzYYpW5FSL+j0f5i5LS9IH1ZZFpzawJLSUTrW2tddvixqYR6vpo/77elD13RptBMq kI/2q9vidFQotyRu/syLcnWYnJIhIfuOYBcaT/Y8ykjxpvVli5ujEYflW+U/Ljlrx0lv2wSVFo6 c69fsocQOFaPAPH3XC8LwZNz5AP6e6NdZGAh49f0eJSck14MkaFddY8aGruY9bG4dEyOrnppEtB ptu9ZhrOytM8gSNbvh7bSXi0BGauUQP0dwRrhXRxI/c/Y+mea5S0nzD1CHNt+fmYF2poBWJkdH2 dLnejncUF3q+6sTd2C1NTDeVRjH8d01TnzvqWjmJDreFGTdUfb+Fws= X-Received: by 2002:a17:903:b43:b0:2d2:a952:2628 with SMTP id d9443c01a7336-2d64b0d7b26mr129424855ad.2.1787417164695; Sat, 22 Aug 2026 09:46:04 -0700 (PDT) Received: from localhost.localdomain (45.78.65.84.16clouds.com. [45.78.65.84]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-327f9209fafsm15623986eec.23.2026.08.22.09.46.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Aug 2026 09:46:04 -0700 (PDT) From: Chengfeng Ye To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Asias He Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Chengfeng Ye , stable@vger.kernel.org Subject: [PATCH net] vsock/virtio: flush works in dependency order Date: Sun, 23 Aug 2026 00:45:56 +0800 Message-ID: <20260822164556.3750959-1-nicoyip.dev@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit virtio_vsock_remove() stops the virtqueues and then flushes each work item before freeing the enclosing virtio_vsock. The current order does not account for dependencies between those items: tx_work may queue send_pkt_work, and send_pkt_work may queue rx_work. In particular, send_pkt_work can set restart_rx and release tx_lock. The remove path can then stop the queues and flush rx_work before send_pkt_work queues it. Although the later send_pkt_work flush waits for that producer to finish, nothing waits for the newly queued rx_work, so kfree(vsock) can race with it. KASAN reported: BUG: KASAN: slab-use-after-free in virtio_transport_rx_work+0x487/0x4b0 Read of size 8 at addr ffff888114c2b008 by task kworker/1:1/47 Workqueue: virtio_vsock virtio_transport_rx_work Call Trace: virtio_transport_rx_work+0x487/0x4b0 process_one_work+0x688/0x1120 worker_thread+0x45b/0xd10 Allocated by task 1: virtio_vsock_probe+0xef/0x6b0 Freed by task 84: kfree+0x131/0x3c0 virtio_vsock_remove+0xd1/0x100 Flush the works in producer-to-consumer order. virtio_vsock_vqs_del() has already disabled the queue callbacks and cleared the run flags, so after tx_work and send_pkt_work are drained, no source remains that can queue rx_work after its flush. Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko") Cc: stable@vger.kernel.org Signed-off-by: Chengfeng Ye --- net/vmw_vsock/virtio_transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 96c9fe8d357c..4f9aa9c4c3aa 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -872,10 +872,10 @@ static void virtio_vsock_remove(struct virtio_device *vdev) /* Other works can be queued before 'config->del_vqs()', so we flush * all works before to free the vsock object to avoid use after free. */ - flush_work(&vsock->rx_work); flush_work(&vsock->tx_work); flush_work(&vsock->event_work); flush_work(&vsock->send_pkt_work); + flush_work(&vsock->rx_work); mutex_unlock(&the_virtio_vsock_mutex); -- 2.43.0