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=1796202406; b=K2wSZ0WUsSEu5Ijg5vytylb8NKDBZptlujVy3rqcGRCq5bOr2aIpRfKe9n1wJ24ZalNx H8+ioMSL3bRvp2z5OuzFEjal6jwkmEEmLUzFDZ8cuuFg6VKZPvwkc+WQ4eTbhlkYTg5OL xPexfAJqrrtzeoJK7fBqTUYRZZOaAGUvRV1KyhjrEosA1WHMqPSTmpamjkYjtxoIjaZC5 Oqs8lduE+KzsrWgE8cvOx8MkgV323ID6M/Z/v/rbwtlKUdoOgqSIhDQtRMOLl1rlPLs0Q 22o4mzbZ2cPFtT+tJPK5ZdotYqtX8er6ccTIOy2myjvtl6KwmVbKtbYC9FuwUxWkMMw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202406; 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=58+0OR09zcy3kXqZHHhq3ZZaT6fRes2GGWeXUfu+EJ4=; b=o8MoKr+KqZlicg2UA6QmdP4/VLRvQV/m8bhH4AJvL3RC6BsziJJIMVfnd4M/cMzyw5Xh B8Qz6XeTD44P+T/mT11cWbmCxr0BIGYBK6vczt6ig5cPLClVQAreOUKUapmdhR+/3u92c AF8GoVYWPRi0bm1Xfo/iMH9xQ1fRq7+hGxxZlWga3My3+1tmnVEomx0xJFyVatg1xP0wB E1lByxFR2SMLvaobXG3rcKFMwpJBLFQ3rjVjCNxud39pPT8Q+7wKtnNKhGKueaimvIENI S5AESKaHinDp/WIjFCy+h6VZmmqWvZtu6xVdB0hDjBOK89IskGiNch1mt/W3mnl9QWA== 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=A4oYuFRX; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=YxZ6vMLj; 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 4D26C606A327 for ; Wed, 2 Dec 2026 09:06:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4D26C606A327 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=A4oYuFRX; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=YxZ6vMLj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796202405; 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=58+0OR09zcy3kXqZHHhq3ZZaT6fRes2GGWeXUfu+EJ4=; b=A4oYuFRXq2Omnp0yaNHAUDbphPaJUqR5HYLXJb29C9LXDUxIS0a+W45f8goRNf/nMkSK/g lrMkhLBguobcxhGxFrHQ15R1A9lAxzn3csmsoB79hCEa8uHF+jY59VzpHlJ9ERf5s+34PJ 7/tjctoWnH8bv8lCHmNDAXRY2UiIbzA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-_DUh8k_xP12NqIxiSrPoGA-1; Wed, 2 Dec 2026 09:06:42 +0000 X-MC-Unique: _DUh8k_xP12NqIxiSrPoGA-1 X-Mimecast-MFC-AGG-ID: _DUh8k_xP12NqIxiSrPoGA_1796202401 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4cdb04d7ecaso89500f8f.1 for ; Wed, 02 Dec 2026 01:06:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796202401; x=1796807201; 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=58+0OR09zcy3kXqZHHhq3ZZaT6fRes2GGWeXUfu+EJ4=; b=YxZ6vMLj4UZfijm1tf6SSFdpBZaJMtqK9Hn620geCvPIyEwRenDzZ+PXE2oeLFAz87 ofLT8GQVmfN4wpWEY11gfk09FXxwIf7PHUJBE8IhbMjTWAjoYgPzb4ucG1hAjj22Y+1G CiIxRlHacdFPH+H4Db4I/KpuO8i3EZKmXiqbYb9FPIev+F0sc99pbbbO8CRqHHkw39WX 0ny49Pfy5e9mVR2PJaEuXdGCavEQhXXK46zK7r1OKpB5vja+9m2hn5mfTuco+aMT9uNN nvJXEZE0PHH/Ko8fUxy1onOZi/oRnkFv0kkuG1mPlq4Ydb/yIAM8o/32f/0vPaBfXIRR 5a6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796202401; x=1796807201; 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=58+0OR09zcy3kXqZHHhq3ZZaT6fRes2GGWeXUfu+EJ4=; b=sziw4ctiGa80WHHgTRgQGDZKkUKtDpwdOQBp8Ou592GxnUdfm8v7fy7WAejB43L4An rTDr6AM8xT02s26q6Z5YrOBRs5OPnWCd/Hd0pUbqBj79eGmIjaIj2Y9+2BWfXelvb+rM DPp5PamABRkkhbEqBumxxyVqdDje6snRfaeMLLf95WBGvzTq1vCN0ms0eT4gm0QIXemz ohdcI2w+imWm9FO4JJJz9NCk3CtLubxHgOA0mK3XkZxUD6iSPTsPapr1PIEUh2GQRTf2 VzYr0eGji2QCuRl+ldRxt9sZhhYebvWsgGIx3uOg5QTWBroABvc3VT5TSQYZJEtxL8FR 7HVw== X-Forwarded-Encrypted: i=1; AL+hErGhtgjGIt51aTC22B7DA8K4YKu/4ey5ux/wkOU8GusPb42m8c29PaH+e9D1AMwiJPqxNHqz0AY=@vger.kernel.org X-Gm-Message-State: APuU4Z+t/YaT3RVi5WKfLJioDx7z5fYe9y0Ae92Kfh44bwUsTQNG25g+ 26PBd4WVapM68v7QHGSz/tGc3Z9SFrb0eYxDbrDk2ii6xVxd72gMEAkPzKouuabx61N4LVOPhOE 1+eaptcS33Uej/GEaMI3nK4i1YC2RgglVdNVCjuQSHTwwHC+zPiti/UNqTg== X-Gm-Gg: AZFdTZdGS+RqTW3ZdFehPhWoVsviHlhsSHoVpJccIKH0LBlYtuon5QL2QyBi9kALTWx yLvNYvPPxmPlJVzj7fgNk5sc5sVtR+DPu8JEpMrcMCI4t87LnStv2aM5B4doy0xvOXtq/mtu15D yhet0Yxav5hZQv7AOA0uoIGCIiN4TtzjLmpOh0dqp8SXMR6rGysoCreuo7/k1lID3a1069ZVBeP Aq9FP8Mdybqi10ZLJZExrjGyhNgZv/3NvCLNPyMgWRy2G62jRCKdqMOLPBplJ9/m3B5PtXYOVtl 54lRDdHtMOYOyd3KkOSZZBhkG6tPhrC+5Hqp8QWmjiIenrjrtpvG5A9whtvf4J44fNzfQIIeWDd FPmTS8Atus+95gO/INXKT+RN9QKqZYijbn6dPexmiTV3Ui3bIj3aLhMRU7PRlVL8fABrm+wbNHm gHhiduFDcQhWhhuA== X-Received: by 2002:a05:6000:402b:b0:4a4:f86e:d97 with SMTP id ffacd0b85a97d-4abaa976a91mr73060544f8f.1.1796202400921; Wed, 02 Dec 2026 01:06:40 -0800 (PST) X-Received: by 2002:a05:6000:402b:b0:4a4:f86e:d97 with SMTP id ffacd0b85a97d-4abaa976a91mr73060509f8f.1.1796202400337; Wed, 02 Dec 2026 01:06:40 -0800 (PST) Received: from sgarzare-redhat (ip190-139-192-82.pool-bba.aruba.it. [82.192.139.190]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b10b2c9sm78356058f8f.31.2026.12.02.01.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 01:06:39 -0800 (PST) Date: Wed, 2 Dec 2026 10:06:33 +0100 From: Stefano Garzarella To: Bilal Hashim Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , 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: References: <179602872770.13688.17108715679213800277@126.com> <179614298864.2872.3567081270371906851@126.com> X-Mailing-List: netdev@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; format=flowed 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 Is this another optimization to be fixed in another patch? I mean why this 2 changes should be in a single patch? Also, this maybe can be combined when we check `other`, I mean something like this: mutex_lock(&vhost_vsock_mutex); other = vhost_vsock_get(guest_cid, vsock->net); if (other) { int ret = other == vsock ? 0 : -EADDRINUSE; mutex_unlock(&vhost_vsock_mutex); return ret; } But again, this should go in another patch IMHO. >synchronize_rcu() after hash_del_rcu() before modifying vsock->guest_cid >and re-inserting into vhost_vsock_hash. > >Found by manual code inspection. Since you just ignored me on v1: mmm, really, it seems related to https://lore.kernel.org/all/sashiko-outbox-222286@kernel.org/ no? > >Fixes: 834e772c8db0 ("vhost/vsock: fix use-after-free in network stack callers") >Cc: stable@vger.kernel.org >Signed-off-by: Bilal Hashim >--- >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(); We have vhost_vsock_mutex held here, is this okay? Stefano >+ } > > vsock->guest_cid = guest_cid; > hash_add_rcu(vhost_vsock_hash, &vsock->hash, vsock->guest_cid); >