mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Charles Pellegrini <c4ffein.work@gmail.com>
To: akpm@linux-foundation.org, egorenar-dev@posteo.net,
	robert.jarzmik@free.fr, t-pratham@ti.com, david@davidgow.net,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 5/5] lib: scatterlist: add zero-nents regression test for sg_split()
Date: Wed, 10 Jun 2026 15:39:35 -0700 (PDT)	[thread overview]
Message-ID: <178113124324.90620.18138438076056571852@gmail.com> (raw)
In-Reply-To: <178113124323.90620.6403136846887207198@gmail.com>

Add sg_split_t8b_trailing_zero_no_input_left: a split_sizes[] array whose
first split consumes the entire input, so the trailing zero-size split
receives no input entry (nents == 0). Without the guard in the previous
patch, the last-entry fixup in sg_split_phys()/sg_split_mapped() writes
through a ZERO_SIZE_PTR; with it, the empty split is skipped.

Run under KASAN to catch a regression as a clean out-of-bounds report,
e.g.:

    tools/testing/kunit/kunit.py run sg_split \
        --arch=x86_64 --kconfig_add=CONFIG_KASAN=y

Without KASAN the write lands at a wild address and faults, so the case
still fails -- KASAN just turns it into a precise report rather than an
oops.

Assisted-by: Claude:claude-opus-4-8 hegel-c
Signed-off-by: Charles Pellegrini <c4ffein.work@gmail.com>
---
 lib/tests/sg_split_kunit.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/tests/sg_split_kunit.c b/lib/tests/sg_split_kunit.c
index 82eef313944d..6d4ba0f2d5bd 100644
--- a/lib/tests/sg_split_kunit.c
+++ b/lib/tests/sg_split_kunit.c
@@ -311,6 +311,20 @@ static void sg_split_t8_sizes_trailing_zero(struct kunit *test)
 	sg_split_run(test, in, 2, 0, sizes, 2);
 }
 
+static void sg_split_t8b_trailing_zero_no_input_left(struct kunit *test)
+{
+	/* First split consumes the entire input; the trailing zero-size split
+	 * gets no input entry (nents == 0).  sg_split_phys()/sg_split_mapped()
+	 * must not write out_sg[-1] for that empty split (out_sg would be
+	 * ZERO_SIZE_PTR).  Distinct from T8, where a trailing input entry
+	 * leaves the zero split with nents > 0.
+	 */
+	const struct sg_split_in_spec in[] = { { 0, 0, 10 } };
+	const size_t sizes[] = { 10, 0 };
+
+	sg_split_run(test, in, 1, 0, sizes, 2);
+}
+
 /* ========================================================================
  * Group D — boundary-position matrix (3 x 10-byte entries).
  */
@@ -487,6 +501,7 @@ static struct kunit_case sg_split_test_cases[] = {
 	KUNIT_CASE(sg_split_t6_dthev2_aead_shape),
 	KUNIT_CASE(sg_split_t7_skip_plus_partial_midentry),
 	KUNIT_CASE(sg_split_t8_sizes_trailing_zero),
+	KUNIT_CASE(sg_split_t8b_trailing_zero_no_input_left),
 	KUNIT_CASE(sg_split_t9_mid_first_two_trailing),
 	KUNIT_CASE(sg_split_t10_edge_first_two_trailing),
 	KUNIT_CASE(sg_split_t11_mid_middle_one_trailing),
-- 
2.47.3


  parent reply	other threads:[~2026-06-10 22:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-31 23:42 [PATCH 0/2] lib: scatterlist: fix sg_split() partial-coverage geometry + add KUnit tests Charles Pellegrini
2026-05-31 23:42 ` [PATCH 1/2] lib: scatterlist: fix sg_calculate_split() nb_splits overshoot on partial coverage Charles Pellegrini
2026-05-31 23:42 ` [PATCH 2/2] lib: scatterlist: add KUnit tests for sg_split() Charles Pellegrini
2026-06-02  0:55 ` [PATCH 0/2] lib: scatterlist: fix sg_split() partial-coverage geometry + add KUnit tests Andrew Morton
2026-06-10 22:35   ` c4ffein.work
2026-06-10 22:39 ` [PATCH v2 0/5] lib: scatterlist: fix sg_split() partial-coverage geometry, two latent corruption bugs, and " Charles Pellegrini
2026-06-10 22:39   ` [PATCH v2 1/5] lib: scatterlist: fix sg_calculate_split() nb_splits overshoot on partial coverage Charles Pellegrini
2026-06-10 22:39   ` [PATCH v2 2/5] lib: scatterlist: fix sg_split_phys() ->length clobber on !NEED_SG_DMA_LENGTH Charles Pellegrini
2026-06-10 22:39   ` [PATCH v2 3/5] lib: scatterlist: add KUnit tests for sg_split() Charles Pellegrini
2026-06-10 22:39   ` Charles Pellegrini [this message]
2026-06-10 22:39   ` [PATCH v2 4/5] lib: scatterlist: guard sg_split_phys()/sg_split_mapped() against zero-nents splits Charles Pellegrini

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=178113124324.90620.18138438076056571852@gmail.com \
    --to=c4ffein.work@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@davidgow.net \
    --cc=egorenar-dev@posteo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robert.jarzmik@free.fr \
    --cc=t-pratham@ti.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

all inboxes | Powered by JetHome®