Netdev List
 help / color / mirror / Atom feed
From: Dickson Wu via B4 Relay <devnull+dickson.wu.certik.com@kernel.org>
To: netdev@vger.kernel.org
Cc: John Fastabend <john.fastabend@gmail.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Sabrina Dubroca <sd@queasysnail.net>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	 Simon Horman <horms@kernel.org>, Vakul Garg <vakul.garg@nxp.com>,
	 Jiayuan Chen <jiayuan.chen@linux.dev>,
	 syzbot+ca1345cca66556f3d79b@syzkaller.appspotmail.com,
	security@kernel.org
Subject: [PATCH net] tls: use non-blocking sends in tx_work_handler
Date: Fri, 27 Nov 2026 10:08:46 +0000	[thread overview]
Message-ID: <20261127-ktls-close-c-v1-1-1470bb718a8d@certik.com> (raw)

From: Dickson Wu <dickson.wu@certik.com>

tx_work_handler() calls tls_tx_records(sk, -1), so each record is
pushed with the flags of the sendmsg() call that created it. 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. tls_sk_proto_close() then
waits for it in disable_delayed_work_sync(), so the closing task sits
in D state and ignores SIGKILL.

Each such socket holds a system_wq worker. With the tls module loaded,
an unprivileged local user can occupy all events workers on a CPU this
way (1024 on a one-CPU test guest), which stalls
schedule_on_each_cpu() callers.

Pass MSG_DONTWAIT from the work handler. On -EAGAIN the record stays on
tx_list and tls_sw_write_space() schedules the work again when TCP has
room. The close path does not change: tls_sw_release_resources_tx()
still calls tls_tx_records(sk, -1) from process context, so data
queued before close() is still flushed with the socket's own blocking
semantics and the FIN follows it. The worker no longer applies the
saved per-record flags, such as MSG_MORE or MSG_NOSIGNAL, which belong
to a sendmsg() call that has already returned.

Jiayuan Chen proposed the same approach earlier with a new extra_flags
argument to tls_tx_records() (Link below). This version needs no new
argument, and the close flush that review of that patch focused on is
unchanged.

Reported-by: syzbot+ca1345cca66556f3d79b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ca1345cca66556f3d79b
Link: https://lore.kernel.org/netdev/20260227063231.168520-1-jiayuan.chen@linux.dev/
Fixes: a42055e8d2c3 ("net/tls: Add support for async encryption of records for performance")
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
Tested on x86_64 UML with KASAN at v7.4-rc4 (9437ee8b6cf6), as uid 1000
with no capabilities or namespaces, over loopback:
- Interrupted 256 KiB send, peer reads 1 KiB and stops, then close():
  stock and reverted, the closer stays in D state 33 s after SIGKILL
  with the worker in sk_stream_wait_memory(). Patched, the closer is in
  S state in the normal close flush and SIGKILL ends it within 3 s.
- 1900 kTLS pairs, each with a partial send after a 20 ms SO_SNDTIMEO:
  stock and reverted, 1024 busy events workers and a
  /proc/sys/vm/stat_refresh write over 10 s. Patched, 0 busy workers
  and 11 ms.
- Patched controls: an immediate close after an interrupted send
  delivered and decrypted all 32768 accepted bytes. With the sender
  idle (no further send, no close) after the worker got -EAGAIN, the
  next write_space rescheduled it and a slow reader still got all
  32768 bytes. An uninterrupted send delivered all 262144 bytes, and
  plain TCP is unchanged.
- No KASAN, BUG or WARNING in any run. The patch applies unchanged to
  6.1.y, 6.6.y, 6.12.y and 6.18.y.

A reproducer is available if it helps.

This was found and the fix prepared with AI coding tools (OpenAI Codex
agents, with review by Claude). I went over the analysis, the earlier
thread and the patch before signing off.

 net/tls/tls_sw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 226e0f176..16dcd134e 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);
 		release_sock(sk);
 		mutex_unlock(&tls_ctx->tx_lock);
 	} else if (!test_and_set_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask)) {
-- 
2.43.0



             reply	other threads:[~2026-11-27 11:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 10:08 Dickson Wu via B4 Relay [this message]
2026-11-28 11:53 ` [PATCH net] tls: use non-blocking sends in tx_work_handler netdev-bot+sashiko
2026-11-28 14:14   ` Dickson Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127-ktls-close-c-v1-1-1470bb718a8d@certik.com \
    --to=devnull+dickson.wu.certik.com@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dickson.wu@certik.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=security@kernel.org \
    --cc=syzbot+ca1345cca66556f3d79b@syzkaller.appspotmail.com \
    --cc=vakul.garg@nxp.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox