All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Octavian Purdila" <tavip@google.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net 05/10] tls: reject unreadable skbs in tls_strp
Date: Fri, 04 Dec 2026 21:09:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-250671@kernel.org> (raw)
In-Reply-To: <ca7838ea6e679590625fe463804e046b9bbe0244.1796329894.git.tavip@google.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] tls: tls_strp_check_queue_ok() enters copy mode on unreadable
  skbs
- [Medium] tls: tls_strp_skb_copy() returns NULL on -EFAULT, misreported
  as -ENOMEM
- [Medium] tls: tls_strp_msg_load() skips queue validation on
  force_refresh
- [Medium] tls: tls_strp_copyin_frag() ignores skb_copy_bits() errors on
  frag_list
--

commit 2c01b4221727542d5938c961d8c4dd858cff2e10
Author: Octavian Purdila <tavip@google.com>

tls: reject unreadable skbs in tls_strp

This commit checks skb_frags_readable() in tls_strp_skb_copy(),
tls_strp_copyin(), and tls_strp_check_queue_ok(), and aborts stream
parsing with -EFAULT when unreadable fragments or skb_copy_bits()
failures are encountered.

> 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;
> +		}
>  		offset += skb_frag_size(frag);
>  	}

[Severity: Medium]
Does returning NULL after tls_strp_abort_strp() cause callers to
misreport -EFAULT as -ENOMEM?

All callers of tls_strp_skb_copy() (tls_strp_copyin_skb(),
tls_strp_msg_cow(), and tls_decrypt_device() via tls_strp_msg_detach())
treat a NULL return as an allocation failure and return -ENOMEM.  On the
hardware offload path, tls_rx_one_record() then calls
tls_err_abort(sk, -EBADMSG), overwriting the EFAULT just written to
sk->sk_err, and returns -ENOMEM to userspace.

On the copyin path, tls_strp_check_rcv() sees -ENOMEM and queues
strp->work on tls_strp_wq even though strp->stopped is already set.
Returning ERR_PTR(-EFAULT) vs ERR_PTR(-ENOMEM) from tls_strp_skb_copy()
and tls_strp_msg_make_copy() would preserve -EFAULT and avoid clobbering
sk->sk_err or scheduling dead work.

> @@ -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;
> +	}
> +
>  	skb = strp->anchor;
>  	if (!skb->len)
>  		skb_copy_decrypted(skb, in_skb);

[Severity: Medium]
Can an skb with a readable head and an unreadable frag_list member still
bypass this check and hit unchecked skb_copy_bits() calls in
tls_strp_copyin_frag()?

skb_gro_receive() checks p->pp_recycle != skb->pp_recycle but not
p->unreadable != skb->unreadable, so a readable pp_recycle head skb can
chain an unreadable devmem skb onto frag_list (for example via
gro_cells_receive() or a driver sharing one NAPI across RX queues).

When that happens, tls_strp_copyin() passes the head skb check and enters
tls_strp_copyin_frag(), where both WARN_ON_ONCE(skb_copy_bits(...)) calls
ignore -EFAULT, trigger a kernel warning, skip tls_strp_abort_strp(), and
advance skb->len, skb->data_len, and frag size over uninitialized pages
from alloc_page().  Checking the return value of both skb_copy_bits()
calls in tls_strp_copyin_frag() and aborting with
tls_strp_abort_strp(strp, -EFAULT) would match tls_strp_skb_copy().

> @@ -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;
> +
>  		if (TCP_SKB_CB(skb)->seq != seq)
>  			return false;
>  		if (skb_cmp_decrypted(first, skb))

[Severity: Medium]
Should tls_strp_check_queue_ok() abort directly on unreadable skbs
instead of returning false and entering copy mode?

Both callers in tls_strp_read_sock() treat a false return as a
recoverable queue anomaly and call tls_strp_read_copy(strp, false).  That
allocates up to 20 KiB of pages (under GFP_ATOMIC in softirq) and
discards the -EFAULT from tls_strp_read_copyin(), leaving those pages
pinned on strp->anchor until socket close.

It also defers to tls_strp_wq on allocation failure instead of aborting,
and consumes and ACKs any preceding readable skbs in the same record
before hitting the unreadable skb.  Aborting with -EFAULT directly and
returning an error status to tls_strp_read_sock() would avoid the
copy-mode fallback.

[Severity: Medium]
What about tls_strp_msg_load() when force_refresh is true?

tls_strp_msg_load() is the other caller of
tls_strp_load_anchor_with_queue(), and it reloads strp->anchor without
calling tls_strp_check_queue_ok().  If a validated readable record is
drained from sk_receive_queue (for example via
getsockopt(IPPROTO_TCP, TCP_ZEROCOPY_RECEIVE) forwarded by
tls_getsockopt()) while an unreadable devmem skb of at least
strp->stm.full_len bytes remains queued behind it, tls_strp_msg_load()
anchors the unreadable skb and hands it to tls_rx_one_record().

tls_rx_one_record() then allocates decrypt buffers, fails, and calls
tls_err_abort(sk, -EBADMSG) without stopping strp or clearing
strp->msg_ready, so SO_ERROR reports EBADMSG, tls_sk_poll() keeps
reporting EPOLLIN | EPOLLRDNORM, and later reads keep re-anchoring and
failing on the same skb.  Re-checking
tls_strp_check_queue_ok(strp, strp->stm.full_len) in tls_strp_msg_load()
and clearing strp->msg_ready on failure would route it back through
tls_strp_read_sock() to abort cleanly with -EFAULT.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796329894.git.tavip@google.com?part=5

  parent reply	other threads:[~2026-12-04 21:09 UTC|newest]

Thread overview: 42+ 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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot [this message]
2026-12-04 22:07   ` netdev-bot+sashiko
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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
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=sashiko-outbox-250671@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tavip@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.