🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26691

[PATCH RFC net v5 08/10] net/iucv: return EOF to a reader parked when the peer closes

#26691
From: Bryam Vargas via B4 Relay
Date: Fri, 04 Dec 2026 03:02
130 lines
16691 bytes
From: Bryam Vargas <hexlabsecurity@proton.me>

A recvmsg() that starts after the peer closed returns 0. One that was
already waiting returns -ENOTCONN: its wait ends on sk_state and does
not ask whether anything is left to read. In a z/VM guest over
HiperSockets that was every parked reader, 13627 of 13627 on net-next
[1]. poll() does not report EPOLLRDHUP for the close either.

Return EOF from the wait too when the socket is IUCV_DISCONN with
nothing left to read. As for a call that starts afterwards, it does not
matter how the socket got there: the peer's FIN, a severed z/VM path, a
transmit error, a window update that could not be sent or the device
going down. EOF does not say that all the peer sent was read: a severed
z/VM path drops the messages not yet received, for either call. Set
RCV_SHUTDOWN where the HiperSockets FIN is applied, as TCP does: poll()
then reports EPOLLRDHUP and EPOLLRDNORM for the close, and EPOLLHUP if
the socket had shut down its own sending. The other ways still report
none of the three.

Fixes: 561e036006dc ("[AF_IUCV]: Implementation of a skb backlog queue")
Fixes: 3881ac441f64 ("af_iucv: add HiperSockets transport")
Reported-by: Hidayath Khan <hidayath@linux.ibm.com>
Closes: https://lore.kernel.org/netdev/82691101-92d7-4838-b16e-2e41a83f65d0@linux.ibm.com/
Link: https://lore.kernel.org/netdev/51a4a40a-f34b-4d41-b049-69aa53f4dcf5@linux.ibm.com/ [1]
Cc: stable@vger.kernel.org # 6.18.x
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
---
v5: no code change. The last paragraph below names sendmsg() too: with
6/10 of v5 it applies a recorded FIN. The -ENOTCONN counts of the first
test are from this version's run; half of its cycles race the close, so
the counts move from run to run.
v4: unchanged, was 7/7. The last paragraph of v3's note is gone: since
2/10 the NETDEV_GOING_DOWN notifier no longer writes sk_shutdown, so it
cannot lose the RCV_SHUTDOWN of a FIN.
v3: this was 2/2 of v2. The EOF in the receive wait, which v2 had in
the lock patch, is here now, so both halves of one change in behavior
are in one patch: the wait returns EOF, and the FIN sets RCV_SHUTDOWN.
v4: https://lore.kernel.org/netdev/20261114-b4-disp-fc0634a3-v4-8-f96c506447ce@proton.me/
v3: https://lore.kernel.org/netdev/20261110-b4-disp-2a6b4364-v3-7-35677b68e697@proton.me/

Each half covers what the other does not. RCV_SHUTDOWN at the FIN gives
the parked reader EOF and poll() EPOLLRDHUP on HiperSockets, but a z/VM
path severed under a sleeping reader sets no RCV_SHUTDOWN; the check
in the wait covers the sever and gives poll() nothing.

In the emulated setup:

- the peer closes under a reader, 40 cycles, half with the reader
  parked and half with the close racing its recv(): -ENOTCONN in 34 on
  net, 28 with 1/10 to 3/10 and 24 with 1/10 to 7/10; EOF in all 40 with
  the series
- poll() after the peer's close, 10 cycles of three cases (nothing
  queued, a message unread, the socket's own SHUT_WR first): on those
  three kernels no EPOLLRDHUP in any of the 30 and no EPOLLHUP in the
  10 with SHUT_WR; with the series each case reports the same EPOLLIN,
  EPOLLRDHUP and EPOLLHUP bits as an AF_UNIX socketpair does on the
  same kernel. With RCV_SHUTDOWN at the FIN taken out again the reader
  still gets EOF, from the wait, and poll() reports as before the
  patch
- a reader parked while its own interface goes down, or while a send of
  its own fails in the adapter (SBALF15 0x10), and a z/VM reader whose
  path is severed (emulated CP): -ENOTCONN on those three kernels, and
  again with the EOF taken out of the wait; EOF with the series

