From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144335; b=jTUaX0pGY82sQ+ibqMk8dhG8DhbF402at+UgyHezzMmFJRKXCeDo4VTOwosvtbx9IvTM yJTfNZt1FQ9ZcR1JBiuTjal/KMrZIR/ImtIGS/L2fPtFx5kdrKFnAM0jFRisff9GvnyGB KUVGZL8aSBsLvr59hW8if1RqVoxdSIMS+8WfnqEqUErRiVbSXsnY0+uFC2a6FYJ/bZ+Pn cl2/F881UYxO7Ykr353+uc2WWEtHcuULOqyzajUJO2U4j0aidYPFwrobRn0zpq8Yq8U8Q 6dRtO1ut7hRN/9E3Cqrj24iTgSYLdnicCQg6S3r1RYT07pC8L/2RK89KdF8SbM8zwmQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144335; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=4+0eNwziAEFrpY1C06WPxtp+rK/4xdBpSDPXugSrDbM=; b=ay3pqgSluFTRxtajfrZ6dqD5FHbSw0zpdK65lIa9ltWyX8swIHeYpFzQs5KzoiUh8THm 8/xpAExrn2b7TcJr1NVBbx3//qSRgNtUyNNqQ2jcaWrohAFOvCocV25OgMXj9X7SX4nSn jZhCnlMDtnhMk0DWhuecXjydnwHZrG1oXpI9KbfHsNuqp8CxW01h+Z1/VQQLYl/4Et6bW 421nnasVV+N8oe99cW9L4c+9OA1zmqBRCsmTu3KaBOF623EqVZhmXou/Be+THmXo1ZRtt mQdZHjwtRGUA1vae+bFAFVVp+OR8YhJuUlsacPSyoasE7hrAMXj4O+82r7XJM7YU8zw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AZt3sQJE; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=Dby+db6P; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 AF139606A333 for ; Tue, 1 Dec 2026 16:58:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AF139606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AZt3sQJE; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=Dby+db6P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796144333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4+0eNwziAEFrpY1C06WPxtp+rK/4xdBpSDPXugSrDbM=; b=AZt3sQJEEV6QDldftJsjdbcIQtxWkRaA2XHHcA06+wUQexaD4LgYe0pMCl7yjiF71kcdE5 f6v3U0MqDkMwVpciVTqVKKDIq0xZ4x75zeyrou2Svbc35O6rKjWkkJziM7K2Y5B89S/5GQ Xj+LMtScTXkPZcpASFgzDDPfDYhNg0E= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-346-MnSCM-afOC6Amogo_QA0KA-1; Tue, 1 Dec 2026 16:58:47 +0000 X-MC-Unique: MnSCM-afOC6Amogo_QA0KA-1 X-Mimecast-MFC-AGG-ID: MnSCM-afOC6Amogo_QA0KA_1796144326 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4bb69d84053so93673565e9.0 for ; Tue, 01 Dec 2026 08:58:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796144326; x=1796749126; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=4+0eNwziAEFrpY1C06WPxtp+rK/4xdBpSDPXugSrDbM=; b=Dby+db6Po3CJ7Y01uljlJuShxfzHUwspPaorB1WVEo4Sc4gyHeB+6wKKoO51qHwGMG J1iAdQ1nzwV3XbfvA05zx7kaHhp8ja6y7sO3mPUIjAodl/YsNMSNCptYd3pVD+2x2kuS PNz2OhVMUJiZt6NWF7vNU7kks5nxNQeIrlEiQRWdjvalI3oOvOP2x6IVosezTCxMDCz1 DEFv8uya1x/BcuTZG6j0QkV4TPZoxBgtXoWTQgrtJ2kcVrO3tBNAljsAArzfjkv2QMk7 6fbosgbkGYOyvmHBdmhDaEuE9ALPx30IyeGDky0GJa/7u2UoDQnAi1cBsZKWyujgNBj1 6l2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796144326; x=1796749126; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=4+0eNwziAEFrpY1C06WPxtp+rK/4xdBpSDPXugSrDbM=; b=sZQOg3gYKXkmXu7x1gNniDooiK9HrFEpFi8n03fEpbmkrgVjQ0XiedGWOhXB80g5lS dpEPwWHg3KO2p/lsdRpU2wofcgQW8nIRVoGmSHQvpLEAp1pY92sNS4Z9eVP7X23bHjKO RvD9OTyGxxzL2H+QkdXas7joHvstN6ya/x1mGi4jGf5J2WAYQsX3PD/BQX/nPPD4PSNm 9r2CzORan5iDSqZZD/bh/bULdAQ8+NZKdt9OE5vIGuEux1yi63W+LhenbRJhrMJPup7Z XPopyUyacino8JAIrwGAp1jGzO1WLGd7nJecRke4v/uoxqDC+xHsP2AeEU6X5yYNA9WN KFPg== X-Forwarded-Encrypted: i=1; AL+hErHNqQPWlgRKaKOYNpDo0cvqb9aLx5mFWoA4Wg/SrXARPJD2HxGtlto9FoXVpYeQ+0XfW28=@vger.kernel.org X-Gm-Message-State: APuU4Z9iqoaqNFkt1mVwOacd2DqN6ZZOw/oPkb2bqYSt+MnWWLYzJpgo TKA6Z/eujs73GeTGFYFVD2cNvDe6Ww8xYzfW75Exnihct93SstZUt4FIm6hO9xkgCu5WZJj6MIN 25YddvK8V7u3oK+k9GuH+wfgTi/pru5h8V4GSvQhh4jElL1QtlXKOqQ== X-Gm-Gg: AZFdTZfkC4OmQ3MTfAm6Ae/Ik2QjHMvweGxbVoqdwZQyfdFBqUaW1bEK5oOZGG4Ts1M I63iYa3KrX9roNtTnyKR0x4SdNDdSM8PLAnykrnPgn0urf2vaQvr1vdkzn204YvfIg0mBQ9CsuL /SceWpqeTvIwddcWbF1VqcwDEQMEFRbZffjLplJAvlye3T6tphqV55rumrd/W7jpBXUPgnwC0+Z 4TRDxoBtK1UHDefUAZGl/qd9Aq7f2dE1Gf8jU1A/JiEwI4B//dAFye45ARmfMh7nUdxS842cN10 WENCWsD8mXFH2n7TIx8Z6NMoTwivEtOe2xhwRQZaVXuo0B3GfwOZBhbt2XL4fOCMKWN+09Cv9d2 d+LwJpnq2gwGmgTht1k0O35WTbvHDnFCG4LYtUlhzNA== X-Received: by 2002:a05:600c:1548:b0:4a3:5aea:21e5 with SMTP id 5b1f17b1804b1-4bb887fe7e0mr771655025e9.9.1796144326222; Tue, 01 Dec 2026 08:58:46 -0800 (PST) X-Received: by 2002:a05:600c:1548:b0:4a3:5aea:21e5 with SMTP id 5b1f17b1804b1-4bb887fe7e0mr771654405e9.9.1796144325622; Tue, 01 Dec 2026 08:58:45 -0800 (PST) Received: from redhat.com ([2a0d:6fc0:1529:2e00:86ec:bef7:c309:ba1f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853b2437sm1384986405e9.13.2026.12.01.08.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 08:58:44 -0800 (PST) Date: Tue, 1 Dec 2026 11:58:42 -0500 From: "Michael S. Tsirkin" To: Bilal Hashim Cc: Stefano Garzarella , Stefan Hajnoczi , Jason Wang , Eugenio Perez , phind.uet@gmail.com, kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] vhost/vsock: wait for RCU grace period before rehashing CID Message-ID: <20261201115614-mutt-send-email-mst@kernel.org> References: <179602872770.13688.17108715679213800277@126.com> <179614298864.2872.3567081270371906851@126.com> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <179614298864.2872.3567081270371906851@126.com> On Wed, Dec 02, 2026 at 12:36:28AM +0800, Bilal Hashim wrote: > 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 Some process comments: - pls include net/net-next [PATCH ...] to indicate the tree this is against - send new versions as a new thread not as reply to the old one > --- > 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);