All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jakub Kicinski" <kuba@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net 2/7] selftests: tls: add test for data loss on small pipe
Date: Thu, 30 Apr 2026 22:31:29 +0000	[thread overview]
Message-ID: <20260430223130.52A0EC2BCB3@smtp.kernel.org> (raw)
In-Reply-To: <20260429222944.2139041-3-kuba@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Test logic flaw on architectures with large page sizes defeats the purpose of the test.
- [Medium] Unhandled failure paths and use of EXPECT_EQ cause uninitialized memory reads and test hangs.
--

commit 52c9391392d3ea9a9876d20000032a6a0985383b
Author: Jakub Kicinski <kuba@kernel.org>

selftests: tls: add test for data loss on small pipe

This commit adds a new selftest splice_to_pipe_small to the TLS test suite.
The test verifies that data is not lost when using splice to move data from
a TLS socket into a small pipe that requires multiple iterations to drain.

> diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c
> --- a/tools/testing/selftests/net/tls.c
> +++ b/tools/testing/selftests/net/tls.c

[ ... ]

> +TEST_F(tls, splice_to_pipe_small)
> +{
> +	int send_len = TLS_PAYLOAD_MAX_LEN;
> +	char mem_send[TLS_PAYLOAD_MAX_LEN];
> +	char mem_recv[TLS_PAYLOAD_MAX_LEN];
> +	size_t total = 0;
> +	int p[2];
> +
> +	memrnd(mem_send, sizeof(mem_send));
> +
> +	ASSERT_GE(pipe(p), 0);
> +
> +	/* Shrink pipe to 1 page (typically 4096 bytes) to force multiple
> +	 * splice iterations for a 16384-byte TLS record.
> +	 */
> +	EXPECT_GE(fcntl(p[1], F_SETPIPE_SZ, 4096), 4096);

Does this test behave as expected on architectures with large page sizes?

The kernel rounds pipe capacities up to the system page size. On architectures
with a 64KB page size (such as ARM64 or PowerPC), the pipe size will be set
to 64KB instead of 4096 bytes.

Since the 16KB payload easily fits within a 64KB pipe, the splice call would
transfer the entire payload in a single iteration, bypassing the intended
multiple-iteration behavior.

> +	EXPECT_EQ(send(self->fd, mem_send, send_len, 0), send_len);

Will this test hang on a short send?

Unlike ASSERT_EQ, EXPECT_EQ allows execution to continue on failure. If send()
transmits a partial payload, total will not advance enough relative to the
data on the socket. The subsequent splice() could then block indefinitely
waiting for data that will never arrive.

> +	while (total < (size_t)send_len) {
> +		ssize_t spliced, drained;
> +
> +		spliced = splice(self->cfd, NULL, p[1], NULL,
> +				 send_len - total, 0);
> +		EXPECT_GT(spliced, 0);
> +		if (spliced <= 0)
> +			break;
> +
> +		drained = read(p[0], mem_recv + total, spliced);
> +		EXPECT_EQ(drained, spliced);
> +		if (drained <= 0)
> +			break;
> +
> +		total += drained;
> +	}
> +
> +	EXPECT_EQ(total, (size_t)send_len);
> +	EXPECT_EQ(memcmp(mem_send, mem_recv, send_len), 0);

Could this read uninitialized memory?

If splice() or read() return <= 0, the loop breaks early with total < send_len.

Because mem_recv is uninitialized stack memory, the memcmp() call will
read past mem_recv + total into uninitialized memory, triggering undefined
behavior and potential memory sanitizer failures.

> +
> +	close(p[0]);
> +	close(p[1]);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260429222944.2139041-1-kuba@kernel.org?part=2

  reply	other threads:[~2026-04-30 22:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 22:29 [PATCH net 0/7] net: tls: fix a few random bugs Jakub Kicinski
2026-04-29 22:29 ` [PATCH net 1/7] net: tls: fix silent data drop under pipe back-pressure Jakub Kicinski
2026-04-29 22:29 ` [PATCH net 2/7] selftests: tls: add test for data loss on small pipe Jakub Kicinski
2026-04-30 22:31   ` sashiko-bot [this message]
2026-04-29 22:29 ` [PATCH net 3/7] net: tls: fix page pin leak on sendpage_ok() failure Jakub Kicinski
2026-04-30 22:31   ` sashiko-bot
2026-04-29 22:29 ` [PATCH net 4/7] net: tls: fix off-by-one in sg_chain entry count for wrapped sk_msg ring Jakub Kicinski
2026-04-30 22:31   ` sashiko-bot
2026-05-01 16:40   ` Sabrina Dubroca
2026-05-03  1:26     ` Jakub Kicinski
2026-04-29 22:29 ` [PATCH net 5/7] selftests: bpf: cover wrapped sk_msg ring chaining in ktls TX path Jakub Kicinski
2026-04-30 17:58   ` Jiayuan Chen
2026-04-30 22:31   ` sashiko-bot
2026-04-29 22:29 ` [PATCH net 6/7] net: tls: fix use-after-free in tls_sw_sendmsg_locked after bpf verdict Jakub Kicinski
2026-04-30 17:50   ` Jiayuan Chen
2026-04-30 22:31   ` sashiko-bot
2026-04-29 22:29 ` [PATCH net 7/7] selftests: bpf: cover tls_sw_sendmsg UAF after bpf_exec_tx_verdict split Jakub Kicinski
2026-04-30 17:55   ` Jiayuan Chen
2026-05-03  2:20 ` [PATCH net 0/7] net: tls: fix a few random bugs patchwork-bot+netdevbpf

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=20260430223130.52A0EC2BCB3@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=sashiko@lists.linux.dev \
    /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.