The interface going down and the TX error change sk_state with no socket
lock, so the check in the wait looks at the receive queue again. A test
kernel has an mdelay() that holds the reader between its look at the
queue and its look at the state; a byte arrives and the interface goes
down in that time. The reader's call returns -ENOTCONN and its next two
the byte and EOF. With the receive queue left out of the check, the
first call returns 0 with the byte still queued. FWIW, by inspection
net returns -ENOTCONN the same way when the skb lands between its own
two checks, a narrower race window. The window update that could not be
sent is by inspection too.

After 6/10, the FIN is applied under sk_lock.slock on every path: by
the softirq when there is no owner, or by the owner from release_cb or
from sendmsg(). 7/10 has shutdown() write the same field under that
lock.
---
 net/iucv/af_iucv.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index b9eecebbdff1..8336f7056d49 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -75,6 +75,8 @@ static void afiucv_hs_synfin(struct sock *sk)
 static void afiucv_hs_fin(struct sock *sk)
 {
 	sk->sk_state = IUCV_DISCONN;
+	/* as a TCP FIN: EOF for a reader, EPOLLRDHUP for poll() */
+	WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
 	sk->sk_state_change(sk);
 }
 
@@ -1440,8 +1442,9 @@ static void iucv_process_message_q(struct sock *sk)
  * then and ends the wait.
  *
  * Context: Process context, socket lock held; sleeps with it released.
