Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: cel@kernel.org
Cc: john.fastabend@gmail.com, kuba@kernel.org, sd@queasysnail.net,
	davem@davemloft.net, pabeni@redhat.com, horms@kernel.org,
	davejwatson@fb.com, shuah@kernel.org, qingfang.deng@linux.dev,
	edumazet@kernel.org, netdev@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next v4 6/9] tls: Return copied data ahead of a run of empty records
Date: Tue, 13 Oct 2026 16:11:41 +0000	[thread overview]
Message-ID: <179190790187.434549.10720335019823028544@kernel.org> (raw)
In-Reply-To: <20261012-tls-follow-on-v4-6-8cea429565da@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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).

- [Medium] This patch fixes only the case where the reader has already
  met the low-water mark.

--

tls: Return copied data ahead of a run of empty records

This commit makes tls_sw_recvmsg() leave its receive loop at a
zero-length application_data record once the bytes copied so far meet the
receive low-water mark. Before this change, a peer that sent a stream of
empty records after data could keep the reader in the loop. The reader
held the copied data until the stream stopped or a signal was pending.

Link: https://lore.kernel.org/r/179124254665.434549.12245680127262431659@kernel.org

> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> index b7790b17f79c6..15a3a6d3f6380 100644
> --- a/net/tls/tls_sw.c
> +++ b/net/tls/tls_sw.c
> @@ -1939,6 +1939,12 @@ int tls_sw_recvmsg(struct sock *sk,
>  
>  			/* An empty record still marks a boundary. */
>  			msg->msg_flags |= MSG_EOR;
> +
> +			/* Return data already copied instead of holding it
> +			 * through a run of empty records.
> +			 */
> +			if (decrypted + copied >= target)
> +				break;
>  			continue;
>  		}

[Severity: Medium]

Can a non-blocking reader still be held here when it has copied some data
but is still below target?

target is computed without regard to MSG_DONTWAIT:

	target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);

So with MSG_DONTWAIT|MSG_WAITALL, or with MSG_DONTWAIT and SO_RCVLOWAT set
above the bytes copied so far, a reader can end up with
0 < decrypted + copied < target.

In that state the new check is false, so the empty record goes to
continue. Empty records advance neither len nor decrypted, so the loop
condition stays true:

	while (len && (decrypted + copied < target || tls_strp_msg_ready(ctx))) {

For a non-blocking reader, the usual way out with its partial data is the
-EAGAIN return in tls_rx_rec_wait():

	while (!tls_strp_msg_ready(ctx)) {
		...
		if (!timeo)
			return -EAGAIN;
		...
	}
	...
	return 1;

That check only runs when no record is ready. If the peer has an empty
record ready each time, tls_rx_rec_wait() returns 1. The empty record is
then consumed and the loop runs again. Without the empty records, the
same reader would get -EAGAIN right away, and recv_end would return the
copied bytes.

The reader keeps the copied data until the run of empty records stops or
the nodata && signal_pending() check fires. That is the same delay this
patch fixes for readers that have met target.

The commit message says:

    A reader that has copied nothing still reads empty records
    for as long as they arrive.

This reads as if readers that have copied nothing are the only case left.
The subject line also does not hold for the readers described above.

Later patches in this series do not appear to touch net/, so this case
would still be present after the series.

Would it make sense to also break for a non-blocking read that has
already copied some data? For example:

	if (decrypted + copied >= target ||
	    ((flags & MSG_DONTWAIT) && decrypted + copied))
		break;

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261012-tls-follow-on-v4-0-8cea429565da%40kernel.org

  reply	other threads:[~2026-10-13 16:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 15:29 [PATCH net-next v4 0/9] net/tls: Receive-path fixes for zero-length data records Chuck Lever
2026-10-12 15:29 ` [PATCH net-next v4 1/9] tls: Bound consecutive no-data records in tls_sw_read_sock() Chuck Lever
2026-10-13 16:11   ` netdev-bot+sashiko
2026-10-12 15:29 ` [PATCH net-next v4 2/9] tls: Check for a pending signal after an empty record Chuck Lever
2026-10-13 16:11   ` netdev-bot+sashiko
2026-10-12 15:29 ` [PATCH net-next v4 3/9] tls: Honor O_NONBLOCK in tls_sw_splice_read() Chuck Lever
2026-10-13 16:11   ` netdev-bot+sashiko
2026-10-12 15:29 ` [PATCH net-next v4 4/9] tls: Consume empty data records " Chuck Lever
2026-10-13 16:11   ` netdev-bot+sashiko
2026-10-12 15:29 ` [PATCH net-next v4 5/9] tls: Consume empty data records in tls_sw_recvmsg() Chuck Lever
2026-10-12 15:29 ` [PATCH net-next v4 6/9] tls: Return copied data ahead of a run of empty records Chuck Lever
2026-10-13 16:11   ` netdev-bot+sashiko [this message]
2026-10-12 15:29 ` [PATCH net-next v4 7/9] selftests: tls: Skip the zero_len tests when TLS is unavailable Chuck Lever
2026-10-12 15:29 ` [PATCH net-next v4 8/9] selftests: tls: Extend coverage for zero-length records Chuck Lever
2026-10-13 16:11   ` netdev-bot+sashiko
2026-10-12 15:29 ` [PATCH net-next v4 9/9] selftests: tls: Cover splice on a nonblocking socket Chuck Lever

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=179190790187.434549.10720335019823028544@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=cel@kernel.org \
    --cc=davejwatson@fb.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=qingfang.deng@linux.dev \
    --cc=sd@queasysnail.net \
    --cc=shuah@kernel.org \
    /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