From: netdev-bot+sashiko@kernel.org
To: dickson.wu@certik.com
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
Subject: Re: [PATCH net] tls: use non-blocking sends in tx_work_handler
Date: Sat, 28 Nov 2026 11:53:30 +0000 [thread overview]
Message-ID: <179586681082.3135.2680031921481682331@kernel.org> (raw)
In-Reply-To: <20261127-ktls-close-c-v1-1-1470bb718a8d@certik.com>
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
next prev parent reply other threads:[~2026-11-28 11:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:08 [PATCH net] tls: use non-blocking sends in tx_work_handler Dickson Wu via B4 Relay
2026-11-28 11:53 ` netdev-bot+sashiko [this message]
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=179586681082.3135.2680031921481682331@kernel.org \
--to=netdev-bot+sashiko@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