🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #2393

[PATCH net-next v4 2/9] tls: Check for a pending signal after an empty record

#2393
From: Chuck Lever
Date: Mon, 12 Oct 2026 15:29
87 lines
9572 bytes
tls_rx_rec_wait() tests signal_pending() only after it sleeps, and
it skips the wait loop when a record is already parsed.
tls_sw_recvmsg() calls tls_rx_rec_wait() once per record, and a
zero-length application_data record does not advance either bound
of the receive loop. A peer that streams such records holds the
caller in recvmsg(), unresponsive to SIGKILL, for as long as they
arrive. The hang has not been reproduced.

Test for a pending signal in tls_sw_recvmsg() before it fetches the
record after an empty one. A reader that has copied data gets the
data. A nonblocking reader gets -EAGAIN rather than -EINTR. Pending
task work alone makes signal_pending() true, and io_uring retries a
nonblocking receive only on -EAGAIN. The test stays out of
tls_rx_rec_wait() because tls_sw_read_sock() also calls
tls_rx_rec_wait(), from callers that cannot act on a signal.

Decrypt an empty record synchronously. The code at recv_end
overwrites err once any record has been decrypted asynchronously.
With only empty records queued, the reader then gets zero, not the
errno.

Fixes: c46234ebb4d1 ("tls: RX path for ktls")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260720-tcp-read-sock-v2-0-29545d034f3c@kernel.org?part=1
Signed-off-by: Chuck Lever <cel@kernel.org>
---
 net/tls/tls_sw.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index a64244566af4..f2062e141512 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1824,6 +1824,7 @@ int tls_sw_recvmsg(struct sock *sk,
 	bool is_peek = flags & MSG_PEEK;
 	bool rx_more = false;
 	bool released = true;
+	bool nodata = false;
 	bool zc_capable;
 
 	if (unlikely(flags & MSG_ERRQUEUE))
@@ -1858,6 +1859,18 @@ int tls_sw_recvmsg(struct sock *sk,
 		struct tls_decrypt_arg darg;
 		int to_decrypt, chunk;
 
+		/* A run of empty records advances neither loop bound, and
+		 * tls_rx_rec_wait() tests for a signal only after it sleeps.
+		 */
+		if (nodata && signal_pending(current)) {
+			long timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
+
+			err = -EAGAIN;
+			if (timeo)
+				err = sock_intr_errno(timeo);
+			goto recv_end;
+		}
+
 		err = tls_rx_rec_wait(sk, flags & MSG_DONTWAIT,
 				      released, !!(decrypted + copied));
 		if (err <= 0)
@@ -1874,9 +1887,12 @@ int tls_sw_recvmsg(struct sock *sk,
 		    tlm->control == TLS_RECORD_TYPE_DATA)
 			darg.zc = true;
 
-		/* Do not use async mode if record is non-data */
+		/* Do not use async mode if record is non-data, or if it
+		 * is empty: once a record has gone async, recv_end
+		 * discards the error that ends a run of empty records.
+		 */
 		if (tlm->control == TLS_RECORD_TYPE_DATA)
-			darg.async = ctx->async_capable;
+			darg.async = ctx->async_capable && to_decrypt;
 		else
 			darg.async = false;
 
@@ -1910,6 +1926,7 @@ int tls_sw_recvmsg(struct sock *sk,
 		/* TLS 1.3 may have updated the length by more than overhead */
 		rxm = strp_msg(darg.skb);
 		chunk = rxm->full_len;
+		nodata = !chunk;
 		tls_rx_rec_done(ctx);
 
 		if (!darg.zc) {

-- 
2.55.0
Technical Details
Message-ID: <20261012-tls-follow-on-v4-2-8cea429565da@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-345070-linux-kernel-netdev=dewy.ru
References: <20261012-tls-follow-on-v4-0-8cea429565da@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-345070-linux-kernel-netdev=dewy.ru
From: cel@kernel.org (Chuck Lever)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v4 2/9] tls: Check for a pending signal after an
 empty record
Date: Mon, 12 Oct 2026 11:29:50 -0400
Organization: Usenet Network
Message-ID: <20261012-tls-follow-on-v4-2-8cea429565da@kernel.org>
References: <20261012-tls-follow-on-v4-0-8cea429565da@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="1811728"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:n+IpagDjQLshXH1Nz1nykpupasE= sha256:gBCgZJ1REZUlIwHszR7aoGuNMq/6I1A9/8A6gzdjTug=
	sha1:hNhCsX50ntdTBnzfGwIcysxxpZE= sha256:U/pBnxVbezxTlbevt4nCv0hWbH6ENuEoeD+QpFueZ9s=
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 BD89210FC34; Mon, 12 Oct 2026 18:38:57 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.441
X-Spam-Status: No, score=-1.441 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.241, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	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 UdPzz7YSZTNP;
	Mon, 12 Oct 2026 18:38:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-345070-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 B21D810FC25; Mon, 12 Oct 2026 18:38:44 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sto.lore.kernel.org (Postfix) with ESMTP id D0CA6602065; Mon, 12 Oct 2026 15:30:49 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 1AE2D4A012A;
	Mon, 12 Oct 2026 15:30:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AQLe2+W5"
X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0E3E4A0129;
	Mon, 12 Oct 2026 15:30:07 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791819009; cv=none; b=A/KDKo0Nv3PlWCmcI43kRfafWO8e7l5lvKmcDTQ5v6oNKt2DSK2veRiHnUpA4k+dueAF40RuDDEG/8QLN6fFhDo/Jl6lwlVPPAgyprMGbqOk8o4kWrwtM+vv/p7iz3WUpT39Qf9MSvB5RzH9G3IzJw+aaRp+UmrB8J81womrTUg=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791819009; c=relaxed/simple;
	bh=mOepAjr//54ldF1UryFcMVOT1lu3Ngq/1OgW50HIwBk=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=Tw4Gp+4DsyYmZpEBSfuwxHEOPkXKnFSP8kUFnTaiFxUM/fJwOEomoP5kTEyaSulOrBVODZh2gJnT9QKt/2Ujgw6nkC34rR/zoOPPlZ7b5WWhmwvzsY3l7NV2Mfn4tgsRUBKTQXIzk+4luui+Ooj9fv0yhjehylAzKZl1sOLeIVU=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AQLe2+W5; arc=none smtp.client-ip=100.103.45.18
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50A4C1F0089E;
	Mon, 12 Oct 2026 15:30:06 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1791819007;
	bh=mUVftk9YWXAVqs1uJSVHJuCxdiqbHnEl83BwT4U73+c=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=AQLe2+W5mwzRPjmkR4elrkHAb4xDtSQrHPN1y+4K+ZDix5wVTcRYsvwVm1ZNUt64I
	 R1B/PtyVr0n9DfphWT5OqtysPKr6atmxqBJo0tc6I7NKXEtrTt0I1pWjhtAn6RfgKx
	 XUH8Unuzw95z0rloElj9pYCjKE8cDsy1oO122FA0ouEKYklIx7VM0ebPh0OFwSUO/T
	 0iLdxyCyfdqx769Q2Zh35hMPHAwEFQgP9AvE5H0M1b5joxs3G9vx195mLJIYghOsdC
	 8IaZWKwF4MtknhGcQd5D/CLAO27MV3Wl2kjqLW9HfU+v7uHPveLxcFjnt06k8B7Chm
	 kVJ119IDDVxRQ==
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-In-Reply-To: <20261012-tls-follow-on-v4-0-8cea429565da@kernel.org>
X-Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, 
 sashiko-bot <sashiko-bot@kernel.org>
X-Mailer: b4 0.17-dev-9c833
X-Developer-Signature: v=1; a=openpgp-sha256; l=3207; i=cel@kernel.org;
 h=from:subject:message-id; bh=mOepAjr//54ldF1UryFcMVOT1lu3Ngq/1OgW50HIwBk=;
 b=owEBbQKS/ZANAwAKATNqszNvZn+XAcsmYgBqzPz6bmv26F2M95nea1XJtmuUUcSBT3Bi1mpom
 QEb0PNd1mKJAjMEAAEKAB0WIQQosuWwEobfJDzyPv4zarMzb2Z/lwUCasz8+gAKCRAzarMzb2Z/
 l/DpD/96pV/7+YLnrwtLbl8KOpnS4N46ueR1AE8K7JrlPqz8bvYiqBNEiZmd1jSOJ29acl7AIzX
 eIx+jtPKBF0rrP/czVcPV1eR/mgLTBZ2tYGi9F7yGlW+pT+iX/D1sOaREJx/vOdAnVfspIwr1jx
 mY3uEMNQIlLq7MR+wtPo63UIedLVXppCv1X2fVHUrFO1ZPazdCfR3MDJoqBEVAiqmYy4rXLFdDa
 biopXsTGgb8Fk14Xppic2aukpAFUvHW0q+rDR6M2D/J3dTfYkVAk8nUV2Tj1FFyn0Wjb6P0TLNp
 /I6IbHcIUl+5OraWdShlMTHIpdUmRQ9K/JPcBsyOcZXqlfleYTodYtOPpCAZhQlynqX69aqlXlT
 8KZsSb2G3eScbvk3vpus4CZrv7IsPsGFLPDbqJ8g78mZTBtKlFHH8QkBHiIBIRHQWnFVamdX8Jp
 MpCH5q1GOsQSJN//BpxUrCbF8+LNUjCwI7qxYJc8EZCxKkuaxX4fZK56WdwtpBCQeZ9pS1MTTtm
 OZJ+lFhbCJLEPL0V3ypHAsmsW1hc6S00S9Ugl8IeE6rOH19xGfex3MyfXJeYpt25gZFSlpoVZh1
 kRguZRK7Q3x6AgXMR7GPQe51sjwM2Dn4TWhNJ6Vvm2vBJra9uqNjsawANykZ9Fnt/dcYVIEKakr
 5g34W8DREQXE1uQ==
X-Developer-Key: i=cel@kernel.org; a=openpgp;
 fpr=28B2E5B01286DF243CF23EFE336AB3336F667F97