- * Return: the skb, or NULL with @err set. At RCV_SHUTDOWN the caller
- * returns EOF whatever @err is.
+ * Return: the skb, or NULL with @err set: 0 if the connection is gone with
+ * nothing left to read and the call could still wait. At RCV_SHUTDOWN the
+ * caller returns EOF whatever @err is.
  */
 static struct sk_buff *iucv_sock_recv_skb(struct sock *sk, int flags, int *err)
 {
@@ -1459,7 +1462,16 @@ static struct sk_buff *iucv_sock_recv_skb(struct sock *sk, int flags, int *err)
 		if (!timeo)
 			break;
 		if (sk->sk_state != IUCV_CONNECTED) {
-			*err = -ENOTCONN;
+			/* disconnected and nothing left to read: EOF, as at
+			 * the top of iucv_sock_recvmsg()
+			 */
+			if (sk->sk_state == IUCV_DISCONN &&
+			    skb_queue_empty(&iucv_sk(sk)->backlog_skb_q) &&
+			    skb_queue_empty(&sk->sk_receive_queue) &&
+			    list_empty(&iucv_sk(sk)->message_q.list))
+				*err = 0;
+			else
+				*err = -ENOTCONN;
 			break;
 		}
 		if (signal_pending(current)) {

-- 
2.56.1
Technical Details
Message-ID: <20261203-b4-disp-8029c32d-v5-8-0bce531e20d0@proton.me>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377011-linux-kernel-netdev=dewy.ru
References: <20261203-b4-disp-8029c32d-v5-0-0bce531e20d0@proton.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377011-linux-kernel-netdev=dewy.ru
From: devnull+hexlabsecurity.proton.me@kernel.org (Bryam Vargas via B4 Relay)
Newsgroups: linux.kernel.netdev
Subject: [PATCH RFC net v5 08/10] net/iucv: return EOF to a reader parked
 when the peer closes
Date: Thu, 03 Dec 2026 22:02:20 -0500
Organization: Usenet Network
Message-ID: <20261203-b4-disp-8029c32d-v5-8-0bce531e20d0@proton.me>
References: <20261203-b4-disp-8029c32d-v5-0-0bce531e20d0@proton.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="2661141"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:BKy6ACn281DnqDyIwalCjpb6RLc= sha256:fc75/X3Bs4rKXCgfq8VwIbTzGCn63LvwHMHavdmi/iA=
	sha1:ZBxNupRJz0Wo8qAR0Np3D6HA5kM= sha256:dM+YnAhcztVLae+H7A0U8EniwD9p8xxsOxyr9jLtKHw=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id D403A117AD2; Fri,  4 Dec 2026 06:02:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.74
X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id QlswDObShex4;
	Fri,  4 Dec 2026 06:02:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-377011-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 1B08A117AB3; Fri,  4 Dec 2026 06:02:36 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 9CED76016C8; Fri,  4 Dec 2026 03:02:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796353340;
	b=ce9Q9falHE9jwxGHccCtRNZusSRjEC6P+27O6IN4hnhA0L3filWfgzjiGDMtr57s6M5Z
	 82X8nzI+4qJt5N6k59KkxWYxyrkAv7re5PCHiFQD3V+iJUYSx7glN+2yD2ESw7She1Ig9
	 6WN5bmafJoofTj05HEvTJTa2EGf+7X0tK9YSyGQKUQnAxjg5GLtVdOtnL9GYI9lElfPf+
	 wBrNjfUPQ2fvBvNtsO2J3uZUDJ91PKDyq8sci6D3tnH3oWDDR5+CtZbzPQlDXWrWz238L
	 /cqeDfnfLo13W/OsszdIjYmTm+sQamRGqLO5JvctqEDvaemys+YquReeDNIkUGryv4w==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796353340;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date:
	 Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Message-Id:References:In-Reply-To:To:Cc:X-Mailer:
	 X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To:Content-Transfer-Encoding;
	bh=1XoJWbGdIUbC5ohBkRUeEcxZ+qpau02xr4szBngHApM=;
	b=Nc+d2z7MR9W9pXmvP+bSAs3IQRbMuB2rESRy/rT24VW3HDjPIsQWZg7PUcTo4mFidcgu
	 YN9tCXKUFF6dRASjXBnKD0kilqXxINMCBmjM3EuZgL4Bdk60WIPS9AeyARszWaTmZKMRC
	 mAamSdvHSX+karSAUI1L1WAI2v18guZtrxmQxuicuKyAJhL05uaxOAteIcpgy8XhKR0wr
	 TThoNub/tdjwPv11p8HJ9h9nms6b3rDI6xbkJrHAWhavgYgE38nof8VJDC0WjvWnRY/lh
	 eT2f5pqvt3WmLwKT6voYI7LSBShwXc0yjuRE5vDR3HrJWK9ZvHKjECCpSI4atzYbGVQ==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a9IQYrs3;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 0690860A2629;
	Fri,  4 Dec 2026 03:02:20 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a9IQYrs3
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796353339;
	b=Nq8Tn4VSRo6I7cZ6gwCkSHgiyGARxvpkl5ou1p5bPha5d5dowvG6qhTk9YWsUH83AB9C
	 QBjXf4hGaYHYiR4PVYLCMAMh73q2hKb558+oH+isHSYv0BcS//33OGmiPL+Sr6101Hk0z
	 /rIfVq9AzGgvWpXkOsziV9DEY5po5DW8fSc1N8HPGMSufyUB36E1DAVWDAp3yKV8BcKVu
	 8RTKbQJ7+fDH2M0KGRbZBMAzQXnUMAVH4wPvWPnLrZc8xN5dcpdXc7eTnrjMl3pVatkp1
	 Z8e5mPeJW3Em8/c8hB5TWifuiqYZKwPxaLIKTHlkUmMjMRcgecpJ76S5Rvq9UCHdxww==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796353339;
	h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version:
	 Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer:
	 X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To:Content-Transfer-Encoding;
	bh=1XoJWbGdIUbC5ohBkRUeEcxZ+qpau02xr4szBngHApM=;
	b=n/G3yBkkDk4mEfRD9UOsCrMJ6VxQZjGz5BQTgP9z1nMzedZKunB+JrbGjoZ0396NInV8
	 iJ/EGZrZR7S0gRQpcVgQ9qY66DkCEild/7rZ4Nli99JIXTa3UKChGThmb2FmdifLNys86
	 MjLBFkNC1Z3Qfp6Ohy0cmiV4sRJYhp/MlfVyURJeAAhRSNcP/6KXqv2onqv5ilf+x9KPD
	 iyxLnqGFBIdMriyusuWRYXH7vwB0HUUFqlGg/nrkpPTKi9d09yEroJdvVIYgmKkrcQzXn
	 y0UPAELY6DU1WEy62T9MJPRWg///tHK2ZAPlaCK70VgrwNWu7YLGt49SvAqjsnECxlg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a9IQYrs3;
	arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(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 E48AA60A2602;
	Fri,  4 Dec 2026 03:02:18 +0000 (UTC)
X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none;
	t=1796353338;
	b=G3hwKmE0281eBUyfrPHuYbxEuUwcH7PFexiz5s1+ULdij2iE9M111gbNj07SZh1elg2W
	 iQGseCp5fEHYyhzDvaK7T9gcFTMxVYb18A7boRo6aYMKKwI0Ua0WwvTqYOy0Xxn6DjYzN
	 5LKnKPXHS0nPb5HjHjKGYELUlmuSZmn6w52wBONaZBmBLfZMCajO8rfZzWvB003EnFFex
	 0x86cOkKmtN2jGJnqfylc8n81+QKggkys7tuy30m9kTvSRgln6CHG8WLJKw7WSiwcsQNo
	 yN6D9cFE6HYlVN5fuCZo/PWqFVZ/y/D7eS+ZEeDUD33KrBy7J6LFye6IKLvGjeE2qvA==
X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256;
	c=relaxed/relaxed; t=1796353338;
	h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type:
	 Message-Id:References:In-Reply-To:To:Cc:X-Mailer:
	 X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To:Content-Transfer-Encoding;
	bh=1XoJWbGdIUbC5ohBkRUeEcxZ+qpau02xr4szBngHApM=;
	b=cxS1z3aYz9A/8u5g4jE1F5zb+4haojTX7lAGc3Rd1PSOOYtsTX4BgaDEJkQSp+fZq23h
	 c2JxRfmP8g5rlkX38ZkHNRgqxkcrqrddhHdW0if5u+4hOFQ8ilDqluDyN1GcYvEwxm54B
	 2rsQ98KT2Gz87BL3/5VJfLSlcTQl6zqfQlxv8M4878/P7qBbhaW58JQMn3qnEBlQEh99x
	 1Bdh4aNh7Ok8fNcKHG3cdmAlYiGJv1QApcxTS6TslBL7mfMygSfPktswTATJkmgPz5YmM
	 WFsNgS2f34wGp1ymwQZDp5XIwUI3b34klKBk0BOi7WGXKs+nKbzfvfO5qL77EBbIC0A==
X-ARC-Authentication-Results: i=1; smtp.kernel.org; 
	arc=none smtp.remote-ip=100.80.115.77
X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77])
	(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.kernel.org (Postfix) with ESMTPS id A33151F0093B;
	Fri,  4 Dec 2026 03:02:16 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796353338;
	bh=1XoJWbGdIUbC5ohBkRUeEcxZ+qpau02xr4szBngHApM=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To;
	b=a9IQYrs3FF5oOuofFeBg0BmMXmvK7NO3Ahl+k4YdrhtKmqa+Uu6LXWb5fmPfPPzca
	 qccx//tLrBRT38q2Qh2tGNGjuHrUEf6yYDeZtNGjWQPUkioclE2pNjTaAYlLub9460
	 JWJrWf0dSVgOjdTepZTQXqDYk/i1MoTFTB4nWIP+pyl/QCiqguxwigm/1joSjaVO9H
	 UXS/aUlNhY0MqN+7A++PmmWKUilib584FZy6NDCXePBDj8roMK55K4u94s6xNMQQlX
	 OwiEBcGOP0TXgud/nbi82Qx67MT1ECFjlhNmjbgtMHAysD0YgriGc0Jcr+rJ6Gr3xo
	 EvGzJCygNEKfQ==
X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1])
	by lkml.kernel.org (Postfix) with ESMTP id 68B664D8B4;
	Fri,  4 Dec 2026 03:02:15 +0000 (UTC)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261203-b4-disp-8029c32d-v5-0-0bce531e20d0@proton.me>
