Article View: linux.kernel.netdev
Article #24512[PATCH] vhost/vsock: wait for RCU grace period before rehashing CID
From: Bilal Hashim
Date: Mon, 30 Nov 2026 08:52
Date: Mon, 30 Nov 2026 08:52
73 lines
10744 bytes
10744 bytes
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, calling
synchronize_rcu() after hash_del_rcu() before modifying vsock->guest_cid
and re-inserting into vhost_vsock_hash, and annotating concurrent accesses
to vsock->guest_cid with WRITE_ONCE()/READ_ONCE().
Found by manual code inspection.
Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko")
Cc: stable@vger.kernel.org
Signed-off-by: Bilal Hashim <AeeSec@126.com>
---
drivers/vhost/vsock.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -78,7 +78,7 @@ static struct vhost_vsock *vhost_vsock_g
hash_for_each_possible_rcu(vhost_vsock_hash, vsock, hash, guest_cid,
lockdep_is_held(&vhost_vsock_mutex)) {
- u32 other_cid = vsock->guest_cid;
+ u32 other_cid = READ_ONCE(vsock->guest_cid);
/* Skip instances that have no CID yet */
if (other_cid == 0)
@@ -572,7 +572,7 @@ static void vhost_vsock_handle_tx_kick(s
hdr = virtio_vsock_hdr(skb);
/* Only accept correctly addressed packets */
- if (le64_to_cpu(hdr->src_cid) == vsock->guest_cid &&
+ if (le64_to_cpu(hdr->src_cid) == READ_ONCE(vsock->guest_cid) &&
le64_to_cpu(hdr->dst_cid) ==
vhost_transport_get_local_cid())
virtio_transport_recv_pkt(&vhost_transport, skb,
@@ -856,10 +856,17 @@ static int vhost_vsock_set_cid(struct vh
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;
+ WRITE_ONCE(vsock->guest_cid, guest_cid);
hash_add_rcu(vhost_vsock_hash, &vsock->hash, vsock->guest_cid);
mutex_unlock(&vhost_vsock_mutex);
Technical Details
Message-ID:
<179602872770.13688.17108715679213800277@126.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374043-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374043-linux-kernel-netdev=dewy.ru From: AeeSec@126.com (Bilal Hashim) Newsgroups: linux.kernel.netdev Subject: [PATCH] vhost/vsock: wait for RCU grace period before rehashing CID Date: Mon, 30 Nov 2026 16:52:07 +0800 Organization: Usenet Network Message-ID: <179602872770.13688.17108715679213800277@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1384367"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:e1GlH6O3M15VMUU5++/ipsN9fuk= sha256:m62hTG6MYMwG7iFAGS9Rk47Rm44lX4f3Pj0dGBOAKwg= sha1:8ex1JmSV/z/BigQh1mdKXoycotg= sha256:ILFRxpr85WYCpqM5qBYbnfARkfHZnB8Q7JkDk1L4F8I= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 41E83125FCF; Mon, 30 Nov 2026 11:53:19 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.149 X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=126.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l31uQJNVEJxy; Mon, 30 Nov 2026 11:53:16 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374043-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=126.com X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id B89DB125FCC; Mon, 30 Nov 2026 11:53:07 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 50C79266C9; Mon, 30 Nov 2026 08:52:56 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796028766; b=HGfc7E+sq662VvqaJq7N1WI3S6FtgYhQtLX7VqZI9MppFV/max1D3kSnPvSe3GEFirMc IEA7UKOjCdv76X7M6HD/OIWMV9P1mjdHvAphh3MDrrX7nBzOuxymdvRtRsKUxmU5OZYXz 007GZU884gOEGHPHAE19BGwIqk41BB1D5Gu+damKe9mas6Ev+QA/K/OckYa/U19l4Bkyv Phq04JxmlJ7S2XR5mnpp4E7x5nSG12pGzm5XmAlQdQKFVOo5/trICgxEm6YMBjVBVz5CZ +jvbZuKZ6CRJS+qpLxIuLf7yHatG5aKgbeeVlYCD6ikJhJCFgpX6s1NDNJF+JRdw3Rg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796028766; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:Content-Type:Content-Transfer-Encoding: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:X-CM-TRANSID: X-Coremail-Antispam:X-CM-SenderInfo; bh=KNrnj4+ZROXjstopjHZbpT1F+ndyD9fa/vEbvTY8ntw=; b=SlOxSoqzguPnSn6jUwSrWmGMrt5wlhCGKcX1ECsSP8Wo+MPRpiQj4Qgv+MH6HMUD+a17 sw9iuJa7cUpICCaXOnfcA0Sh8ls1le9Tm8ZYBQLM0x38ienorZZkaO4hh+55rZn9Rnnva mAjmdKJR7BmR1X46uB9gEK2wrGiomreKuTlbRKfojWjz7mlejegDutGqGxzv8NI7U324M +Jtf+hp/WlPGMUTDDEUUI7iJ5mRr9LddjA3QDEkmlLVnS7wI3yXAaaHVO3JU1dVVCiV0k Rio86/hWA4kX5MM7c8Npo1akiEC2PYFK8J59kT57fzO8tEGmqdn7Ccmop/g08RFm4+A== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=mkTLrbEn; dmarc=pass header.from=126.com; spf=pass smtp.mailfrom=126.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2D83606A693; Mon, 30 Nov 2026 08:52:46 +0000 (UTC) X-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=mkTLrbEn X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.8 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796028755; b=0O6u+Ku7cNm/5Zr6DZd6cpKBU1uZFyJosw9x16TtkwYagiuCBgr13nI+WVwAJqD2wObx Rbav5zX+NB2u8HYyIoBwBo3Kvq7BHq3IuPzcttQY20Segbaz7e2YdgkcZ7f9OtShenJbJ k+eSt+0JGzvM+UFDTOWb/iwEHj/pdoiapE4UEA/ZMFOFQFggN9K5WXIBaR2lhzGQID4eH Ks9SDv0dfrIGfqSGH2OWu+TR0nVeInyGmYZVAKIN05Lp6klel6/Xma5Q4n3WRqro6QdGn DymVywiuDqn88ZLFXP7EuVmoMyqeab+Rsa1D9qfs633jhsX2Ub9MOjhJVWE0eFZeTXQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796028755; h=DMARC-Filter:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: Content-Type:Content-Transfer-Encoding:MIME-Version:X-CM-TRANSID: X-Coremail-Antispam:X-CM-SenderInfo; bh=KNrnj4+ZROXjstopjHZbpT1F+ndyD9fa/vEbvTY8ntw=; b=jt/irYD0Ew96J2hJL1XWt7PS+16k5ZADZ0a2VIYS141Ur0rF28YIrTqrrbIzaJCktuV7 LY36ApDKQLWJMPyuhBU1Vur5zq2+bNpI+2Vg1l7/G96VQWjT7Z7/LHhG6ejXxAg+PjLT7 lVgJSziNkJfNAdCm4X8uSgM551EK7/XqhsZRQb527CLmL5iafgF2/8csnfujvCNXvkx0k m0L1dx28inMar4ajjGn1z1ReWhzQD/o+wfMXUdQV6Oaxkw6/NvTzzq58kjGnXAqFqwBlO 8sKisSpJMeMVWJeBJ6TO2Kj6/oPuHBA29i5DJstzACriy/CxtlD6zpykKXtAqxZ/5GQ== X-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=mkTLrbEn; arc=none smtp.remote-ip=117.135.210.8 X-Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.8]) (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 98339606A33D; Mon, 30 Nov 2026 08:52:33 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 98339606A33D X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com X-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=KNrnj4+ZROXjstopjHZbpT1F+ndyD9fa/vEbvTY8ntw=; b=mkTLrbEn2LgO+8+oNaWuTMKhnUyw6v7XqlblTCQ4nJlwRFa+hq+I3isp7VYkdX +f3prKE5u/Ldx8NIDsbv/TOYUZEQvYSvttZ9XVeJdtutlm/tzAd69LSbRALhFwra npgOKPK9TNkqxVie1AnZj6GS8sW/Yv10i9ZIsn+j/vkhQ= X-Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-CM-TRANSID: QCkvCgAHGAo3OQ1reA+OEQ--.58894S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGw15ZF13tr4kWF48WFyUJrb_yoW5WFW3pr yYk3s3tw47JF1j93WfAr47JF1UGwn5Ary7Xr97W3Zayr48Kr1j9rZFga4FkFnrtFZ7XFyr JrsrKF15C34jyaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UGeHDUUUUU= X-CM-SenderInfo: 5dhh2vbf6rjloofrz/xtbBrBh6FWsNOTjiGQAA3H