From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 CCB6E286881 for ; Wed, 10 Jun 2026 22:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781130953; cv=none; b=LuSlNYJPCLcDoNbwqR0ejqkxTtDgm3iDmvNvGMOwLYOjM1S43JzxpazcboscLt/FPCB4e/TW3uPvHmdOs/91Bi7iQnaENUdMSMf9WXwDoKir98bA4HWBHSEkT3SMjauUJPDC4RsxuHzMMv9c2KcRsapenVFNyRK1pLQS7n9dCZY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781130953; c=relaxed/simple; bh=yFiaog3VkGMY+Enn0KDA8HMcV0j6CsSsBlVRUqm4pqw=; h=Message-ID:Date:Content-Type:MIME-Version:From:To:Cc:Subject: In-Reply-To:References; b=JLPkJp6SIbR0F8fvI0rEBWfzCsbaOVlKZEfX1uv8RPCfp1Vs7MidEpVf3j8bj+Fa/AD9HKFhZD6mJ+DB49TqgGnFA6S1RfuJNhCqIXyx2H88AcVTFKKRmCHKR7cMoJ3r+5MqzDU6WPGf0QyjhQCn/vRqak2Ridp0E7srGIG6Vmg= 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=TA6jwrsS; arc=none smtp.client-ip=209.85.221.54 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="TA6jwrsS" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-45f3cf907ceso3806587f8f.2 for ; Wed, 10 Jun 2026 15:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781130950; x=1781735750; darn=vger.kernel.org; h=references:in-reply-to:subject:cc:to:from:content-transfer-encoding :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=g/D1irD7H2COSIlqfBmKm6Z8H6xz/cGj28gGU8DwqkI=; b=TA6jwrsScwcyE4V4iECMRW7hcm4kKRZJCcTB76hF5SF4roXv10rD4yQf1a66n17X0B a8g0gHacd2llxgabLVslcezNVtNFjh80NERASg3nckbkV2Wnc0sVtERI9bc7Gy+zzjr0 p4OwFrDnnnS1rXudh/ZxUE7lZsNRgPtkYaXoeaTw50yhSxj8Q9x0cAuVM5jhFJtepxy8 K/lzA+eykrWojY3PA8bjfKuFbb9UUREHBRRxN7b+Sh0m+3DT8G2oTrUdqc34PMlQBa2u Ml4zWCTUvdGYaDVXVMj3qhlM1FX98rBDS3O4MDF89YoWspBhu1wgs9BHVMNW7X9ZMGVP AOaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781130950; x=1781735750; h=references:in-reply-to:subject:cc:to:from:content-transfer-encoding :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g/D1irD7H2COSIlqfBmKm6Z8H6xz/cGj28gGU8DwqkI=; b=QPr09hl2Vtbf0s2Osa7wIvfhGJl4S0Rg67QQY41hsfLebAeF917wf99wlH8MnLNpAw ejiIauO350u8EBOLEZUsX1KVNsD8cSxIdmAr3TIIdXamciC00u101OG4yuxrmK8ed8OL xdQv6LkNdoqmTy9KXRxMMvaDkaYbcp7L1X0fNof4FjMETVgL8YudNNJ6QIWYdc3RxfOI IMvUR03yMrmYIHLYzFWiInZttWg4d0Psn59tf9QSgu/8Jl5yPMYPEGKmKfQZ2hoKxrsj AbfuWYrt0VOFoo010i89Sk6U+FBg9Ukpjt0uAL0hgFKcFOHTRQcftosqqnoKdtZn41TL rniA== X-Forwarded-Encrypted: i=1; AFNElJ8YFNgjmQT0px7eikaVfb+cpGxRGADSDpJkigedwj7nxCjrRlKtZvYB5bMU2Q20YDFwrt+o2pVvq8Jtabk=@vger.kernel.org X-Gm-Message-State: AOJu0YxAgnDDElkgXtAl4SrnABTrdtJ6bFZ/OixEphPIjhT32Q+4926c 1aFuqvFeErLrQ2WrmPv8RTasIVAXeKr6s81Jaxaj5grZqnwIDiJ3SyJv X-Gm-Gg: Acq92OG7IEH8NIIw4Om82Vi92LwirxAGouHYvQec22Aa7kMuDMUiuh/a06nz079WsQJ 7ypl0LYB/1VUoTfTLAYapR/7fCKdIIQRkUs/EkN4wYZEtC618tNsVuUR7YMEBWhDZz2P6ryGxlJ p2UMInmwkhFXneL/zRGS26pZW8xXY3pDYvgcIpQR/nePmkuCjwOuM7UqlMNMKAaMW22D5Gzla8N p5pyrIfLR1JQxIGJkcBmyZEG05/dvGzPlocxf2vs1pa8Ry2xtYTx893pIpQk8szfzfjU9lR+is/ nkgfEHuJFCaKy8tJCybqRFxQSBa+maV2UNJPzAMQIWOFsuk5cIRnsHKifuTo90BNsMUEaPnmEx7 LTEksdRYtakcpTGfqysT3hGTOfzzYHi7eXz4yGu6C05ARHgF7i8HATJib65+x3XGC8PSWIQhhzZ SJqDzeH7ZcZypvr0anKrS6HJPxKsSTWifntswKICwRDffv4A== X-Received: by 2002:a5d:40c2:0:b0:43b:3e40:2223 with SMTP id ffacd0b85a97d-460675a6038mr176752f8f.19.1781130950067; Wed, 10 Jun 2026 15:35:50 -0700 (PDT) Received: from [127.0.0.1] ([141.255.129.1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2e4004sm75127428f8f.9.2026.06.10.15.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 15:35:49 -0700 (PDT) Message-ID: <6a29e6c5.53cb9477.9024c.bc8a@mx.google.com> Date: Wed, 10 Jun 2026 15:35:49 -0700 (PDT) Content-Type: text/plain; charset="us-ascii" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: c4ffein.work@gmail.com To: akpm@linux-foundation.org Cc: egorenar-dev@posteo.net, robert.jarzmik@free.fr, t-pratham@ti.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/2] lib: scatterlist: fix sg_split() partial-coverage geometry + add KUnit tests In-Reply-To: <20260601175549.b4a10c07dd9e3b867f66da0c@linux-foundation.org> References: <178027099087.72481.1976843064458686851@gmail.com> <20260601175549.b4a10c07dd9e3b867f66da0c@linux-foundation.org> On Mon, 1 Jun 2026 17:55:49 -0700 Andrew Morton wrote: > Thanks. Has this been observed in real life, or was the patch motivated by > code review? Not observed in real life. I was crafting a pure C client for the Hegel PBT library (and related bug-hunting Claude skills). I used known kernel bugs to benchmark various interfaces and skills. Crafting Hegel tests for sg_split.c led Claude to report this one to me. I only realized it was actually already reported later. > AI review > (https://sashiko.dev/#/patchset/178027099087.72481.1976843064458686851@gmail.com) > might have found a pre-existing issue, which you may choose to reject, > fix, add to todo list or ignore. Also a possible issue in the kunit > test changes. > > Please take a look, let us know? I took a look; it raised more questions and led to more changes: --- 1: The first comment noted that the existing code has no guard against a split_sizes array ending with a 0 size This is arguably the caller's responsibility, but since it's an out-of-bounds write in an exported function, I lean toward guarding it here. A trailing zero-size split that receives no input entry leaves out_sg == ZERO_SIZE_PTR, and sg_split_phys()/sg_split_mapped() then write out_sg[-1].length: an out-of-bounds write. Confirmed with KASAN, and with a userspace ASAN harness. Fix: skip empty splits in both copiers. (It needs a caller to request a trailing zero-size split with no input left; no in-tree caller does, so it's latent.) 2: The second comment flagged an issue in the kunit suite The test passes in_mapped_nents = n_in for an unmapped list, where it must be 0. On NEED_SG_DMA_LENGTH arches, the mapped pass then reads a zeroed dma_length and returns -EINVAL. It passed for me only because UML aliases dma_len onto ->length. Fix: pass 0. 3: The test finding also turned up a separate pre-existing bug, also latent. On !NEED_SG_DMA_LENGTH arches sg_dma_len() aliases ->length, so sg_split_phys() zeroes, via sg_dma_len(out_sg) = 0, the length it has just computed. The trailing out_sg[-1].length assignment restores only the last entry, so for the non-last entries of a multi-entry split the zero sticks -> silent short data. Fix: write ->length after the sg_dma_len() = 0. Verified in-kernel (UML and x86_64+KASAN) and under ASAN. (No in-tree caller hits it: the sole unmapped caller, DTHEv2, runs on arm64 = NEED, which is immune.) --- v2 grows to 5 patches. 1. the overshoot fix: the exact same initial patch 2. the additional size computation fix 3. the base test suite, improved - fixed the second comment from sashiko - each case now run both unmapped and identity-mapped - added DMA-address + end-marker assertions and NEED-gated divergent-geometry cases 4. the zero-size OOB guard 5. its associated regression test That way, patches 4 and 5 can be skipped if you think we should actually keep the responsibility on the caller. The automated review prompted patches 4 and 5 and the test-arg fix in 3; chasing that fix is what surfaced 2. I'll note that in the commit messages. I went with tolerate-and-skip for the empty trailing split rather than rejecting it with -EINVAL, reasoning it's the droppable tail of the request. Happy to respin that one patch to -EINVAL if you'd prefer the stricter contract -- trivial either way. I'll send v2 threaded under this series shortly. Thanks, Charles