From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Sat, 28 Nov 2026 11:53:32 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 464851F00893; Sat, 28 Nov 2026 11:53:31 +0000 (UTC) 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== Subject: Re: [PATCH net] tls: use non-blocking sends in tx_work_handler 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 Date: Sat, 28 Nov 2026 11:53:30 +0000 Message-ID: <179586681082.3135.2680031921481682331@kernel.org> In-Reply-To: <20261127-ktls-close-c-v1-1-1470bb718a8d@certik.com> References: <20261127-ktls-close-c-v1-1-1470bb718a8d@certik.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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