๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23854

Re: [PATCH net] tls: use non-blocking sends in tx_work_handler

#23854
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 11:53
173 lines
14181 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 1 ยท Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] Incomplete fix: the TLS close-time flush can still sleep forever
  in a system_wq kworker.
- [Medium] Lost reschedule (TX stall) after the worker gets -EAGAIN with
  empty TCP queues.
- [Low] Commit message inaccuracy.

--

tls: use non-blocking sends in tx_work_handler

This patch makes tx_work_handler() push pending TLS records with
MSG_DONTWAIT instead of the per-record flags saved from sendmsg(). This
stops a system_wq worker from sleeping forever in sk_stream_wait_memory()
when the peer keeps its window closed. The close path flush in
tls_sw_release_resources_tx() is unchanged.

Link: https://lore.kernel.org/netdev/20260227063231.168520-1-jiayuan.chen@linux.dev/

> When a
> blocking send returns early (signal or SO_SNDTIMEO) and leaves a
> partially sent record, the work handler pushes the rest with blocking
> flags. If the peer keeps its window closed, the worker sleeps in
> sk_stream_wait_memory() with no timeout.

[Severity: Low]
Is this accurate for the SO_SNDTIMEO case?

Before this patch the worker pushed with rec->tx_flags, which do not
include MSG_DONTWAIT. tcp_sendmsg_locked() takes the wait time from the
socket:

net/ipv4/tcp.c:tcp_sendmsg_locked() {
    ...
	timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);
    ...
}

So the worker inherited sk->sk_sndtimeo. With SO_SNDTIMEO set,
sk_stream_wait_memory() returns -EAGAIN when the timeout expires, and
tls_tx_records() treats -EAGAIN as non-fatal.

The wait has no limit only when sk_sndtimeo is infinite at the time the
worker runs. That is the signal case, or SO_SNDTIMEO cleared after the
partial send. The 20 ms SO_SNDTIMEO test in the notes would only match
this description if the timeout was cleared afterwards.

Could the commit message say more precisely which configurations hit
this?

> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> index 226e0f176fdc8..16dcd134e572f 100644
> --- a/net/tls/tls_sw.c
> +++ b/net/tls/tls_sw.c
> @@ -2428,7 +2428,7 @@ static void tx_work_handler(struct work_struct *work)
>  
>  	if (mutex_trylock(&tls_ctx->tx_lock)) {
>  		lock_sock(sk);
> -		tls_tx_records(sk, -1);
> +		tls_tx_records(sk, MSG_DONTWAIT);

[Severity: High]
The commit message says tls_sw_release_resources_tx() "still calls
tls_tx_records(sk, -1) from process context". Is that always true?

net/tls/tls_sw.c:tls_sw_release_resources_tx() {
    ...
	tls_encrypt_async_wait(ctx);

	tls_tx_records(sk, -1);
    ...
}

When a kernel thread drops the last reference to the kTLS socket file,
__fput_deferred() hands the file to the global delayed_fput_work:

fs/file_table.c:__fput_deferred() {
    ...
	if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
		...
	}

	if (llist_add(&file->f_llist, &delayed_fput_list))
		schedule_delayed_work(&delayed_fput_work, 1);
}

An unprivileged user can set this up. They put the kTLS fd in an
AF_UNIX SCM_RIGHTS cycle and close every fd. unix_gc() runs from
unix_gc_work. When it purges the dead skbs, unix_destruct_scm() calls
__scm_destroy(), which calls fput() in kworker context.

The kworker then runs:

delayed_fput()
  __fput()
    tls_sk_proto_close()
      tls_sk_proto_cleanup()
        tls_sw_release_resources_tx()
          tls_tx_records(sk, -1)
            tls_push_sg()
              tcp_sendmsg_locked()
                sk_stream_wait_memory()

The saved rec->tx_flags do not include MSG_DONTWAIT, so timeo is
sk_sndtimeo. By default that is MAX_SCHEDULE_TIMEOUT. If the peer keeps
its window closed, the signal_pending() check never fires because
kworkers ignore signals.

delayed_fput() releases its list one file at a time, and the work item
never runs concurrently with itself. Would every later deferred fput in
the system then stall behind this socket? Those files, their dentries
and their mounts would stay pinned until the peer reads.

This is the same kind of system_wq worker hang that this patch fixes.
Should the close flush also be bounded when it runs in a kthread, for
example by forcing MSG_DONTWAIT or a bounded timeout there?

