From nobody Tue Sep 29 01:56:48 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 5AAEA36EA88 for ; Thu, 13 Aug 2026 17:31:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786642309; cv=none; b=UhtM43CFpi93RWCCGQ8ohmYe2PKgyB4587mx6DDcD6tOjdwv4ouYmeRJrFz2MKuNVvHJb6X436aIDA6BUxz0MRR2tojHbW0LZQiKo1Yo6c/BadWoDEZHPJhex2PHBoT/BWrSOJdHLRTFeLrvwhHbDnHjht0cJ7WY79A96XRkUcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786642309; c=relaxed/simple; bh=OeOX0RoRjBPyIuSi1g0jByNM0OtD/yGNyEiSTE2q4+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=awzQyEBd0QmFhhnbfWpNZnvpGK4+BOEy70oyW5p3irUG6g+g0MDznVDcpjvLWD4MWVqDCozc6upRYwmukdn+piLQMhY2xIbnj346+dj0nGTE2Vn/ECFw6D2oi8TKsokVv+tndmPTvMQLOSKvzBMhSlBHxHKuFdSCl1IfRJxdiBo= 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=o1xFjkNF; arc=none smtp.client-ip=209.85.214.181 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="o1xFjkNF" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2cf6d65d8a7so3113855ad.0 for ; Thu, 13 Aug 2026 10:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786642308; x=1787247108; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QzQ+02ZArwstq/stXjbk7JGbozF3cjKbB/DHV6r4yWE=; b=o1xFjkNFQJYWqFRBi6/M/9tSgWuGBa9i7WK4N6DITZOceIyILHNZAb5kipbmYx0esx q3cp8NwLYIPm6rrbiz/p7jrxtcZknf9UayCTgBYzJI0l0l1ZOvq9OSvGE2qKCkKrhOVL VAwbPK1byeRPjx/bnbmzjUTrAFza+XIuk2qwjjR15yMQA0Y2t0FCYcLN6LFRdYPw8c2A sClzdkiSZcvaycRziuaKm0Lgk9uoTl0fLLYNUYRY9JibVAM0h22KJbIGYLxZywlBxpig IZoZjHAuMu3Ja3QZCyCqDUAwQmQrYSuAskhU6IDTT3ELW0vIm6mqetl7sFWhpU18Tt53 EKgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786642308; x=1787247108; h=content-transfer-encoding:mime-version:references:in-reply-to :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=QzQ+02ZArwstq/stXjbk7JGbozF3cjKbB/DHV6r4yWE=; b=Y8FOWjAay0+mxKy4WFU/qEDBiHOF0UTS9oqVmwyeVfZoAwDVPQbJnHPz+z5tWozVGQ 67PZw1/aLr0lL3Gzx7g4i9pn1yCBbVrenMnixD4f1cweNjccHOiUOJb86ycGUkFwIWnM Bgpv0a4RZ3xTZLRfmbhjrG+srPMr/uMWav4RLE8vLe9sqrYueNE2Ak6WgYF6mvVsRb/6 VbgJ0TD1cDbE0Hvf++ZMCfcD8EadY0k/AmlL7n+HAdP6avU6xtW4Dr/Zv7/DiLAeDz4X vRoKfLntQ5du3VipxlOyym19sDgANt+6CFqDmDf22NzHx7Y3t6VTDggPlGkBmdbaTz+Y KvZw== X-Forwarded-Encrypted: i=1; AHgh+RqdNii9pQgQZqzU4njWxBKhtWAzmZTs0Z5CKkyFjGduimnh9AAn1RRayzj92t8raeO7rzPkpFnOc1saxCk=@vger.kernel.org X-Gm-Message-State: AOJu0YzynzF5tdUll6tNu0StUxO95Y9BgGbwijrxh/b3I+ydNjRO8rgZ 1H5j/ub+1KXoVazigq+EVAlrfyO/PoW7HywA4G0H2FiuudPJjD8mdvGW X-Gm-Gg: AR+sD10bVVcwbnzhbh2mwA85BbQeZdz0H+qdsb7vZmvtgjEAJYPmV5Ugl50pscA04hn bzceGmgL2piqCEXilH2QYzNnVuVKCi0PfPkCL+4ZYCehfgZ4hXkO56zXjd02gnT9MNfPu2pte7p HWqeYqym2hzFU3mglKK6IiaXRqb32yNTlbP+5HeZwJLEaARzN2lVJL80644362pTTzQ3nSEgMGG n6DLtTeb8eB1dMeTvNPOqGO+l3uLNSpaghuR3SGJqEdZwtzWC18e0ORePh+5SDK0OKMneRE03u/ ODXMqlHKhLdi/06Tji+jwSbzbQsNbWNIjuKKu5dH/enuz7m5VkLpAGh3YFs3F6yhGvblj9UwpNQ LXMdTknuvasyXaeXCY976uq8LTWoCYyuwZbwUNKPd7Y1e5V9YFXF/pzrO0QpxyH0n9Kq4dH2xTt cb9aTPPITt3uf6wtQFXHUILZkewSM1dY/Me8cEyzgM9o20rFRme5ICaHcogcVDcA== X-Received: by 2002:a05:6a20:da1b:b0:3c0:278c:6a31 with SMTP id adf61e73a8af0-3cc54ff0e51mr11048975637.11.1786642307657; Thu, 13 Aug 2026 10:31:47 -0700 (PDT) Received: from phi.nguyendp ([116.86.160.247]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31ebc75d8casm10961169eec.3.2026.08.13.10.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2026 10:31:47 -0700 (PDT) From: Nguyen Dinh Phi To: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , George Zhang , Dmitry Torokhov , Andy King Cc: Nguyen Dinh Phi , syzbot+1b2c9c4a0f8708082678@syzkaller.appspotmail.com, Michal Luczaj , virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 1/3] vsock: don't check the listener's sk_err in vsock_accept() Date: Fri, 14 Aug 2026 01:30:18 +0800 Message-ID: <20260813173024.2362935-2-phind.uet@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260813173024.2362935-1-phind.uet@gmail.com> References: <20260813173024.2362935-1-phind.uet@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Syzbot reported an issue which can be reproduced with these steps: r0 =3D 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 =3D 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. For a non-blocking connect(), vsock_connect() may return -EINPROGRESS immediately, and vsock_connect_timeout() can later set sk->sk_err asynchronously. Since no vsock transport ever sets sk_err on a socket while it is in TCP_LISTEN state, checking it in vsock_accept() serves no purpose and only carries forward errors left behind by earlier, unrelated connection attempts on the same socket. Remove the checks so accept() no longer rejects valid incoming connections because of a stale error, which also avoids the resource leak described above. Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") Reported-by: syzbot+1b2c9c4a0f8708082678@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D1b2c9c4a0f8708082678 Suggested-by: Michal Luczaj Signed-off-by: Nguyen Dinh Phi Reviewed-by: Stefano Garzarella --- net/vmw_vsock/af_vsock.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 622dbd046799..3cd5c3561be3 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1893,7 +1893,7 @@ static int vsock_accept(struct socket *sock, struct s= ocket *newsock, timeout =3D sock_rcvtimeo(listener, arg->flags & O_NONBLOCK); =20 while ((connected =3D vsock_dequeue_accept(listener)) =3D=3D NULL && - listener->sk_err =3D=3D 0 && timeout !=3D 0) { + timeout !=3D 0) { prepare_to_wait(sk_sleep(listener), &wait, TASK_INTERRUPTIBLE); release_sock(listener); timeout =3D schedule_timeout(timeout); @@ -1906,13 +1906,9 @@ static int vsock_accept(struct socket *sock, struct = socket *newsock, } } =20 - if (listener->sk_err) { - err =3D -listener->sk_err; - } else if (!connected) { + if (!connected) { err =3D -EAGAIN; - } - - if (connected) { + } else { sk_acceptq_removed(listener); =20 lock_sock_nested(connected, SINGLE_DEPTH_NESTING); --=20 2.53.0 From nobody Tue Sep 29 01:56:48 2026 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 0CE5438836A for ; Thu, 13 Aug 2026 17:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786642313; cv=none; b=CLluFDU5wCU6GoDYR/JhSxPpjCUBBjbKVm+ybLa8K2GAUzFbvydmGRPaZCLjr5Gny/oFdhFuKBvRzuAirR6/sca1OPpGkH2yultDk8v+wKM4XJ39nHI/ukZKVR3eUTreuqMoMevjqK/gb1x00IMeKb20wQ/KPb2xI32ZpS7GNtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786642313; c=relaxed/simple; bh=sCm4JC/C/nrh5towOjwGQMmxpw99/kz1n1+sjCZg3OM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Asr8Tm4P21dHzmfLB8IrT+k9uxNPHwJ5h2J594hPpco6hcwwP0PiaInruiFv2RiiA/4H8e8ONR96dStojnriXCA2IYia1OHetvU/GR78nJVXcfc0UpSHfEG2fydMVUh2JJRZioXJSqjFtW9owr/XHy0SBk0n24kOu220I6QEOJQ= 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=KqYP55oS; arc=none smtp.client-ip=209.85.216.47 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="KqYP55oS" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-38dfe7eb825so93260a91.0 for ; Thu, 13 Aug 2026 10:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786642311; x=1787247111; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PMBuQPRPUkDIdWcPkANLnrxOobcaxz+FksX3Qk8GmDY=; b=KqYP55oSxthzUjO12VlOeGSb7bj1EOrY5HBI/DOOo9CsVtjGSXHm3CMgvVzzcyloxu wiU7ZYTuQxC88o1uM5nVee6JeTf7ByBrLtxipIY7dYBDCS8hxk/aJz+C7E3eFJOMIFw+ a6RylTU+PggdDgaVVNZ3nQiBDkTn4YvR1ojGeFHU7eYcsV4PhuolA4zCsJgXO3Dl62nQ jp+bZSC4nXAnH+wx3ghGY9o9jdJt4CjPp9iKRgqHsFCZCwnsKzL2sIM6uPDMZ5RBKXlA 4+VMBh9aYYdisgc4wND/x5lp6d3jKYqmDeeNDgIopowjLJOnaPDtsMB7RtAhloYcySE7 Xajg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786642311; x=1787247111; h=content-transfer-encoding:mime-version:references:in-reply-to :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=PMBuQPRPUkDIdWcPkANLnrxOobcaxz+FksX3Qk8GmDY=; b=VZgioAq0y58CQMmcRyEGHqt+nvZjRcoeKK6fnAYzUstbBXN0fVlgVu54syR0xSNMRB ZmLL6ZRrNL1j2HASQfiNbAHSIIISJbGpv1rVghZ/WpzPZUpyzrqxMvwYJxs6O8Li2BCq y/bzrImajDkOTxtdJT3Bjg9jGV94KzoF1R/S4hD38pEoha3cxGTlD5/O6NjhJDjPTgPf xAq23zS/gptkvJM7+wcqtPUhMSIC61S5QkGh33IVycY08Q9hm0qTf2st4/00jTviGoI/ b9ZhWPbrz7qJR59KzXc06AApPVsoyKsDBUWraLIFc53JSjsyzioj+dYsTjLP01NQZfbK UWww== X-Forwarded-Encrypted: i=1; AHgh+Rqmx38vmpBP1ajD42ItdktVwwT7eaYjaIKFV48ZwiTYcFyN5mW+TbQwnOMpkW8HHfw0JVHZwdD4QD3iPVM=@vger.kernel.org X-Gm-Message-State: AOJu0YyLpJZj01mmn4QVzHLU5cEi4M7HidtnEMeElUPJcZ359RUn24lT aWGToxnlZW0wmlHmmyJKB3JgZNvyLCY7jNT8bCf3DJBCZv+uiDdE7oLv X-Gm-Gg: AR+sD13oxSjcDxmmPw8U2PMQvwFxol46huR6UbGkbsNVW61wc9EKcIuoAjxYE0uPtyZ kYXus2N9h7B1s2pcMReSSdMjm9EXrT38g0rK7Ub+paKEjYpRLwjBsmAUF2BltjyrTC0BnBQxEkE yaHL9Le1fH4BMPaq6e+4YBIlTf3RGeNi3v494U50+fxvClnulBhGls2U5cXOYv6Hc0dc2qOmRLh ixUB43PuqBsvvCxjij1jDGfGy1o0U2SWX3hB2SWJih104iFMoe2wV6pJA/drpWPeSsyyJvIZz0y TvZ3Fh6oOTBQycHlZTZkCkmlMScLL3Z1BXkw1A4wJ91q3P4fg+gnCZfKqQKfwWBXNUDiFL4kMro xZC11+iH/NWAqmwd8QcA0HfYi6Nx7U9JzZExIQgjU27rblOFsO7LwnAXOR1op2kYE2nOQN7jnOE uMo1QbGPE+xtC5ZxqQCvYUzRyenocjWgJ/U//Gynxo4YUbXYnoQV1Dl1LxLAHVDg== X-Received: by 2002:a17:90b:4d01:b0:381:528a:808c with SMTP id 98e67ed59e1d1-3931e0fd153mr7752510a91.12.1786642311225; Thu, 13 Aug 2026 10:31:51 -0700 (PDT) Received: from phi.nguyendp ([116.86.160.247]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31ebc75d8casm10961169eec.3.2026.08.13.10.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2026 10:31:50 -0700 (PDT) From: Nguyen Dinh Phi To: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: Nguyen Dinh Phi , virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 2/3] vsock: remove the now-unused rejected flag Date: Fri, 14 Aug 2026 01:30:19 +0800 Message-ID: <20260813173024.2362935-3-phind.uet@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260813173024.2362935-1-phind.uet@gmail.com> References: <20260813173024.2362935-1-phind.uet@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After previous patch, the branch marking a socket rejected in vsock_accept() is unreachable, and nothing ever sets vsk->rejected elsewhere. In fact, since commit d021c344051a ("VSOCK: Introduce VM Sockets"), where `rejected` was introduced, there has never been a path that sets sk_err on a listening socket, so that branch has been dead code since the beginning. Therefore, we can remove the `rejected` field from vsock_sock structure. Suggested-by: Stefano Garzarella Signed-off-by: Nguyen Dinh Phi Reviewed-by: Stefano Garzarella --- include/net/af_vsock.h | 5 +---- net/vmw_vsock/af_vsock.c | 46 +++++++++++++--------------------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 30046a3c20f7..3357ee62d10b 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -52,13 +52,10 @@ struct vsock_sock { * The listening socket is the head for both lists. Sockets created * for connection requests are placed in the pending list until they * are connected, at which point they are put in the accept queue list - * so they can be accepted in accept(). If accept() cannot accept the - * connection, it is marked as rejected so the cleanup function knows - * to clean up the socket. + * so they can be accepted in accept(). */ struct list_head pending_links; struct list_head accept_queue; - bool rejected; struct delayed_work connect_work; struct delayed_work pending_work; struct delayed_work close_work; diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 3cd5c3561be3..62e22c4b13c0 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -38,10 +38,9 @@ * pending socket. When that socket reaches the connected state, it is re= moved * from the listener socket's pending list and enqueued in the listener * socket's accept queue. Callers of accept(2) will accept connected sock= ets - * from the listener socket's accept queue. If the socket cannot be accep= ted - * for some reason then it is marked rejected. Once the connection is - * accepted, it is owned by the user process and the responsibility for cl= eanup - * falls with that user process. + * from the listener socket's accept queue. Once the connection is accepte= d, + * it is owned by the user process and the responsibility for cleanup falls + * with that user process. * * - It is possible that these pending sockets will never reach the connec= ted * state; in fact, we may never receive another packet after the connection @@ -49,9 +48,7 @@ * future, after some amount of time passes where a connection should have= been * established. This function ensures that the socket is off all lists so= it * cannot be retrieved, then drops all references to the socket so it is c= leaned - * up (sock_put() -> sk_free() -> our sk_destruct implementation). Note t= his - * function will also cleanup rejected sockets, those that reach the conne= cted - * state but leave it before they have been accepted. + * up (sock_put() -> sk_free() -> our sk_destruct implementation). * * - Lock ordering for pending or accept queue sockets is: * @@ -774,11 +771,10 @@ static void vsock_pending_work(struct work_struct *wo= rk) =20 if (vsock_is_pending(sk)) { vsock_remove_pending(listener, sk); - } else if (!vsk->rejected) { - /* We are not on the pending list and accept() did not reject - * us, so we must have been accepted by our user process. We - * just need to drop our references to the sockets and be on - * our way. + } else { + /* We are not on the pending list so we must have been accepted + * by our user process. We just need to drop our references to + * the sockets and be on our way. */ cleanup =3D false; goto out; @@ -942,7 +938,6 @@ static struct sock *__vsock_create(struct net *net, vsk->listener =3D NULL; INIT_LIST_HEAD(&vsk->pending_links); INIT_LIST_HEAD(&vsk->accept_queue); - vsk->rejected =3D false; vsk->sent_request =3D false; vsk->ignore_connecting_rst =3D false; WRITE_ONCE(vsk->peer_shutdown, 0); @@ -1914,26 +1909,15 @@ static int vsock_accept(struct socket *sock, struct= socket *newsock, lock_sock_nested(connected, SINGLE_DEPTH_NESTING); vconnected =3D vsock_sk(connected); =20 - /* If the listener socket has received an error, then we should - * reject this socket and return. Note that we simply mark the - * socket rejected, drop our reference, and let the cleanup - * function handle the cleanup; the fact that we found it in - * the listener's accept queue guarantees that the cleanup - * function hasn't run yet. - */ - if (err) { - vconnected->rejected =3D true; - } else { - newsock->state =3D SS_CONNECTED; - sock_graft(connected, newsock); + newsock->state =3D SS_CONNECTED; + sock_graft(connected, newsock); =20 - set_bit(SOCK_CUSTOM_SOCKOPT, - &connected->sk_socket->flags); + set_bit(SOCK_CUSTOM_SOCKOPT, + &connected->sk_socket->flags); =20 - if (vsock_msgzerocopy_allow(vconnected->transport)) - set_bit(SOCK_SUPPORT_ZC, - &connected->sk_socket->flags); - } + if (vsock_msgzerocopy_allow(vconnected->transport)) + set_bit(SOCK_SUPPORT_ZC, + &connected->sk_socket->flags); =20 release_sock(connected); sock_put(connected); --=20 2.53.0 From nobody Tue Sep 29 01:56:48 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 20CFA384233 for ; Thu, 13 Aug 2026 17:31:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786642317; cv=none; b=INsolHWKzksNegBqNlfPimehDNjxBf0DjaGkSQim1DgMJ7fz5fD1+I1NkFXdnogi6/1E6gYxpND7ooc7FbVfkvzqBz+3fln3KsghwBVptgd84KazibpkQuHqzbgZNUEz0X2Mmr+agNpqBjzNyrlp8wfphPAij2UpCFUg+UPFAW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786642317; c=relaxed/simple; bh=OK+3PSY7/vVg8tPTstwFNKlug+QDc4pfGSyYeQEKZn8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ed9dcW7M/0LNiP0ZKrTx0R1oPy7t/OyxFhVARXRnnI56Fbb3GudnDcrLriyVb9BAuDejaElON0KyrKZ6ElOhq2FR+djjbLTzcS0B4XBEcM+DP1+EYuVYl/Lv5C+R299YDEsO2cIipigm2dO7UxA2t+ywrQEHVQFMZzrHktrJo+4= 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=iWHSLbQZ; arc=none smtp.client-ip=209.85.216.42 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="iWHSLbQZ" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-38dc4553f62so155724a91.0 for ; Thu, 13 Aug 2026 10:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786642315; x=1787247115; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hHhRM52KdKrRi6gpE3cIbQsE04qBYaQW/Y0DpiPJx5g=; b=iWHSLbQZnFFTq5IIqwBV2/o32D25e71oEmXPTin7AOAIgcc9J/pezSWTPZQx3MIIf9 CjWlBijwkGyxfxInWNdloYIpKK2jH2QdYkwwgfgmNSSygmDKtSo0wcxQmFW9faT2MujV lU56m/VH2EPkDW0J1MrG9qncgPQp9gpKZFzPI4zMkClnGRJvlx0yMB/IRlvgUqhotnlj LwKihQhey3q+8NmVE9kRX+J/2rqhXpVdJvoqG6KyfIQ6Bdm94wln5IqiIw/TcKpjusNT MXc1fxR0+W2P9+O8/Rgg9MTzJsUX+gByliRRvo9fevugwnwDCC93YZmcMnbJRakNgOTQ i9ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786642315; x=1787247115; h=content-transfer-encoding:mime-version:references:in-reply-to :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=hHhRM52KdKrRi6gpE3cIbQsE04qBYaQW/Y0DpiPJx5g=; b=r5jOjsqWccGPSL6D6/iD9T2XxcNrAtSRMwpzOi05Lcwxx4JssJdBVH42XisZiC9rbi nzXtz35xU4IU67qPRlPO+PZNBFKQlpD+HfymIuf+ncxHyANZR2YqUWJeDc0jHuWo0bPw olYhYE0syqu5dWerx4FujS62uctJvngq/VDuZsGdextIADyH5itnkf/Ys058Q6jL6sYD wMIYtstRNFkfsWVAarC09EH8SPdHeSxpb0HqxnbBHvM+kAVJYoWdm64lFh5A5j5Rnh+E gpP4+4J2KuGuUPS0zB5slAtcXIHr/GI988TAUzgYSdKq07LaiGbZjKQ2aiu63DHGlTqZ SjMA== X-Forwarded-Encrypted: i=1; AHgh+Rq/4ccrV4wQauxMV3hVWcZLq6mNfAu48Milmnhfhyk25QQvGms0X7QevfqbiKlGsithhd4Z3HzHAjsdCCI=@vger.kernel.org X-Gm-Message-State: AOJu0Ywo2w5V3xmoefz3HHcxmfOeYSlCHETVhM6DEa8d2nkKCfKW3cvv 0R8AZkcoiG4xNM3j724i7oyF8pR6uVRHouLjWceGYq1UFeLvCju2m8d3 X-Gm-Gg: AR+sD10VDy37cbiR6UUcUnt1acvU1ttm+P5VqKANuGOOB9QccmcAm6vVi+UaSmeSxEM pDsYlN+2RK+z6izrpQKh7AmOTefnPEeHwmWqJzBmSFwSq7FCwNkD922yzAQqIqasG+vqYEx5bUZ HrHT5UbNSVfdcwvbNQh768rpYnbhGvJnwutjWO0QymTPJETWA71yOWreNiCF4RLD7PyJ9xRrCiz 91XC8iWmyh9X1Sj8UT1EM8HVGdSfd3Tzwgfu4mBozdF9xcdl8RvdIlsDF/SGM5oGBIwiRaegao2 VAPc0Cl8+GsDOJJ9lYVeuI9IPovKwmvjDWeOqP6OFI3wf+z1fShNznA7cZAx0yWp2GF3TW4sW8B Iu4ZTYYM17wVsZw6DRC+SSQ9NCffcarM/hGzcN/szziNdnoIyRFdF7RXVTbrPF3yChSaijOWVy5 0H1b/oCkQJO/sHyT/TmE0ceDI4c7MuRPlMjgp1P+5fsmnfEtOXdnzbD9/aLbroqA== X-Received: by 2002:a17:90a:d40b:b0:393:19a3:4f1 with SMTP id 98e67ed59e1d1-3931e058763mr8418570a91.6.1786642315261; Thu, 13 Aug 2026 10:31:55 -0700 (PDT) Received: from phi.nguyendp ([116.86.160.247]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31ebc75d8casm10961169eec.3.2026.08.13.10.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2026 10:31:54 -0700 (PDT) From: Nguyen Dinh Phi To: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Dmitry Torokhov , Andy King , George Zhang Cc: Nguyen Dinh Phi , Wupeng Ma , virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 3/3] vsock: use sock_error() to consume sk_err after a failed connect Date: Fri, 14 Aug 2026 01:30:20 +0800 Message-ID: <20260813173024.2362935-4-phind.uet@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260813173024.2362935-1-phind.uet@gmail.com> References: <20260813173024.2362935-1-phind.uet@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" vsock_connect() returns sk_err to userspace but does not clear it: if (sk->sk_err) { err =3D -sk->sk_err; For a blocking connect() the error has already been delivered as connect()'s return value, so leaving it set causes subsequent operations like poll()/epoll() to keep reporting POLLERR even though the connect failure was already delivered. The error should be consumed once it has been returned to userspace. Switch to sock_error(), which reads and clears sk_err atomically, matching the behavior of other protocol implementations such as __inet_stream_connect(). Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") Tested-by: Wupeng Ma Reviewed-by: Stefano Garzarella Signed-off-by: Nguyen Dinh Phi --- net/vmw_vsock/af_vsock.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 62e22c4b13c0..e89cb84b8d73 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1842,12 +1842,10 @@ static int vsock_connect(struct socket *sock, struc= t sockaddr_unsized *addr, prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); } =20 - if (sk->sk_err) { - err =3D -sk->sk_err; + err =3D sock_error(sk); + if (err) { sk->sk_state =3D TCP_CLOSE; sock->state =3D SS_UNCONNECTED; - } else { - err =3D 0; } =20 out_wait: --=20 2.53.0