From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144333; b=YW6KMl3Fgy3YR93Ylj7k7LUgi8wOQQ1stAjhhacTF/LAguCrXE7UsY2N2+f4EXtowaqI 4SpPcjwKgrum3Mhe3zE1AzfMvti77RVLMwspYmoCBhI3/mIH8rir4QyDMF7HO6/RDM298 WG35t7XQipueoBkTVWbPipLrlQ/1Xdt5SS9eiVUu+mDv9OLrxfo2ujmFBIlem7kwF9M0q m0J76yDpUwrWuEEFzBUDZ3R2VZM10w7H9sxsRck/Vvf4WpElu3RouI7Eubyvt/Kz/ZQL0 28gL9q7BY4t7HYkodE0h+Tzg07TjM5VeAsLhc+MUSiGyTt7x3YggzK9eE3u4Zkt+Q2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144333; h=DMARC-Filter:DKIM-Signature:X-MC-Rep:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received: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:In-Reply-To:X-Mimecast-Spam-Score:X-Mimecast-MFC-PROC-ID: X-Mimecast-Originator:Content-Type:Content-Disposition; bh=4+0eNwziAEFrpY1C06WPxtp+rK/4xdBpSDPXugSrDbM=; b=tEXP6MnFSPntZuMk0CBCXgPI2VD23hziv6p0jf1Kgo79IdePoiDxG14Bz3ABvkz8ru3m zt2YMgrygnQqlzKZF8wiavQm3vpREw/1ZRSrZwIxHsVN/n8JD0CZywwyhRvQgZ5XKIjU+ R8wlR38oXex9dcLEjVx8VymU7ga9FJ9xZFngWA2QXA+lq/IDdRkbjoxgXzZhb3XnjYlkR stcMld8ttzPLdQ/FCMDdhjGYrDfR5UNdAG0ZWFD7xWcWWeVPKTsLww1mGmyqznb9hQ1hk NNcHUf8+GrO3+3BXXPopdlmhUFi1JIgRm8t8NLsAxc5uJ2aOK2Fqzw9aFzD4n4SlleQ== 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=LX+zmji8; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 7DBB6606A325 for ; Tue, 1 Dec 2026 16:58:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7DBB6606A325 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=LX+zmji8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796144331; 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=LX+zmji8P01m3p10nPent72ch1TR671IkkWZZuV/bp27RFRgGOwYNQWlHz2WDspirAA9N8 I8trCBQAsi6T0OcmMVMaXyU1U79XVbquGvZKc3BGvfrF+ryhdp/M0z9/e0AY5NHAfLCnQP 3/s9eXYNsvqdNhuZnMDupCjbqwg6h78= X-MC-Rep: binary re single Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-KepVmUWJMd6rZHjZ8hsKZA-1; Tue, 1 Dec 2026 16:58:47 +0000 X-MC-Unique: KepVmUWJMd6rZHjZ8hsKZA-1 X-Mimecast-MFC-AGG-ID: KepVmUWJMd6rZHjZ8hsKZA_1796144326 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4bb9379a835so67274105e9.3 for ; Tue, 01 Dec 2026 08:58:47 -0800 (PST) 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=yiHi4KmYW8ie2fpeC0DTQrKW4sNZ0em1Dpd6DYCcSmo1AIIMhUlw0dkCxgbb7xhpUw 1TD6fH3LfDQ4X4eZ3xc7cKDuLrQT9rNIQFV1dhtiMglrNONIA46kat0f5vBTtq4ICnR3 FcEDjfFBBOxNRIXkYu0dzh1i3R8eSlvHst5XNEjxBihEmEgIKTQg1kGF75ZAL3KOi7RL Nvs+yIFzsoar8mXsPc6IsKHsmlY/sy2mMxzQeTlcH7oehyEvTPiI6OhmE8avWgCLzrpq FaXf2nDC9iuN4IUNZXXs8pb3kavmSOixaT2YqZ6ISiLpNW7eTTgRwDaZnGGim6iymaAf sALg== X-Forwarded-Encrypted: i=1; AL+hErEYKBAMhv+31aRs1795wWokRBios0PrgYVXjQiJ9i6bdm36y3S4Ilk7JC/UCOVDoWSaCPKyta+/AKJPjFZOHg==@lists.linux.dev X-Gm-Message-State: APuU4Z/tvMOmj1oZYsxUPAdXhV3Zlnnn+XFANMwoKx1SsL5fBecw6+dQ x55EXt7L1UHK1voBY9r/BrJ9UQa3+Y9KVvqT1U0lXXnwW735z3+Oz20oeoHYJXTXFexcsbRG20u Pbu2RjH3ARQUxIWYpgVjzlLlqfIKGCMrIi20MY1P9Z9DblhYSPriophmgB2Dj1B7nRKCM X-Gm-Gg: AZFdTZckT126Tn1YBCDAvzxVcJf9cI0TcpWyMIK0EFrnGm7EoPIShJ5E/hyqCLDve45 /CaLpGL+SybwxFc6GFGpssnPxXC5eUbQvwO7G28d3scatDK5DEn69PdDapHkcslmyj6kECVleDB kND3yZH79/HdKDmHbLZ7SltTDY56DCROyac0uLzbU4SBc65v20vPG06+Tk04/bk8zD4k59ZgnV9 zKezevZBRSIQuXwKmXIBVDlNjHn0ETXugIvLAzU3en18LIHBLuMxTkC6nLQz/XWP3Fx9bLtN9iE VOxnGLjjfEGOqN+IUE3CGMOuKWW6SR+XuB/0L2EURsfgFcAGPDOcWqRKLlqCfm+NwltTCPBPBOJ zESVcW0fPr6EvZyvKeoBzEI1HOTYzhKbtjo6MbcRuxw== X-Received: by 2002:a05:600c:1548:b0:4a3:5aea:21e5 with SMTP id 5b1f17b1804b1-4bb887fe7e0mr771655135e9.9.1796144326239; 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: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 In-Reply-To: <179614298864.2872.3567081270371906851@126.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: lSGftzv-cE7B5gOtJZX-ZrtpaAMjfJUAiu8Cq0gI67w_1796144326 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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);