[Severity: Medium]
Every worker push is now non-blocking. Can tx_work miss its only
reschedule when the TCP rtx and write queues are empty?

tls_push_sg() sets ctx->splicing_pages = true before it calls
tcp_sendmsg_locked(). Suppose the queues are empty and
tcp_stream_alloc_skb() fails, or tcp_wmem_schedule() returns 0. Then
sk_stream_wait_memory() returns -EAGAIN at once because timeo is 0.
tcp_sendmsg_locked() then issues the only wakeup it gives for this case:

net/ipv4/tcp.c:tcp_sendmsg_locked() {
    ...
	if (unlikely(tcp_rtx_and_write_queues_empty(sk) && err == -EAGAIN)) {
		READ_ONCE(sk->sk_write_space)(sk);
    ...
}

That callback is tls_write_space(). It returns early while
splicing_pages is still set:

net/tls/tls_main.c:tls_write_space() {
    ...
	if (ctx->splicing_pages) {
		ctx->sk_write_space(sk);
		return;
	}
    ...
}

So tls_sw_write_space() is never called. Nothing is in flight, so no
ACK arrives to run tcp_check_space(), and tx_work is not queued again.

The record, possibly partially sent, then stays on tx_list until the
application calls sendmsg(), splice_eof or close(), or until the peer
sends something. Before this patch, records from blocking sends were
pushed with a non-zero timeo. sk_stream_wait_memory() then slept for a
short random vm_wait and retried by itself.

Records from MSG_DONTWAIT sends already had this gap. This change
extends it to records left by blocking sends that were interrupted by a
signal or a timeout, and to records from blocking sends with async
crypto. Is a fallback reschedule needed for this case?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-ktls-close-c-v1-1-1470bb718a8d%40certik.com
Technical Details
Message-ID: <179586681082.3135.2680031921481682331@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373105-linux-kernel-netdev=dewy.ru
References: <20261127-ktls-close-c-v1-1-1470bb718a8d@certik.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373105-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] tls: use non-blocking sends in tx_work_handler
Date: Sat, 28 Nov 2026 11:53:30 +0000
Organization: Usenet Network
Message-ID: <179586681082.3135.2680031921481682331@kernel.org>
References: <20261127-ktls-close-c-v1-1-1470bb718a8d@certik.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="941187"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:e4nP2y925VY5s0N/+xXnrMPbJoM= sha256:MRJiSr2vwFefJxfbmUUtzciZ5Zito2GzHJL1EyxGNlw=
	sha1:axaoH8dL95YKB4zhwUKZ6d11Avs= sha256:zJVo5xeB8NXVSYitRt1kp6DIIJDRnwsB3RpQmgDgGAE=
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 148C4125F76; Sat, 28 Nov 2026 14:53:49 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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, URIBL_BLOCKED=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 JVkrmzjPqoQb;
	Sat, 28 Nov 2026 14:53:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373105-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 757DF125F72; Sat, 28 Nov 2026 14:53:35 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 7641925A1F; Sat, 28 Nov 2026 11:53:33 +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=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795866813;
	b=Ly5fnjuP7yGH6lWd8rrtEj9SQ0p2q1QtDnxwwC/oMHE+LbWee2zYjEfNky7BU1I4t3yZ
	 4RKxWvOq1iAQ0cmRFhO3LqkoBq9wmIEUG52MKVU/Y6FhKJTgT4HVNEoNNE3SVweSK2+3J
	 SJFIT3xnwcA3geM0TRnM6gr9BWgblSBuQ/tf7EA7eG5BEnCoz5WpByTJNtF739pR1JZlJ
	 eEdZU7I8NDh28UrZBYTaU/3B5AvZbVRcpp3cRbSA4aIK57eIrwz4ngx/wjFLmnkoGE3rD
	 XxmNyqllmsPd19x68mPch4Yobcu29PNZ35OLdF+82mXPCj/s0YbyNBRyvooC3DBQFrQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795866813;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=wT0Xa54YLlAfw3wPfmWKRXAKAisE6O065y0EN249Thk=;
	b=NymGBGf4eeK/6HVbafA9qKjp/gyR1gn+lXqIlv52hiAmVbtGcfVpjX1ca+HXjm5+BmYe
	 yuj3YPSfzuzfmTnhBn0boVFXUOXG2tNYjpD8kt9XkRhMevUd9ZiiOrNS2ys1DCYXXKis4
	 uCGXGg3QWm5Hv81I5He9ddmJQfEVTwKyTl81QkRIOlC7C89FaK7nBhNSj+cFMhw0tnivc
	 oG9pqept6qfclVNRptI2By9g4Z5qAeGjJINjJk1UXREp1eq8eaweVmVZ5zi30ZxStCPis
	 81/wR3BR2iFRX1CfA7Xp47TXymUlWdAz2c0+OZDlGPiMLQGG7+hrZayVd2nOAIx8z1w==
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=WPLNqnGN;
	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 4804A606A329;
	Sat, 28 Nov 2026 11:53:33 +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=WPLNqnGN
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795866812;
	b=ucZ7QFytEG+c6t+OGXeB5ggHN3WKqbEXhq+2dCEevhXbpVsfAiPV+fa/bj4lVnYnftei
	 z2QSkPTSYmRW+SuOIRqeAyqHnQx2uvJgW7+vNTjcfEkVnkbbV4o49bZEJJC7SC4MTwAtI
	 h9X2tzN02P4JVYRT+Nq/gDE0tNAaAUwJnTvCUMksARn8ifHuSCbRhWR8enKWTNiobe1Vu
	 ngYQ2Hw9nZWb9Man4eaVjdsL6o4LFOWJ3cufqzk08T55z+CEnI/bRRPcqXdHpgUWgCAsT
	 j3lnsIt5F0K0215Xng66b72jKVaDSQgE1rl94mvldUQkk95rknMjpJIOKoRgpQ3JzvA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795866812;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=wT0Xa54YLlAfw3wPfmWKRXAKAisE6O065y0EN249Thk=;
	b=hLfBHoy/GJbFHXESvXpeldRJVbd1j5MKeDT9b9KLcy0Lb6QUp7YnFAQBnwYW7GYjcLPD
	 2bGPHzqnaGvIXhdD8fLno9Lq6ix2SMS/+eT8k/ELGUQv2IbAIt9gtBB4Ie3CZMKB6OHgB
	 2Vhq2dy1V48dx4C6eiZYGxZOrvGbZODC7DAvyaYt7bGhUOVUvbHarUCHgs2p+xKQmCYqM
	 e2Jf43YQ1Oe/3A9Wxj79C1QivyhCLJZrCFzH1mMIC7crxlttE4lZ0JqE7UMKgnveQ6Xqa
	 ig7ZTfotFty4VF1iCmkg1xI/L7m1FaOXK/WSRBM7J2X3hFFqw1xkS33wVTs51++iPvw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WPLNqnGN;
	arc=none 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 671D6606A31F
	for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 11:53:32 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 464851F00893;
	Sat, 28 Nov 2026 11:53:31 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795866812;
	bh=wT0Xa54YLlAfw3wPfmWKRXAKAisE6O065y0EN249Thk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=WPLNqnGNhpum1GDeUOF0ABxIRUe3vIRP+zgZGS1lwdfFRk0AkkvBzNTCQgi/CbmA/
	 YIOVZg83XaMR4pFx7er3kh1k8IdPrsHvDtk65la9WETpSdX9n93Je8XwUWirlZB2Sm
	 YMaKw6RRXvJTja0w2mSBJ0Q76NQIL/0RHOVpOFAbG7p+mF4a8QW6ipZC9Qs4O/mBhD
	 RmWQc3jSQW8htyejoj2Q3cOolckjmU06+ihu0T+0Myymfo9PBpnxLMAtJJz4wKTto6
	 btVKqoYcep6dN30joUqM1JtcpGjYNnABkU/kDVFxi6OLw+AvAUcL5V72f43SQzvzAd
	 zH4oZpfwyJDcA==
X-Cc: netdev@vger.kernel.org, john.fastabend@gmail.com, kuba@kernel.org,
 sd@queasysnail.net, davem@davemloft.net, edumazet@kernel.org,
 pabeni@redhat.com, willemb@google.com, horms@kernel.org, vakul.garg@nxp.com,
 jiayuan.chen@linux.dev, syzbot+ca1345cca66556f3d79b@syzkaller.appspotmail.com,
 security@kernel.org
X-In-Reply-To: <20261127-ktls-close-c-v1-1-1470bb718a8d@certik.com>
X-sashiko-severity: High
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