🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27163

Re: [PATCH net 05/10] tls: reject unreadable skbs in tls_strp

#27163
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 22:07
232 lines
16576 bytes
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
Technical Details
Message-ID: <179642207345.3146.9826928279954710925@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377689-linux-kernel-netdev=dewy.ru
References: <ca7838ea6e679590625fe463804e046b9bbe0244.1796329894.git.tavip@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377689-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 05/10] tls: reject unreadable skbs in tls_strp
Date: Fri, 04 Dec 2026 22:07:53 +0000
Organization: Usenet Network
Message-ID: <179642207345.3146.9826928279954710925@kernel.org>
References: <ca7838ea6e679590625fe463804e046b9bbe0244.1796329894.git.tavip@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2884016"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:3a1gL0sdQTMEIEnoVrsj0x74LsY= sha256:HVe+U/bwh86vlo8UiZ8cmf49fAOHc+qb7pKYCW7gfPA=
	sha1:XJX3k+zv8ypH/27fuH+ffNGIPAs= sha256:Ro7+mGaQioIotXxK1dNV0CTPQVjBSMaJTKc62MGjOno=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 1F616117D0E; Sat,  5 Dec 2026 01:08:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ExuSXyKZiSjU;
	Sat,  5 Dec 2026 01:08:36 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377689-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id CDE0F117D0B; Sat,  5 Dec 2026 01:08:27 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 70A1A3EB42; Fri,  4 Dec 2026 22:07:56 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796422076;
	b=bR9sx1Ti/Yzw2oEmJOjYSvdTDmInFGZUq7BGGaNbcBrjQvRCaectkQ0CtJDONbVFqFK5
	 k/2W4Odl4Zu4WeAuFsg7zHALb98lbPkMc6eVwT9sbzlxaL4bKl3GWA15bs+KZSwlauseC
	 i8KBHZiSkWtM8FUavwkjH8HqawL27tOvKaLSgPXZnbXcls5gBLz4/42VkJf8v9w160Kvv
	 nO9oXezxdaJonJhsse21hjOsp0Qpdcfza8faDbtkVZpl04k9dvpIEzcW8BWG9qXksg8PT
	 gkZVm9MtFR6L+vIkTALtgdHRiZQYkpxbJm1hEPdbmBfzskm/Lh/m/8e7+nprs9SRVdg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796422076;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=yLfuRrZbpLA9mg/NT/CGUV6g0q7+MYZINIUbcGfSVDU=;
	b=HDi2UAUOwJVZ6v3dadUSvdlPGX6jvXvu2QIvorGh+Wk8Zrw0cYeyhAs4DZusc+mRXb5J
	 0YHXVYmPvtsPdk54TyWCYADb9laNmOxJuvfgSxBCsmx/RW3SzfUnWDIBUe7hzwOhsQQai
	 hF6IDwE0+NaVrYbWOKqyp/P61R9oyB8Mfhj8uB3vilDkljHfY2jmWBSlQuu09Zoroi/uf
	 4TyqfGijIx1rpDFYWjBqztx88iJQnQDs+vIg0YAcQY9saLspT4rZcONAsXdyJshGoaKV7
	 +MhiGkipv5yC3M1SGPfOD703jTGqsClTXE5EJlf9OGBoi1N4MWNnb1/aDUaF4gzaZUQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=E62ZoV8O;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4422F606A680;
	Fri,  4 Dec 2026 22:07:56 +0000 (UTC)
X-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=E62ZoV8O
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796422075;
	b=jP1y4SSozJKhpF+25zMdB3eooOFARINCfssp1QqtcRGyuu6zVpxlXf66wdBb+H0DGFcL
	 NXPFaVLbeM1/PJPuFESoj6J0a0V+qAmpxe6q/4IoE2IPLivn80HnkvlaqVs+Oogq9GhX+
	 AaBwjjPMknNgvZYhN9uHe5Wx0NhgQ6mfgQcL4p5rl22t62WK8MAiVebW/yc5ZmxH7DUq3
	 swnKz5v5ELV8cG2BJg2um6tcGROZFGdH7sq4pZAjIx6rR3pBBgZ1259pQhnGMUJRr3BuW
	 9zcWKOj6XKiauTfPj/cRUuYsJtSprqCrNa+t4nKvq99RLLdswcYxpNH+aRKfppTLA8Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796422075;
	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=yLfuRrZbpLA9mg/NT/CGUV6g0q7+MYZINIUbcGfSVDU=;
	b=Q2ar9cQ/BKl3IRFMdwAW7vmwl9Y25j5h5aIxJN5R6PAjWTbaz1vtosSEXzBGLD/o970z
	 KpOXC1CoF5cDb9oGnlMfBlaC+Pa2oUg5gmntW3ClrCAT33wBzd0nfZ6tFlUDjJuymDFzu
	 ObM7sVUmdpffgpIvOScD6LYjiXuygyXY81Nd/rifRWt78XUGa49Bd8zKKjLa7r5tESFqK
	 Oj2ssrTsQKdfEaRehhRoyfYZBjgvoDp8oNvgoxGAEF/Rf5rx41ka+4xtGbsYxoqOn/Jwd
	 dbrg5yiDMYS5jchl5R/Kz7cMgiH5dKF5eEeT/4hcyF3pYx/Q3mcL2p3ImbmvBNhy6QQ==
X-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=E62ZoV8O;
	arc=none smtp.remote-ip=100.103.45.18
X-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 65523606A339;
	Fri,  4 Dec 2026 22:07:55 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8A771F0093B;
	Fri,  4 Dec 2026 22:07:53 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796422075;
	bh=yLfuRrZbpLA9mg/NT/CGUV6g0q7+MYZINIUbcGfSVDU=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=E62ZoV8OaZRC4yoznKlPrzfW26LKynZuFtsiOqUHyyNIXhFjR4S0NJHVWx8IyZ8OE
	 vVnJEmQ740I8pXW/x5IzLavUTVKmm3kUMh5tfStFpKLUKdm0NaEWvC71+/Gn0eN/tr
	 NzkuGO26PvigejgQl++avtZYLotXAmwq+T+KCovNpF8a7KR/GHSVjSsb2Wgi5oDKYe
	 lxZIbX64RZJXxEhaPi6jzwF8VAH1zaZYoSWte0PgdDbGlcEufpVQWyDFyNDscNppJ6
	 Xbycal3b8VvT4usVRQ682x7qvDft4UwE1ee28HuCkmE5/8N8bOgPTeGadhkE43ivLl
	 B0ACJYiL68GWQ==
X-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
X-In-Reply-To: <ca7838ea6e679590625fe463804e046b9bbe0244.1796329894.git.tavip@google.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list