Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: tavip@google.com
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
	horms@kernel.org, andrew+netdev@lunn.ch, ncardwell@google.com,
	kuniyu@google.com, dsahern@kernel.org, idosch@nvidia.com,
	john.fastabend@gmail.com, jakub@cloudflare.com,
	jiayuan.chen@linux.dev, sd@queasysnail.net, shuah@kernel.org,
	almasrymina@google.com, sdf@fomichev.me, kaiyuanz@google.com,
	ilias.apalodimas@linaro.org, hawk@kernel.org,
	mcroce@microsoft.com, herbert@gondor.apana.org.au,
	ecree.xilinx@gmail.com, bpf@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net 05/10] tls: reject unreadable skbs in tls_strp
Date: Fri, 04 Dec 2026 22:07:53 +0000	[thread overview]
Message-ID: <179642207345.3146.9826928279954710925@kernel.org> (raw)
In-Reply-To: <ca7838ea6e679590625fe463804e046b9bbe0244.1796329894.git.tavip@google.com>

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

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

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] The patch only closes part of the bug class it describes.
- [Low] After this patch, a NULL return from tls_strp_skb_copy() can mean
  two things.
- [Low] tls_strp_check_queue_ok() now also rejects unreadable skbs, but
  its comment still says only "Make sure there's no duplicate data in…

--

tls: reject unreadable skbs in tls_strp

This patch makes tls_strp reject skbs with unreadable (net_iov) frags. It
adds readability checks to tls_strp_check_queue_ok(), tls_strp_copyin()
and tls_strp_skb_copy(), and aborts the parser with -EFAULT when it finds
unreadable data. It also changes the WARN_ON_ONCE() around skb_copy_bits()
in tls_strp_skb_copy() into a checked failure path.

> diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c
> index 53d3256d0114a..a9e49384a1692 100644
> --- a/net/tls/tls_strp.c
> +++ b/net/tls/tls_strp.c
> @@ -45,6 +45,11 @@ tls_strp_skb_copy(struct tls_strparser *strp, struct sk_buff *in_skb,
>  	struct sk_buff *skb;
>  	int i, err;
>  
> +	if (unlikely(!skb_frags_readable(in_skb))) {
> +		tls_strp_abort_strp(strp, -EFAULT);
> +		return NULL;
> +	}
> +
>  	skb = alloc_skb_with_frags(0, len, TLS_PAGE_ORDER,
>  				   &err, strp->sk->sk_allocation);
>  	if (!skb)
> @@ -53,9 +58,13 @@ tls_strp_skb_copy(struct tls_strparser *strp, struct sk_buff *in_skb,
>  	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
>  		skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
>  
> -		WARN_ON_ONCE(skb_copy_bits(in_skb, offset,
> +		if (unlikely(skb_copy_bits(in_skb, offset,
>  					   skb_frag_address(frag),
> -					   skb_frag_size(frag)));
> +					   skb_frag_size(frag)))) {
> +			kfree_skb(skb);
> +			tls_strp_abort_strp(strp, -EFAULT);
> +			return NULL;
> +		}

[Severity: Low]
With this change, a NULL return from tls_strp_skb_copy() can mean either
of two things. It can be a transient alloc_skb_with_frags() failure. It
can also be a permanent fault, where tls_strp_abort_strp(strp, -EFAULT)
has already set strp->stopped and sk_err.

The callers still turn every NULL into -ENOMEM:

tls_strp_copyin_skb():
	nskb = tls_strp_skb_copy(strp, in_skb, offset, chunk);
	if (!nskb)
		return -ENOMEM;

tls_strp_msg_cow():
	skb = tls_strp_msg_make_copy(strp);
	if (!skb)
		return -ENOMEM;

tls_device_reencrypt() passes the tls_strp_msg_cow() error up. Also,
tls_rx_one_record() in tls_sw.c returns -ENOMEM when
tls_strp_msg_detach() returns NULL. Could recvmsg then report ENOMEM while
sk_err on the lower socket holds EFAULT?

In copy mode, tls_strp_check_rcv() also treats this as memory pressure:

	if (tls_strp_read_sock(strp) == -ENOMEM)
		queue_work(tls_strp_wq, &strp->work);

The queued work only exits because strp->stopped happens to be set.

In practice, the new !skb_frags_readable(in_skb) check here doesn't seem
reachable:

- From tls_strp_copyin_skb(), tls_strp_copyin() checks first.
- From tls_strp_msg_make_copy(), the anchor's unreadable bit is copied
  from first, which tls_strp_check_queue_ok() has already validated.

That leaves only the skb_copy_bits() failure branch, i.e. the nested
frag_list case described below.

Would returning ERR_PTR(-EFAULT), or passing the error back through an int
pointer, better match the commit message's "abort stream parsing cleanly
with -EFAULT"?

>  		offset += skb_frag_size(frag);
>  	}
>  

[ ... ]

> @@ -349,6 +358,12 @@ static int tls_strp_copyin(read_descriptor_t *desc, struct sk_buff *in_skb,
>  	if (strp->msg_ready)
>  		return 0;
>  
> +	if (unlikely(!skb_frags_readable(in_skb))) {
> +		tls_strp_abort_strp(strp, -EFAULT);
> +		desc->error = -EFAULT;
> +		return 0;
> +	}
> +

[Severity: Medium]
This only checks the unreadable bit on the head in_skb. Can a readable
head skb still carry unreadable skbs on its own frag_list?

skb_copy_bits() recurses into frag_list members and returns -EFAULT for
any member where !skb_frags_readable() is true. tls_strp_copyin_frag()
still ignores that return value, both in the header copy and in the "Load
up more data" loop:

tls_strp_copyin_frag() {
    ...
		WARN_ON_ONCE(skb_copy_bits(in_skb, offset,
					   skb_frag_address(frag) +
					   skb_frag_size(frag),
					   chunk));

		skb->len += chunk;
		skb->data_len += chunk;
		skb_frag_size_add(frag, chunk);
    ...
}

If that happens, isn't this still the case the commit message describes:
"triggers warnings and advances skb lengths over uninitialized memory when
skb_copy_bits() fails"?

The pages come from alloc_page() in tls_strp_read_copy() and are not
zeroed. tls_rx_msg_size() would parse those bytes, and they would then be
passed to decryption. For a record with decrypted set and mixed_decrypted
== 0, which goes through tls_strp_copyin_frag(), the bytes would be
treated as plaintext.

The path would be:

tls_strp_read_copy()
  tls_strp_read_copyin()
    tcp_read_sock()
      tls_strp_copyin()            <- head check passes
        tls_strp_copyin_frag()
          skb_copy_bits()          <- -EFAULT on a frag_list child, ignored

tls_strp_check_queue_ok() has the same gap. It checks each top-level queue
skb, but not the skbs on their frag_list.

As far as I can tell, the merge path in skb_gro_receive() and
tcp_gro_receive() doesn't compare unreadable between p and skb before
chaining onto frag_list. It checks pp_recycle, zcopy and decrypted, but not
readability. The series adds a mixed-readability rejection for IP defrag,
but I couldn't find an equivalent for GRO.

I also couldn't find a concrete in-tree producer of a readable head with an
unreadable child, since devmem RX needs tcp-data-split with hds-thresh=0.
So this may be theoretical.

This patch already converts the same pattern in tls_strp_skb_copy().
Should the two skb_copy_bits() calls in tls_strp_copyin_frag() also abort
with -EFAULT and return an error, without advancing skb->len,
skb->data_len and the frag size?

[ ... ]

> @@ -438,6 +453,8 @@ static bool tls_strp_check_queue_ok(struct tls_strparser *strp,
>  	u32 seq;
>  
>  	first = skb_shinfo(strp->anchor)->frag_list;
> +	if (unlikely(!skb_frags_readable(first)))
> +		return false;
>  	skb = first;
>  	seq = TCP_SKB_CB(first)->seq;
>  
> @@ -449,6 +466,9 @@ static bool tls_strp_check_queue_ok(struct tls_strparser *strp,
>  		remaining -= skb->len;
>  		skb = skb->next;
>  
> +		if (unlikely(!skb_frags_readable(skb)))
> +			return false;
> +

[Severity: Low]
This isn't a bug, but the comment in tls_strp_check_queue_ok() still only
mentions the old checks:

	/* Make sure there's no duplicate data in the queue,
	 * and the decrypted status matches.
	 */

Should it also mention the readability check?

A false return now has two meanings. It can mean the zero-copy anchor isn't
usable but copy mode will work, as before. It can also mean the data is
unreadable and copy mode can't help. Both callers in tls_strp_read_sock()
still handle it the same way:

	if (!tls_strp_check_queue_ok(strp, strp->stm.full_len))
		return tls_strp_read_copy(strp, false);

With qshort == false, tls_strp_read_copy() allocates up to
TLS_MAX_PAYLOAD_SIZE + PAGE_SIZE worth of pages and switches to copy mode.
It then calls tls_strp_read_copyin() and ignores the return value.

Only after that does tls_strp_copyin() abort on the unreadable skb, and the
-EFAULT is only visible through strp->stopped and sk_err. The pages are
freed later on tls_strp_done(), so nothing leaks.

Would it be cleaner to abort directly from tls_strp_read_sock() in the
unreadable case, rather than setting up copy mode first?

>  		if (TCP_SKB_CB(skb)->seq != seq)
>  			return false;
>  		if (skb_cmp_decrypted(first, skb))

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1796329894.git.tavip%40google.com

  parent reply	other threads:[~2026-12-04 22:07 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 21:09 [PATCH net 00/10] net: fix unreadable net_iov skb handling across networking paths Octavian Purdila
2026-12-03 21:09 ` [PATCH net 01/10] net: gro: free skb on napi_frags_skb() header pull failure Octavian Purdila
2026-12-04 18:31   ` Mina Almasry
2026-12-03 21:09 ` [PATCH net 02/10] net: gro: reset unreadable and pp_recycle in napi_reuse_skb Octavian Purdila
2026-12-04 18:32   ` Mina Almasry
2026-12-04 21:07     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 03/10] inet: frag: reject fragments with mixed readability in reassembly Octavian Purdila
2026-12-04 18:38   ` Mina Almasry
2026-12-04 21:09     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 04/10] net: skbuff, skmsg, strparser: reject unreadable frags Octavian Purdila
2026-12-04 18:58   ` Mina Almasry
2026-12-04 21:25     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 05/10] tls: reject unreadable skbs in tls_strp Octavian Purdila
2026-12-04 18:44   ` Mina Almasry
2026-12-04 22:24     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko [this message]
2026-12-03 21:09 ` [PATCH net 06/10] tcp: reject unreadable skbs on TCP-MD5 and TCP-AO Octavian Purdila
2026-12-04 18:46   ` Mina Almasry
2026-12-04 22:26     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 07/10] net: kunit: test unreadable net_iov napi_gro_frags Octavian Purdila
2026-12-04 18:47   ` Mina Almasry
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 08/10] net: kunit: test unreadable net_iov defrag and skb helpers Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 09/10] selftests: drv-net: devmem: test unreadable kTLS RX Octavian Purdila
2026-12-04 18:48   ` Mina Almasry
2026-12-04 22:28     ` Octavian Purdila
2026-12-04 22:08   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 10/10] selftests: drv-net: devmem: test unreadable skbs on TCP-MD5 and TCP-AO Octavian Purdila
2026-12-04 22:08   ` netdev-bot+sashiko

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=179642207345.3146.9826928279954710925@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jakub@cloudflare.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=kaiyuanz@google.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mcroce@microsoft.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=tavip@google.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