🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26696

[PATCH RFC net v5 02/10] net/iucv: do not clear SEND_SHUTDOWN to send a control frame

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

iucv_send_ctrl() allocates with sock_alloc_send_skb(), which fails once
SEND_SHUTDOWN is set, so it clears the bit first and writes a copy of
sk_shutdown back afterwards. recvmsg() calls it for a window update and
the NETDEV_GOING_DOWN notifier for a FIN, both without the socket lock.
On a socket that has shut down sending:

- A shutdown(SHUT_RD) done in between is undone when the copy is
  written back: the call returned 0 and the socket still receives.
- sendmsg() can find SEND_SHUTDOWN clear and send data after the SHT of
  a shutdown(SHUT_WR) that already returned.

Allocate the control frame with sock_wmalloc() behind the test of
sk_sndbuf that sock_alloc_send_skb() makes, and leave sk_shutdown alone.

Fixes: 4e0ad3221691 ("Subject: [PATCH] af_iucv: enable control sends in case of SEND_SHUTDOWN")
Cc: stable@vger.kernel.org # 6.18.x
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
---
v5: unchanged.
v4: https://lore.kernel.org/netdev/20261114-b4-disp-fc0634a3-v4-2-f96c506447ce@proton.me/
AI review of v3 3/7: https://lore.kernel.org/all/sashiko-outbox-210385@kernel.org/

New in v4. iucv_send_ctrl() clearing SEND_SHUTDOWN is what the AI
review of v3 3/7 is about (link above), what the notes of
v3 2/7 and 7/7 left open, and where my copy of Hidayath's sk_shutdown
test loses its bit. v2 rewrote the function and v3 dropped that after
Alexandra's review. This is only the part about sk_shutdown; v2's
allocation, which ignored sk_sndbuf for a FIN and the first SHT, stays
out (cover letter, "Not in v5"). It goes ahead of 3/10 and 4/10: the
check 3/10 adds and the wait 4/10 moves out of the socket lock both rely
on the bit staying set.

The first item of the commit message, in the emulated setup: a task
reads from a socket shut down for sending, with SO_MSGLIMIT 2 so that
nearly every read sends a window update, and another calls
shutdown(SHUT_RD). Over four runs of 200 cycles, poll() then shows no
EPOLLRDHUP in 8 to 55 cycles of a run on net and with 1/10, and in none
with this patch or with the series.

The wake-up the AI review describes is the one for 4/10's memory wait.
It can only be missed when two waits overlap, so a test kernel on top of
the series makes them overlap. The writer sleeps 1000 ms between
releasing the socket and its wait for send memory, and a window update
waits 1500 ms in iucv_send_ctrl() ahead of its allocation. The
sk_state_change() that recvmsg() calls when its window update finds no
room is taken out, as it would wake the writer. A writer blocks with the
send memory full and SO_SNDTIMEO 8 s, shutdown(SHUT_WR) follows at 200
ms, and at 300 ms a recv() that owes a window update. The writer returns
-EPIPE after 1803 ms, when the reader lets go of the socket lock. With
the clear and the restore put back around that delay, the writer sleeps
until its timeout, 9129 ms. Without the reader the writer returns on
both kernels when the 1000 ms are over.

By inspection:
- the second item of the commit message
- poll() on a socket shut down both ways reported no EPOLLHUP while
  the bit was clear
- sock_alloc_send_skb() also returned and cleared a pending sk_err,
  which af_iucv sets only at the end of close(), after its FIN
- SOCK_NOSPACE is no longer set; SOCKWQ_ASYNC_NOSPACE still is, for a
  socket with O_ASYNC
- of Hidayath's KCSAN reports on net-next, the 6 between
  afiucv_hs_rcv() and iucv_send_ctrl() and the 2 between
  iucv_send_ctrl() and iucv_sock_shutdown() are on these writes

