From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0200F37DE8B for ; Thu, 30 Jul 2026 08:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785399540; cv=none; b=RVQ6SnRjhSDsTbcW/KljHWEot3okWZJIJgWhSR83z5cy3HmlspZF2ZR69pWo7roIREU26RZTCiq+Da6my4vQJppVds+OosI61mKA/ijCjb5GLU5gR4JXhU2M0rTGOn9KdM4477TEd6FtR8YIGtNHsfypeXN6ghFidIZ6bGJsXMo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785399540; c=relaxed/simple; bh=aQj2lpDoDMr3oTGZoAlSySzMKpl0kzj7UtX+5NrpPp4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nrFS18WmVQg3gCNGv/NvbsH2PcMrea3cmYSL3EU5KEHEAz/09wc8NaaeNglj5MWldTu90AdVQXknBXIHC/JTSXGDsiuRbXwfjxPqTLY+SBSN44WGqD4rWncUPdSFo7YacAFcOqgtPMcxGZr34nNEHpyw+0NHKvb5vqvKCOyoBxw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bJZgF7M3; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bJZgF7M3" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-381c51fde6bso2080471a91.2 for ; Thu, 30 Jul 2026 01:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785399538; x=1786004338; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=f2dUIXZ0ftJ9QMv7KKCUkHExqYY5TKyD6DDp/Xnu51Q=; b=bJZgF7M3u2a9vq1S9vEm4DerpDF4R0CwLfH0kuR4gbam9hL71dL2hl8rXqwi00vE2p n6JfKrz+APi3d5XIKwgp4ustJbB8TAYKorKTcQvCudfgtm5m+nUWCE7r2zI5/IBICGk1 /U88z0eDJok4buscRKZFw9tjeBEXZzdnLyusxyysoq9KexeysHBR65ncFGLb7Aewt3bg tsMzbzodaNYNPEcgednO1Q4Dcu6y9T44+aqdjPwqdK3pvl9dYkDk39DPgdlZF7oDIIBn ckdHKvBBe399daXCHlxG15r14rIZJiTr2wnyMYXliBsRfkBTi5emhaQt2Fwn2f8touxo CqYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785399538; x=1786004338; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=f2dUIXZ0ftJ9QMv7KKCUkHExqYY5TKyD6DDp/Xnu51Q=; b=aeuG7sWSvVvVqzFwIF6cHUiA9ArFKdQNENO7HaiVcurUu273UFZ6Q2+I9VSeYtfmvT 9eZjdn8PVsGLXvaJohYljOFK+ER5rUgE6Xlc+mqIJyBQS2gY7np66IInXbNx7Sb7lWNf KGkZ24ysV27ylkS5wf5I9ODFwuXZsvmuAFZtzRTiai1qUF+q5fB6liwcAso453Vqo7+u vNwyzbFKBe0LoxJDYKPmxze0HZbZWnj5T6qa09/F77HT0oauSKfR3V2Krj3DbAW7Sy9r w+Glzn3rKbVfivPH1Ojcvsu8qPe9OLHpCbq9dVTRra+CtuvKxMuFP+NUqGt8KIO/sCjH euBA== X-Forwarded-Encrypted: i=1; AHgh+Rp/flbYhzjyhC90MAdxmiE6xyvZglMFze1Q4V+vin71RqHhAQwbLmiWwDtvjijkhH1GWelXY0rhXbX5mlc=@vger.kernel.org X-Gm-Message-State: AOJu0YzZ+tHWIKRv1ejMY/nmk7terzMZcAM4PX+gMChKXXeJkkRXa34Q npUT4sHDD7AkATJz7DRYqlDGG/clJNGGz7nUBoNLKr5hluRo5NFQqzUhUhEU7F4j X-Gm-Gg: AR+sD11vfXC2kR+SOh6+K4gYp7gcLf17v+7lpO1WbbyWNv15IpI5Brmlfrgz85v9gay 0ykP8L2WAAUqfibwKZLUpFvHsbUu+fEqrRtTnuJcmBk5mjMVBG75l4mEmPf7dnm1vmiVmKBcJkR WP7ixDMYuQLRrYsVoNfJ+Pq0irmteKVW0InEvHXPJcFeVlENISwk4TJb+rzOQuF3k+UyF59kcjl 9qM6pCr1ly5nY1JpGyVx1aOPU4P1WA6jC82PSFf/KRL/PircckDR0F4b8brKcEM9KiQnOjNL9a8 U/SZqlDBHJRbb0nK+vY3Ysf6Kq5w9OatsacvQNP6+WrDEJKvC1OlxS4KCdonTFdrg1FqfgWS9yu m6R92dxbXQWHGsNP19uOYLW9f627SGhpF7HZp26sVfDsg2UPhJTs23vzaP2M5Npc80+V7iHhN8I 2zJEA8U0fOvVqUSbuCXd8K7Zcua50friI76JesvUr/o4lXzCUV7cWgq1v/B+yFrLGkbLjx3EkrV THtcGty6e8= X-Received: by 2002:a17:90b:5745:b0:387:df8f:1408 with SMTP id 98e67ed59e1d1-38f9c08163bmr1533690a91.41.1785399538185; Thu, 30 Jul 2026 01:18:58 -0700 (PDT) Received: from localhost.localdomain ([147.136.157.1]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-38f9bab61desm636142a91.13.2026.07.30.01.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 01:18:57 -0700 (PDT) From: phind.uet@gmail.com To: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andy King , George Zhang , Dmitry Torokhov Cc: Nguyen Dinh Phi , syzbot+1b2c9c4a0f8708082678@syzkaller.appspotmail.com, Wupeng Ma , virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] vsock: use sock_error() to consume sk_err after a failed connect Date: Thu, 30 Jul 2026 16:18:40 +0800 Message-ID: <20260730081843.287563-1-phind.uet@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Nguyen Dinh Phi Syzbot report an issue which can be reproduced with these steps: r0 = socket(AF_VSOCK, SOCK_STREAM, 0) bind(r0, {VMADDR_CID_ANY, PORT}) connect(r0, {VMADDR_CID_LOCAL, PORT}) -> -1, EPROTO (self-connect) listen(r0, backlog) -> 0 r1 = socket(AF_VSOCK, SOCK_STREAM, 0) connect(r1, {VMADDR_CID_LOCAL, PORT}) -> 0 accept(r0) -> -1, EPROTO (stale sk_err) Basically, it creates a socket (r0) and triggers a self-connect after binding it. This self-connect fails with EPROTO because it loops back to r0 while the socket is still in the TCP_SYN_SENT state, causing it to be incorrectly dispatched to the connecting-client path. The unexpected packet type encountered there sets sk_err to EPROTO. After that, it invokes a listen() call on the same socket. This listen() call succeeds because the kernel's listening path never inspects or clears sk_err. Then, a new socket (r1) is created as a normal client and connects to r0. However, vsock_accept() rejects this incoming connection because the listener's sk_err still holds the EPROTO error from the earlier failed self-connect. This rejection causes the child socket created for r1's connection to never be freed on virtio or hyperv transports; only the VMCI transport implements pending_work to revisit and clean up a rejected socket Fix the issue by using sock_error() to read the sk_err to prevent the rejection branch from occurring in this scenario. sock_error() atomically reads and clears sk_err, ensuring the error is consumed when vsock_connect() returns and cannot affect subsequent operations on the same socket. This matches the established pattern used by other protocol connect() implementations in the network stack like __inet_stream_connect(), tipc_wait_for_connect()... Reported-by: syzbot+1b2c9c4a0f8708082678@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=1b2c9c4a0f8708082678 Fixes: d021c344051af ("VSOCK: Introduce VM Sockets") Signed-off-by: Nguyen Dinh Phi Tested-by: Wupeng Ma --- V2: Add reproducer steps to commit message. V3: Fix truncated title and add annotations to reproducer steps. net/vmw_vsock/af_vsock.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 622dbd046799..43eddc33ed12 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1847,14 +1847,11 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr, prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); } - if (sk->sk_err) { - err = -sk->sk_err; + err = sock_error(sk); + if (err) { sk->sk_state = TCP_CLOSE; sock->state = SS_UNCONNECTED; - } else { - err = 0; } - out_wait: finish_wait(sk_sleep(sk), &wait); out: -- 2.43.0