From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.7 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796143041; b=il4S3pBfj12X38RyMxbb2pSpLuKHrBbAVEjvGejBi6/r7AtqJvI5ZkvEqw9n8G4N1RqN 9+2kEVZLGst01vvuuthABhOK5jgToyOyCSK+boRtwiz3KPrQC+YKjxLnjukADVyMa732y Vr3ZlExQCsf9Pd9Vr8m8WGIlyxXkWj589R5u/GpD4qOdzHjvPfcwpdBGy7J6WcvvAlZs0 0QAcG1LGKaCGR6Ce3hfXqD5egyQD+dMqghp+1+GUgBMhXa4bxTHwEosrbaLIRIuql6Rkl 3JqtCE8jQfBCWb1bRwU1/1AgGH95ixldGSGfHBBvxA6cQ+n1xlTqjeOpN3EtO9z43OQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796143041; h=DMARC-Filter:DKIM-Signature:From:To:Cc:Subject:In-Reply-To: References:Date:Message-ID:Content-Type:Content-Transfer-Encoding: MIME-Version:X-CM-TRANSID:X-Coremail-Antispam:X-CM-SenderInfo; bh=cau1KxFjKwBX3ZPZyGlby8Ul5gt8N7S1NhI7iwQwUaI=; b=sQGWLN8ZZg27uO51tCf28JKdRgDFnHuZeBGew17VEPPc8o9RLxGyAa+Lzw7P3IH6JvWP rMFuAFV3gWtQc4uO79ZgE4v+ha6dcTECN4KdwMqMeS8tYfM94dbK+j3f8Lw+x8jv1URxa Co0hXouQ/z9F1ug5VnSxWWK3JEyJlZXn+LGILQHsCr1H1cp/GLdFQJAG4lwamuu6SC8sr RMnpX5cmbsdnXH2TFuEt0WQSLL+o65VPHw1i47A9MQuAJfOvx0nyJv+PTXhjGOZ2z+mKb h285mbRDcaowbyXMRQrASQN3jhQYwAuKTk3Y72x57cNs2WzxfH4F+jjG5vjDNTstcnA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=FmwfYf64; arc=none smtp.remote-ip=220.197.31.7 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35E86606A31A; Tue, 1 Dec 2026 16:37:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 35E86606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=FmwfYf64 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:To:Subject:Date:Message-ID:Content-Type: MIME-Version; bh=cau1KxFjKwBX3ZPZyGlby8Ul5gt8N7S1NhI7iwQwUaI=; b=FmwfYf64acJpJ1/UTsicnNBqF/zJV4fdfzPwHs1l7bzK6QsCDqLnEymq+zI88h +PSzIWOS9zgqfWLXaV6cbaV3fSMCMN+gIjp0y7einAXcQuDvIoVlXm4wuOnX5UcI f3XSa6mavXvfWbX8LJnmdk+0LQwxIj/NQExHO5xE7RdeU= From: Bilal Hashim To: Stefano Garzarella , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , Eugenio Perez Cc: phind.uet@gmail.com, kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] vhost/vsock: wait for RCU grace period before rehashing CID In-Reply-To: References: <179602872770.13688.17108715679213800277@126.com> Date: Wed, 02 Dec 2026 00:36:28 +0800 Message-ID: <179614298864.2872.3567081270371906851@126.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 X-CM-TRANSID:_____wD33xyP9w5rr4S7EA--.28207S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cr18tFyfuF1rXr1fJFyrJFb_yoW5Jry8pr y5K348Jw4UAF1F93WfJa13AF1UC3WrZry7Wr97W3Z2yr48Kr1jvrZFg3WF9FnFyFZrWFyr tFsrKF15C34jyaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Up6wZUUUUU= X-CM-SenderInfo: 5dhh2vbf6rjloofrz/xtbBnwCEH2sO96C4dwAA35 In vhost_vsock_set_cid(), when a vhost_vsock instance already has a CID assigned, hash_del_rcu(&vsock->hash) is immediately followed by hash_add_rcu(vhost_vsock_hash, &vsock->hash, vsock->guest_cid) without waiting for an RCU grace period. Reusing an hlist_node that was just removed with hash_del_rcu() overwrites its next pointer while concurrent RCU readers in vhost_vsock_get() (called from vhost_transport_send_pkt(), vhost_transport_cancel_pkt(), vhost_vsock_reset_orphans(), etc.) may still be traversing that bucket. This can cause RCU readers to: - jump to another hash bucket or terminate early, missing unrelated active vhost_vsock instances (for example causing vhost_vsock_reset_orphans() to reset healthy connections or vhost_transport_send_pkt() to return -ENODEV); or - loop indefinitely inside an RCU read-side critical section (RCU stall / soft lockup) when two instances in the same bucket are repeatedly rehashed via VHOST_VSOCK_SET_GUEST_CID. Fix this by returning early when the CID is unchanged and calling synchronize_rcu() after hash_del_rcu() before modifying vsock->guest_cid and re-inserting into vhost_vsock_hash. Found by manual code inspection. Fixes: 834e772c8db0 ("vhost/vsock: fix use-after-free in network stack callers") Cc: stable@vger.kernel.org Signed-off-by: Bilal Hashim --- Changes in v2: - Drop READ_ONCE()/WRITE_ONCE() changes on vsock->guest_cid, which are already addressed separately by Nguyen's patch (thanks to Stefano Garzarella for pointing this out). - Update Fixes: tag to 834e772c8db0 ("vhost/vsock: fix use-after-free in network stack callers"), which introduced vhost_vsock_hash. --- drivers/vhost/vsock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 88a3103..622b9cc 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -856,8 +856,15 @@ static int vhost_vsock_set_cid(struct vhost_vsock *vsock, u64 guest_cid) return -EADDRINUSE; } - if (vsock->guest_cid) + if (vsock->guest_cid == guest_cid) { + mutex_unlock(&vhost_vsock_mutex); + return 0; + } + + if (vsock->guest_cid) { hash_del_rcu(&vsock->hash); + synchronize_rcu(); + } vsock->guest_cid = guest_cid; hash_add_rcu(vhost_vsock_hash, &vsock->hash, vsock->guest_cid);