From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 927C6374A1B for ; Wed, 10 Jun 2026 22:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781131180; cv=none; b=EhUkoWzrSOwCZwjRBJdK4xcXouqd0GuqNYnYQA0jWWsauyqukzXn0byDilhvWcFCRU9tyr+oeVokWmkM+WLjhbfIQ9w1g/QyzeSh5pekD4GFfM+8z/H3qqe56080yFv2MgCgCbE3b5gvEaYetjugtgVf/KrwsSSG6y35R7q2pZE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781131180; c=relaxed/simple; bh=wfQc7zTP9hbec6iHNwj81OlpNVrxQzDrhaK96NYNtuA=; h=Date:From:To:Subject:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=D3t+sFoBdYEdyZ7ENinxgpXqpONvShOcSo0f2k5HwiEBgMkyknJdmwGSDRusPTVwfHVodwrFsJm8nssuiVMjB4G4wcD1kfAOkObqB+WL+XTL4jYXXcFQRXHlX/oRY3tKlv8ITddZjqmNwKkP0gScnZE68TWgVSmYeRdkR3KHjUk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Imul2v1z; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Imul2v1z" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-45eeea039ebso3942521f8f.1 for ; Wed, 10 Jun 2026 15:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781131176; x=1781735976; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:references:in-reply-to :message-id:subject:to:from:date:from:to:cc:subject:date:message-id :reply-to; bh=nfZ5trrdIn0NZcdW4QhvmU1Uwsvv4GUyZv/n/Nd65pk=; b=Imul2v1z5RstL3X+I7bsce9osjPdnxSZC5v4RIdDaksFWQ75wX75NdTej6ZREnOXeM v9+JBwvfZz3hDpvGxzBp16DIXLNA4qEF3DM1dOvpGsjtBioMbRjpYmot42ouztAn0iNj tUboJGhK6hRnryn2qTBWjxdz3e/b9xt21OBDOiAiG4xQFFrAci8PRaSKAEFsVPZkNV0H ToDOYoP3pkKZM8QguKcvkVWKXOnWElqi5EhcZA7bfqxQMk23PXwZO5bLiWMNNbc9KH6r eMt2G2+5f2Wl56AmOS2H24qc7kjokbmFqo2vvCyNom67EPtlq9P4gE8N9VbT2dmfxeJx qlbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781131176; x=1781735976; h=mime-version:content-transfer-encoding:references:in-reply-to :message-id:subject:to:from:date:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=nfZ5trrdIn0NZcdW4QhvmU1Uwsvv4GUyZv/n/Nd65pk=; b=HlS1FN8r/wifV04L8NNXf2n15pkHTcRApkia7hOP+3etxYvIQnGn0BN7gSZsirlptD QYdwxSEeL4ewQon5/PHUQ5t1C916DVfIg75Ejhxgv+AaQFm34em+zoiPj5/XtMJzIqF2 DlHqhEALHfX3UqQyE5SVCzbZZzyGMWsgSusBs8WKwi4Z4z2TABee0SpT3/vb+DyRQ8Ai 2etquGMrgP0s60m1dqYnkSkYho+yvw+ZcMbHGEX1TrkYlI2CY/jT09It4o2AA/8ynWyU Svma5T22jl77BeOvtsZeR8nCub9YvEmD7GQAem2E5Ciid8g7eZcb2Ci9RQeOmLCE0BRq zktw== X-Forwarded-Encrypted: i=1; AFNElJ91gpxTPviqOm2e+UjHJ5j91d3jQ3tFNnEs9vaHfinU9orTNUCyaXcYy17UKpjoD+Aj7tjOvn0U80fytNA=@vger.kernel.org X-Gm-Message-State: AOJu0Yxgydij8avxN7jUT1W62MO+8WUIDZvR4Yy8UvYLWE8llIJKKy0f GIKwr2xMxT6j7Q0VRCs8vvQSWUrNwPsFix5FmdEoonP+1H8oCk/+zeIr X-Gm-Gg: Acq92OFucI60GFjpgdAdzs7Xp98M01yFC7lpnGjXWLaKS65pk7lNGFI9B5DBEKkyrfT ZiuCY5GksFV568cvFjVYniwa/hQDo2kqGxCApIKuuT322Y37tGmzs9Y2x2m/qJOoJiuAejVYxbZ kxDDVPbx7KGw7eT5Rp8SsWCy7sMfAglKkIMA5rS4OARa2tsMyGISKhIpzg4VkiWwMw6voZ6B/mF WkN+iN0v5/qN7H/kfDGLShp0CZ8YIVNjeCSnGwp6bhmTAaTuEuIa5yrHcau2scLJF4MBUTxWP8g Kv7s07swL3v3H+9hsEisZRfQUvY2h6mO1DqWZSknB6zjvggyE6hyf+tVycWFxvAZxEPtxicyTmE OAJwsV5FrksM+AulQJxzIKjsBGWZ180S4Cvs7nKDtRBqU45Gugz1N2zvSRJS+Lx+rxly38HM2q+ pEV+U3st5SlDuz96QVc8523AMvzj3RCmYrPE0FGxfKmuswbQ== X-Received: by 2002:a05:6000:2408:b0:460:1301:ded1 with SMTP id ffacd0b85a97d-46067576665mr262395f8f.6.1781131176135; Wed, 10 Jun 2026 15:39:36 -0700 (PDT) Received: from [127.0.0.1] ([141.255.129.1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f360bd6sm81616932f8f.36.2026.06.10.15.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 15:39:35 -0700 (PDT) Date: Wed, 10 Jun 2026 15:39:35 -0700 (PDT) From: Charles Pellegrini 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() Message-ID: <178113124324.90620.18138438076056571852@gmail.com> In-Reply-To: <178113124323.90620.6403136846887207198@gmail.com> References: <178027099087.72481.1976843064458686851@gmail.com> <178113124323.90620.6403136846887207198@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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