A KCSAN build of an earlier draft of v5 printed the first of those
pairs 3 times, all on a kernel without this patch and all on the clear
this patch removes. It never printed it with this patch, nor on net,
which has the same clear: too few cycles to show that the report is
gone.
---
 net/iucv/af_iucv.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index 0c69fd661431..4e69c7d6e3fb 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -380,26 +380,25 @@ static void iucv_sever_path(struct sock *sk, int with_user_data)
 static int iucv_send_ctrl(struct sock *sk, u8 flags)
 {
 	struct iucv_sock *iucv = iucv_sk(sk);
-	int err = 0;
 	int blen;
 	struct sk_buff *skb;
-	u8 shutdown = 0;
 
 	blen = sizeof(struct af_iucv_trans_hdr) +
 	       LL_RESERVED_SPACE(iucv->hs_dev);
-	if (sk->sk_shutdown & SEND_SHUTDOWN) {
-		/* controlling flags should be sent anyway */
-		shutdown = sk->sk_shutdown;
-		sk->sk_shutdown &= RCV_SHUTDOWN;
-	}
-	skb = sock_alloc_send_skb(sk, blen, 1, &err);
-	if (skb) {
-		skb_reserve(skb, blen);
-		err = afiucv_hs_send(NULL, sk, skb, flags);
+	/* Control frames go out after a shutdown too, so this is not
+	 * sock_alloc_send_skb(), which fails on SEND_SHUTDOWN. sk_shutdown is
+	 * left alone: it is read without the socket lock, and not every
+	 * caller here holds it.
+	 */
+	if (sk_wmem_alloc_get(sk) >= READ_ONCE(sk->sk_sndbuf)) {
+		sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
+		return -EAGAIN;
 	}
-	if (shutdown)
-		sk->sk_shutdown = shutdown;
-	return err;
+	skb = sock_wmalloc(sk, blen, 1, sk->sk_allocation);
+	if (!skb)
+		return -ENOBUFS;
+	skb_reserve(skb, blen);
+	return afiucv_hs_send(NULL, sk, skb, flags);
 }
 
 /**

-- 
2.56.1
Technical Details
Message-ID: <20261203-b4-disp-8029c32d-v5-2-0bce531e20d0@proton.me>
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377006-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!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377006-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 02/10] net/iucv: do not clear SEND_SHUTDOWN to
 send a control frame
Date: Thu, 03 Dec 2026 22:02:14 -0500
Organization: Usenet Network
Message-ID: <20261203-b4-disp-8029c32d-v5-2-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="2661521"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:7JmGWX28YJXk/yP3xWG/jC9n8ns= sha256:1LlhkjkDO1AUVtxI+CW5iiAZGw6N8eB99KitEx0VQ4k=
	sha1:mOyfPzPS701h+Yd9IcSPrwHDJzg= sha256:8+AwVsQzlaNOdmGd2XBUfw//6cRexLw6Ir4WhpkcudI=
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 D980D117AD4; Fri,  4 Dec 2026 06:03:09 +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 n0be2wCyHmPQ;
	Fri,  4 Dec 2026 06:03:06 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377006-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 9E16F117AB3; Fri,  4 Dec 2026 06:02:58 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id B183A261EE; Fri,  4 Dec 2026 03:02:45 +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=1796353342;
	b=GUxeSvD3xb62BT2Z5mwDcy28N8V3gbOXdLGBhyNxcjabslRzp7V+nfPkWeXUwJQwqZK5
	 KJeMGKblZELyKUkyv1acz32TAokdAMssH9pk5FZHSUmJcMb32Gn647BX0LJwr1YjHUCSv
	 EgXJSWhPST3S1+mp15XkUggnaGUw/vzf+MUri1o3Y6YeJw7XBZBtVeQLXYJ0Xw4h/PKiA
	 h+k1nmEsQs7HxKUdJH9n/R6K5IyOP1p9s6DKT92qHLy2/MdeKBsmed50adJmzGPsdlQRe
	 d1Qub8Gb51tfWo7kVCzlivEyUfpVZXsLPApS1SUI255OpDjKttVbR9LTb9YIPGKYaHg==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796353342;
	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=W4wk9OGDdWGtzW2gNglH3xsH/JuSROnBVsEwYHMgULI=;
	b=YsUXTH66I5F1AUlvkWUCZ12qEPilYRnDUXtaftvW2vLcwy+oo6UZdENEHeHUWNabe2Ba
	 leECaJ01oCx4387ffL3g21xMQDK3feeHqahfnFBY16SBbF67CS1HPMaZHFwwV2s19TPxz
	 tjUbD8g5YUgxKzTOnRUrrZo9IdZbkj7diT4Kuej+EKd6MRYkYyMtfQwJ/Swu9Sdy6IDi0
	 7u6TZJFzc5OyRqLOx/E6w18FwGyVwadUpsf2c5OLYqM9hECYqpi8zmIpnETxIcC0X2Pe/
	 tTn1Z7NAa/KR6b3qlbwYpUP3Uu+KSLg6ZBE9eLtCt2DwRvEDTM9xH8IZ4iAkJBgRlzw==
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=m+JDvQWX;
	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 942A160A3818;
	Fri,  4 Dec 2026 03:02:22 +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=m+JDvQWX
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=1796353336;
	b=T0ua33DnCjn+2X8kqxGvfJ3B7iuODUyc8y24PHaSQfh3A41HQFzYFxdkCDR8HgMvOWF/
	 1b+Ech9t7GMZb+J8VyI/qcPvRC1+pAQMWauyulQEJSzRKBTA7pSrgJHwiHtrdL4890dug
	 zpKjYJFNNJwdzcPDuxPpQ9QWvH6APiXYkZwX+RveS10tPlPEIgPeY0dsD5m9RAm55h1v4
	 ON/XgHaVrOiIF4XIfb6Zb9ttokmgRIcB7DDdtCwHwT3QQXZ22QXRpwEmc9roZXzboLtV+
	 QjAA4bjEJaqzAHlNUCBgTbzQw6pZnmm/x072gUkdRDkRG0Vz1lQ+/O+k0Ijj9PM6sMg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796353336;
	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=W4wk9OGDdWGtzW2gNglH3xsH/JuSROnBVsEwYHMgULI=;
	b=ZoTgGZrk8vFzeVHPwxifZVfXODK6X7vGZ/yyZ90mVpE90Abr9WMPzonKKV44mrZkx04t
	 ryLbn9IImNMpiBv78kKjGelVfQVCtetAbueXSORdilopxm2SABcJocKcSz1Ix7b5gS23R
	 BW2pZSmtgWEdkrUGCCUJ8D7inXG/fWBXB1jaULjmZGj6g9avXejEv1A7KfABgK8q/9hQI
	 qckXSCdqEu0Q0XhKXFeQ97ouwVNJNKdkQTSQKxXvGfQJzF5XfGBNEGLAjCAr8BU3fLMPn
	 /73zHITgPfmOOiN7GpulzJKGDsN2nwjYS20WBfwDVjwUeeUFPVRwg+PBZraJ+yxKAIA==
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=m+JDvQWX;
	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 B129C606A33A;
	Fri,  4 Dec 2026 03:02:16 +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=1796353336;
	b=aHSVrTuQLKYUODz2i/BBbCeCAXjF9yzk0xxc4VVisQzldIqEjVuc33HXQZXg2OegXJ3x
	 MD4RfHsVcyJCBOwGSiYG2vf8546vCwEZMcPScS5F2/LANkHNT0ZaFz+3SF/0e+WR+3qxw
	 E5TVXAjD3JRNEXbzWZtrANDpn8hxuFPRVP/Oy8cDqgVIndHSbAkQxIbKBJUCitqGB+1V7
	 siAjbs69AT5wqDG80ugAgTDeeZ1fpW7Cvn8NQxLYcbmmbYtaASGQyg2e4HDHDynEfRlKR
	 OkVTEu+y9gw6V2/bAZ1qUYtA8Al4dh4b08B5/ckIhDeK5zVF3HijArUtDmHtUbea6cQ==
X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256;
	c=relaxed/relaxed; t=1796353336;
	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=W4wk9OGDdWGtzW2gNglH3xsH/JuSROnBVsEwYHMgULI=;
	b=3pANMM+hCn/WsMX0HVggLq5ZheK4BAC/F3KyO9wV9oeK7gO1iZgDvzxJxCGlh1kxBkAX
	 BFuTeMtIfvNDKG9TGlZbh37ZRIAkVeWs4B5BahhKUKkqDugSRugSdQRFa1jXVxobHzcFO
	 bS8Cdf2RDl3gAHJ+nxtd7qXgK6jqHxLEpMFopvbVvTkj7Sqa93DW7yDVqa/91m9X5fq8N
	 ek4pYC5XUdD6jUsin6JOZfBjzinGK1xvQbo7aWix9KgfVKkwDuGaapfpD4rPZFfon2a4I
	 OZ6zYLIqrcOWXLcZcnMuUS/lpyrzabFdZof4/QtY+15VFVNUWFWUlAiNPtA524VcdfQ==
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 E7D4D1F00897;
	Fri,  4 Dec 2026 03:02:14 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796353336;
	bh=W4wk9OGDdWGtzW2gNglH3xsH/JuSROnBVsEwYHMgULI=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To;
	b=m+JDvQWXjrwtj4YMe8wsYgmogZzaHOjdI2t50xGULWnNLRMcqJHVG9vjFmuU70X9w
	 Y007xNyO6tsjXqRGM3h+Q+SXr+axH7YyIe5u56JtUpOjLPP8G64F/e4Rzk2I3z4QhQ
	 BT1owHyB5xF3NPSOGTI5o1oTaaxi+KFWbvhfbtxk30Vj+Cemk1W3+RADfrD5Xh5Fqq
	 Xc3KHUoOFYMu6D1amYesx4I8OE9xWJ4oyOvJTHqx0vaqITyOAKqR98oaa2FMR7RFX5
	 bWFlgGsd4RnbjBYmtiG8FFeVYQQrd6lwUWn0aLbDRV56pdNUumCTJsC1knBqplRQMB
	 hLLURBvPoSeFg==
X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1])
	by lkml.kernel.org (Postfix) with ESMTP id 75D5B45B0D;
	Fri,  4 Dec 2026 03:02:14 +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=5363;
 i=hexlabsecurity@proton.me; s=default; h=from:subject:message-id;
 bh=TslupjUoD9luFztWezumEtNBP/EsmwWZ9u0ntwfUxWQ=;
 b=QA7U3y6eU89naCo/aCMY+8VU8bWUVKhKL1TPh0+9HY7qoch0DsR84ONInPhvqmO72U2QUjex4
 PNtDW40BAf4C0AmB1LAjPOIxUqywgVafwWlntms4PsqKK8SeDpQQ+C5
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