X-Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, 
 Nagamani PV <nagamani@linux.ibm.com>, linux-s390@vger.kernel.org, 
 Simon Horman <horms@kernel.org>, Thorsten Winkler <twinkler@linux.ibm.com>
X-Mailer: b4 0.15.2
X-Developer-Signature: v=1; a=ed25519-sha256; t=1796353333; l=6271;
 i=hexlabsecurity@proton.me; s=default; h=from:subject:message-id;
 bh=lCP1QYmHFL5myxxBVV0eHKRlBuNnDwQBv7Iz02oe5fM=;
 b=6Bb/aLuWyrSqZGWLRxMEFUWlY56W6XTa7IDHptP8YSCljdIdWHvChUDEzxWxybymyymx0t2aq
 lw55wkVA4pUAx43mBcyjRs6wKJoDTcBSYsuMcUmoz0m/DAQjWyE7Erv
X-Developer-Key: i=hexlabsecurity@proton.me; a=ed25519;
 pk=xw1AhCtQdvuoQc+bOQIYy9o8G++cp4/VniI2G/tc3G8=
X-Endpoint-Received: by B4 Relay for hexlabsecurity@proton.me/default with
 auth_id=893
X-Original-From: Bryam Vargas <hexlabsecurity@proton.me>
X-Reply-To: hexlabsecurity@proton.me