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=1796365461; b=bE2AL3WmrqaqJkHbUaMfy9AjTYeNPaoGsLJ5nTGTyq72NjasYzzvieMPrv7UBz3s2Qf7 c1fUlOTwcbaOES27PpjiHZ4OEqd79iJxAU450Iq9XAPaDULCMpHq4VFm46tXjAih++V0c eWJBbxVLaNV2ocUwCcNq6A0TpB+3MZQa2ifA4hymkkhvAm63iB1sNEDRUvubZucx5FyYD kcza0d/DG0N1j9QnFysGSR7N0BU9piS2J7C9bxNlwlGJ3tY5bRd6/xOjA2jxOQJDMLTpX H3+C6sD2a1vtsmG/JRya/nB+NDIruiynIt28GDy7gCySFfjo00CsQLOQUY8DX8SdwmQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365461; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=DDIenQYWElWhar/QZUMOk5rhyD68jRU3dCgC9UGAKo8=; b=CQ25fNgB7T3CMK3US7+/z1N9B34hTEbnGC+AjVASLVrye6HSaw+pPTYFJdMCEDbLYUmx JHHBuyF5QBK35x/lpwb1Q8UXJuK2fMwC/re56doq+SKOBzwpoz6QG4a4Oz9UIMWNP45MQ PoxVMABg35Q+xY9lXAwzyIZLcnAe/YH/nIcGqP34v2V4DlA0gpaQ36Nb1XwwFdw1Xg1fz ooOAbT7TB/TYob7nNDyYeDVUc7qLtPlOXl5LAEAxgpmvcaRuGplXPD8umrywUWZEd/5Vx 28S67sSf1zHk8M0kUxSztiIyEMKV6BIANpPrstHIm8Hj+O6R/T3YItZinV2Kug7Az/A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fzlTRQlU; 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 9BF9D606A322; Fri, 4 Dec 2026 06:24:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fzlTRQlU Received: by smtp.kernel.org (Postfix) with ESMTPSA id F202F1F000C2; Fri, 4 Dec 2026 06:24:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796365461; bh=DDIenQYWElWhar/QZUMOk5rhyD68jRU3dCgC9UGAKo8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=fzlTRQlUgpPws9KfQUxHh5VQd/VeMXL1Q23qZRq9K7IoRyp+BelVPLUxdCotjvPRl CQn+0Kuw+n3LcQPTG1nse/Sd5ZGk5Jc7AVtJI6QHoidNaM3/cmV02dVK0Cky2D2zXX 3TpB+d5/rnlNFvQ7H/NAfRsoOCwwma54wp9Pyb3vceVbvxl5rOIAFdyRhuq5Psst74 11T8oviJtDJ8gFMyX28wtHuAfbCLfgglHxyF3L7efNIt7gNFdg/nw14mfoBhM0Y7ix m1JNvzHyrCeirsSmi+0/C1t0GYwJ5rMr+PmbnFgWIxOA/lsB6MZWAWnWNeyi3p6i7v OLTIlFcKhDeNA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] vhost/vsock: wait for RCU grace period before rehashing guest_cid Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?S3J6eXN6dG9mIFdvxZs=?= Cc: virtualization@lists.linux.dev, kvm@vger.kernel.org, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <179627895906.335073.17960904565008606745@gmail.com> References: <179627895906.335073.17960904565008606745@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 06:24:20 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] vhost/vsock: vhost_vsock_set_cid() clears existing CID on -EADDRINUSE error - [Medium] vhost/vsock: vhost_vsock_handle_tx_kick() accepts src_cid 0 when guest_cid is 0 -- commit 67b5df7bb320d8c43ffa983b2feb46d9a787de1a Author: Krzysztof Wo=C5=9B vhost/vsock: wait for RCU grace period before rehashing guest_cid This commit serializes vhost_vsock_set_cid() with vsock->dev.mutex, waits for an RCU grace period before rehashing an existing guest_cid, returns early when setting the same CID, and uses READ_ONCE()/WRITE_ONCE() for vsock->guest_cid accesses. > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c > index 88a310390eb0a..e8000c72c3f81 100644 > --- a/drivers/vhost/vsock.c > +++ b/drivers/vhost/vsock.c [ ... ] > @@ -572,7 +572,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_w= ork *work) > hdr =3D virtio_vsock_hdr(skb); > =20 > /* Only accept correctly addressed packets */ > - if (le64_to_cpu(hdr->src_cid) =3D=3D vsock->guest_cid && > + if (le64_to_cpu(hdr->src_cid) =3D=3D READ_ONCE(vsock->guest_cid) && > le64_to_cpu(hdr->dst_cid) =3D=3D > vhost_transport_get_local_cid()) > virtio_transport_recv_pkt(&vhost_transport, skb, [Severity: Medium] Can vhost_vsock_handle_tx_kick() accept packets with src_cid 0 when vsock->guest_cid is cleared to 0? vhost_vsock_set_cid() now clears vsock->guest_cid to 0 before synchronize_rcu() while vhost_vsock_handle_tx_kick() can run under vq->mutex. During that window, a guest packet with src_cid 0 and host dst_cid matches 0 =3D=3D 0 and enters virtio_transport_recv_pkt(). This lets an untrusted guest bypass the fast drop path and reach host socket lookup, locking, and reset packet allocation. Loading guest_cid with READ_ONCE() and checking guest_cid !=3D 0, as vhost_vsock_get() does, would prevent matching the unassigned sentinel. [ ... ] > @@ -842,28 +843,53 @@ static int vhost_vsock_set_cid(struct vhost_vsock *= vsock, u64 guest_cid) [ ... ] > - if (vsock->guest_cid) > + if (vsock->guest_cid) { > hash_del_rcu(&vsock->hash); > + WRITE_ONCE(vsock->guest_cid, 0); > + mutex_unlock(&vhost_vsock_mutex); > + > + /* Wait for concurrent RCU readers before reusing vsock->hash */ > + synchronize_rcu(); > =20 > - vsock->guest_cid =3D guest_cid; > + if (vsock_find_cid(guest_cid)) { > + ret =3D -EADDRINUSE; > + goto out_dev; > + } > + > + mutex_lock(&vhost_vsock_mutex); > + if (vhost_vsock_get(guest_cid, vsock->net)) { > + ret =3D -EADDRINUSE; > + goto out_hash; > + } > + } > + > + WRITE_ONCE(vsock->guest_cid, guest_cid); > hash_add_rcu(vhost_vsock_hash, &vsock->hash, vsock->guest_cid); [Severity: Medium] Should a failed VHOST_VSOCK_SET_GUEST_CID call destroy the device's previous guest_cid? Before this patch, an -EADDRINUSE return left the existing CID intact and hashed. Now, if another VM claims the target CID during synchronize_rcu(), the re-check returns -EADDRINUSE after vsock->hash has been unlinked and vsock->guest_cid cleared to 0. Host-to-guest sends to the old CID then fail with -ENODEV and vhost_transport_cancel_pkt() can no longer find the device to purge queued packets, while existing connections remain stranded without an orphan reset. Allocating an RCU-freed hash entry wrapper (hlist_node, rcu_head, vsock, and immutable guest_cid) before taking vhost_vsock_mutex would let the new entry be inserted before retiring the old one with kfree_rcu(), avoiding both synchronize_rcu() and this destructive error path. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179627895906.335073= .17960904565008606745@gmail.com?part=3D1