From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.12 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793342869; b=pqjyVn+X1PhU6hi8PQu7GhOZzLpE/DN5vuBQ3Ay19DpK0nnALs0nUutdvYrQrOhHvl3F eVB1zj2dg8uv7IoSTEu8lg2W8SOyMxwBKXYIC4LhUduo9x5QKXXLzrCFaYGnLfL/FjFJ+ TM46ASgSwCrjxCKSF+V5LbZrK8J8OiZxncZBqryaQAxKHmXijoS5X7iVw7cYpsAeH0ytG 41hdwDM2YHABHdRHJWF7cSHRc/lEQYKv8aIUcuomClKIDcx2HQJo2T42wtR8nKOxcsk34 mKxfX4piDniuoMhpNaZjDlNt9gJVImCUsMGUbeLXNUVYV8qNXo2vjXs4y5RNmig1oRw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793342869; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=jSNCuWQInnB4aTqSt/QqhCYYoxsHtezivvgpUv5+8rE=; b=AN62UqCoUoeW5LL6E1aTitrxFdzxfuMMccnLOwFy92IdazD/CbPrG2tzKJm/EE42h3ET tptwLte47AkwUKlT781KXVmOsL8K6OSb8uKGKSyJANuVGS1NuMoBoudrDdjju1B4n6Ip5 XD4TDhtFq85nMWBVZ7tWFQqlKQmbMld3ZIjkYdhJQ/4ynjTBcQfMjmIE3c6GkoSF9MwDg ihxlLppYOVin08vbEFqynjWek8zhVUgoeay2/6qtc347UrBOrohcj7VDh/eypEggEicr+ zyuMdZD32n/8tJkuVIWjNQc5cutYWa9cBdhrO2kGOT2ieA6yu8gLK3f+c6p6pUUdy/g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=ikuyo.dev; spf=pass smtp.mailfrom=ikuyo.dev; dkim=pass header.d=ikuyo.dev header.i=@ikuyo.dev header.a=rsa-sha256 header.s=s1 header.b=E98jXeGq; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.12 Received: from sender5-op-o12.zoho.com (sender5-op-o12.zoho.com [165.173.182.12]) (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 359E1606A31C; Fri, 30 Oct 2026 06:47:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 359E1606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ikuyo.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ikuyo.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ikuyo.dev header.i=@ikuyo.dev header.a=rsa-sha256 header.s=s1 header.b=E98jXeGq ARC-Seal: i=1; a=rsa-sha256; t=1793342818; cv=none; d=zohomail.com; s=zohoarc; b=NykSCv8xszM0rcbcli9swwgB4qcQp3pl9NVtUMCmn4YJuao73EDqT1tuyAHJUaWmd1iIwkz6oQ7cG4Dr3GCR0zvjPrF5LK2yk7qDJvPUUchz/dVVw31SZX0TiAPifiF7YKCMBj0JDgbeIasaQP7tmWncRuEq2+1iMNRkO273iuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793342818; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=jSNCuWQInnB4aTqSt/QqhCYYoxsHtezivvgpUv5+8rE=; b=htGtByCqWghsZgFpqJtFIyD8+emCzrrrMwh4/7ebgmmZ6xOvUVzL8P4C16/ONo+qgpdsPccM2+N1yMOTTVItk+TDdKLwmG+Ayj5NOPGnHbqIr5+3vCrYDZmFsXWQRiox73H9JOGf55n+fpae1IK7GFj0+i76YikY8B0nagPN9kU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=ikuyo.dev; spf=pass smtp.mailfrom=eritque-arcus@ikuyo.dev; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=E98jXeGqGHPI5K8Sl59gZfybQYCl/S1MKzCrFkvCfHr/Jf00U9pa4WxXBYzH9eCL7cZPXhqqOQMhJwKlxii8SWjqPGgYwjzCLm/EELRofIcH1tVC04HQp7sB2dl1Q1xb+wQf5Iyop3XFAnTIvfIB8BniposL4FZg/5Bnn8lQOjayJesHkkgnuK83DLDYwo5fEIKXBi0dRj7QIHZzRzwt/EFD+J+wPzZpYKT1UG3L98Y3y4UPcmftdBVKHOvgOUnb52qAGHcFMHQcstH50bjF2oAPquzorLweOIyx+MMd8htaVDh6mrxo5rqTNBvEWuaTtsDPIYHtCgOG5DCcUO29nw==; c=relaxed/relaxed; s=s1; d=ikuyo.dev; v=1; bh=jSNCuWQInnB4aTqSt/QqhCYYoxsHtezivvgpUv5+8rE=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1793342815719234.33637440490043; Thu, 29 Oct 2026 23:46:55 -0700 (PDT) From: Yiran Qiu To: Stefano Garzarella Cc: Stefan Hajnoczi , Bobby Eshleman , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Xuan Zhuo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yiran Qiu , Sashiko Subject: [PATCH RFC net v2 3/3] vsock/virtio: only update a socket's local CID to the transport's CID Date: Fri, 30 Oct 2026 02:44:18 -0400 Message-ID: <20261030064418.133349-4-eritque-arcus@ikuyo.dev> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261030064418.133349-1-eritque-arcus@ikuyo.dev> References: <20261030064418.133349-1-eritque-arcus@ikuyo.dev> 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-Transfer-Encoding: 8bit virtio_transport_recv_pkt() copies a packet's destination CID into the local address of the socket it reaches, so that sockets follow a guest CID change after a transport reset. But the bound-socket lookup also delivers packets addressed to VMADDR_CID_ANY, and vsock_loopback can carry them: a connect() to VMADDR_CID_ANY goes over loopback when the guest->host transport has no CID (no virtio-vsock device, or hv_sock). The socket bound to that port then ends up with VMADDR_CID_ANY as its local CID: a listener on (VMADDR_CID_LOCAL, P) turns into a wildcard listener, and a socket whose connect() was refused for its CID would pass the check in virtio_transport_connect() on the next try. Only take the destination CID if it differs from the socket's current one, is not VMADDR_CID_ANY, and is the transport's own CID. The VMADDR_CID_ANY test is still needed: get_local_cid() itself returns VMADDR_CID_ANY while the virtio-vsock device is removed or frozen. In a guest without a virtio-vsock device, after a loopback connect() to (VMADDR_CID_ANY, P), getsockname() on a listener bound to (VMADDR_CID_LOCAL, P) returns VMADDR_CID_ANY on unmodified kernels and VMADDR_CID_LOCAL with this patch; vsock_test passes. Drafted with Claude. Fixes: 408624af4c89 ("vsock: use local transport when it is loaded") Reported-by: Sashiko Closes: https://lore.kernel.org/all/sashiko-outbox-188830@kernel.org/ Signed-off-by: Yiran Qiu --- Since 36c5b48b91ac ("vsock: fix bind() behaviour taking care of CID") the CID update no longer helps listeners, and connected sockets are reset on a transport reset, so the update could be dropped instead; would you prefer that? Refusing connect() to VMADDR_CID_ANY in vsock_use_local_transport() would also work, but would stop guests without a guest->host CID from reaching local listeners. net/vmw_vsock/virtio_transport_common.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 4d0511629044..b276009efab9 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1861,7 +1861,10 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, space_available = virtio_transport_space_update(sk, skb); /* Update CID in case it has changed after a transport reset event */ - if (vsk->local_addr.svm_cid != VMADDR_CID_ANY) + if (vsk->local_addr.svm_cid != VMADDR_CID_ANY && + vsk->local_addr.svm_cid != dst.svm_cid && + dst.svm_cid != VMADDR_CID_ANY && + dst.svm_cid == t->transport.get_local_cid()) vsk->local_addr.svm_cid = dst.svm_cid; if (space_available) -- 2.56.0