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=1796144332; b=XuHAWTabt3Nt4QvX0kfmWoYxaUG+2sSTxFUxrlF5kVoEEk0kSqsZ1Cd92ejIMk1aXAJu 854tdaEsLisRpZxGuwfjfsmCMBOiTkZp5PSZVX/2bQ3ockL8CDMk2IFTRSwk7w3LVGE2j GWRj+bibtBhrh9H+eLp5zyspe2oySf5P7zlo3KA46odZLlDiJUL5zaQ557na3k9yC5fnb 5thT5lztoRWUBKRCPUcGQvvNU/ZSl3x8t6SIcJiBfLgDdd2EjWabqEgy5Kdj5HBP9FJSn OE+YZVQ/m0LWBW+VI5NxkZz7EPPfHYyOtz7zAlbVT5+TyW05UK53sDyfkrB+7k44n5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144332; 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=qQJNLh6hhYciZXbgvFtCFtFjZHoCDU3sTzbNpt9C5JN7FkhQMrMIFA8a99IzK/p/L4+3 CSowiPRT3LY7F29lPf5dyYYhg0a14HoeWpLDX/3qdEMvVSOG0d6uukrCRWZ3uiz+Vwa9Z E5HqJtIa8xDin5Q6ptcKcfObzM5nyffgACGSYbMzsmJdegrwzIkSAetumqP3lpcszi/yV LyHai2vmcme455oJwfkvU191IVimDtiNhZ77QG3prMxylu5pz3jb0gVqpZYsuyPmZVDYe od+QBEnlGFLdzAfLrwOl0xVQ61VfQNWBnzd9tdMzce7bw14Ce34rkWt2woAnBMigP7Q== 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=AcuJOL9S; 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 9D2BF606A31A for ; Tue, 1 Dec 2026 16:58:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9D2BF606A31A 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=AcuJOL9S; dkim=pass (2048-bit key, unprotected) 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=1796144330; 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=AcuJOL9S01qYzbQ0oVtega/yzxkKaVB+FH0RPUzXKOWZH+7MG3gbvQ3RiZjR+UjVOwuaG7 rfjKOsPanPHK6tL4gdxO1Kg5UNlawkapvvd0Zv5gblxAhD8uh+2P/rK4KRB8ixf1SVXpt0 dSwGYNR/6ktRtvoRsxKKr0YbEfp8oas= 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-460-n2eiXwcMNXG71aIvoefkhg-1; Tue, 1 Dec 2026 16:58:47 +0000 X-MC-Unique: n2eiXwcMNXG71aIvoefkhg-1 X-Mimecast-MFC-AGG-ID: n2eiXwcMNXG71aIvoefkhg_1796144326 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4994d67d0e3so74928165e9.2 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=cO7L+ET0REHDk7c6+Zb6q+agLTB+t7stCb7kiHS0auO6DiJWEUISdSymOyfklf0S6H IbNkLlUwLFKmHGH0yvFnLOZJX1z+Q5vqT52yuJW150zrsG/SCVeaj0FKYCunniAOs643 WczYAsgomD1bnncYh93ulCy1SvseYVfQ2KWm+YmjHTvi0NPxnJfdkpXTfx1bYax98V9r GujYz2z2eUZZ9IB34N3W7Wdo0v1LaDcfOMaxk5NTb4GETahWmPLc7Rljp+4BUqqkffJ2 PxEeY+32u+qQjcobm3l/JVkudAzTb+Aaw9UNSWrnPJ1ZuciENKNEZ8vh+ceGET1fN7Yp dwPA== X-Forwarded-Encrypted: i=1; AL+hErEBqv1VqkMvjzgOK7EPxFQ3SiveBY2yJCa48dHgv9pw+mzHONsfbAXAudrCNlQKbZ7ADzLXGGtiSONkt7w=@vger.kernel.org X-Gm-Message-State: APuU4Z9WgjfVxW9DqELXOxpXOTXvMnyb48B6A9+NmnO3PXWCjGkgSBoN bb1KgTa0+26tbjWpi1tEjCzT/IaGbr9B6NfTXabkz4ASZLSx4yFQICVMyNcM+5uGufCrc1o8Vop Y5tW5tFozkh8V5fjeKo6ofqHmnStVXa/tZ4S383qeRyTqOUcrH0I8w+CIbOq+oSoXVw== X-Gm-Gg: AZFdTZeDacXF4VBHk91bFj84oZIIQgN8J/tu+qtzwIRIlZyju0WaFZ1WU/OLpfy6o5p lJnf1Owmn9+/ZlBgPhGTiyGhkCbCZEwWvBEQuo+WmhAKnMzOLecRvUSVe/wW/AOira86L4RJUui OhqZ/aKBAa3hiKHRc7H5fMx9DF/MizX4/4CtSNIUqMx0OgO1HdjlO+N5mjrt9i6oC48dI2t95aC OH7ZO1UK/3PhWK0rGaEXpaFCWtY3whcFge1X8kEoPr+Wp969zBSBUqct8aWJ7Ji40GRnXAGlMUI 6x9Mq0yhD+Yp85kgVner5Nv3QhRkqM/Et8608RwQxCnfmLK3X7jVWOyKSk9dgTdWFwhbJRuIEUi 7d6VKWGMjR4z9mmalRhDy1y1+1PlypBOJwjCHULagcw== X-Received: by 2002:a05:600c:1548:b0:4a3:5aea:21e5 with SMTP id 5b1f17b1804b1-4bb887fe7e0mr771655095e9.9.1796144326234; 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: linux-kernel@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);