From: "Troy Mitchell" <troy.mitchell@linux.dev>
To: <shao.mingyin@zte.com.cn>, <pjw@kernel.org>, <mikey@neuling.org>
Cc: <jiangfeng@kylinos.cn>, <palmer@dabbelt.com>,
<aou@eecs.berkeley.edu>, <alex@ghiti.fr>,
<linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
<zhang.yue5@zte.com.cn>, <david.laight.linux@gmail.com>,
<qingfang.deng@linux.dev>,
"linux-riscv" <linux-riscv-bounces@lists.infradead.org>,
"Troy Mitchell" <troy.mitchell@linux.dev>
Subject: Re: [PATCH v4] riscv: lib: Fix ZBB strnlen wrap-around regression on huge counts
Date: Tue, 22 Sep 2026 11:48:23 +0800 [thread overview]
Message-ID: <DLLJDLKPZ4S3.1KQ5O4OQBBTEW@linux.dev> (raw)
In-Reply-To: <20260915152656708z04s4oSYY2BGj34F36RZa@zte.com.cn>
[-- Attachment #1.1: Type: text/plain, Size: 1763 bytes --]
On Tue Sep 15, 2026 at 3:26 PM +08, shao.mingyin wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
>
> The aligned scan boundary is derived from the last valid byte,
> (s + count - 1). When count is huge (e.g. SIZE_MAX, which FORTIFY
> strcat/strlcat pass when the destination size is not known at compile
> time), s + count wraps around and the boundary lands before s, so the
> ZBB path returns a bogus length. The original implementation
> (5ba15d419fab) had the same wrap-around in its (s + count) & ~7
> boundary computation; after 5d588c684833 the wrapped boundary is caught
> by the pre-loop guard "bgeu t0, t4, 2f", which then always exits for
> aligned strings of 8 or more characters and strnlen() returns 8
> instead of the real length.
>
> This silently truncates strings built by fortified strcat: the dm
> sysfs name attribute shows "live-bas" instead of "live-base", the
> truncated name pollutes the udev database, and blivet/anaconda (as
> well as LVM/dm-crypt/multipath userspace) break on RISC-V systems.
>
> Detect the wrap-around and saturate the boundary to the top of the
> address space, making the scan equivalent to strlen(). The saturation
> clamps the increment to ~s, so it stays branchless and wrap-free:
>
> s + min(count - 1, ~s) == saturating_add(s, count - 1)
>
> Normal counts are unaffected.
>
> Fixes: 5ba15d419fab ("riscv: lib: add strnlen() implementation")
> Cc: stable@vger.kernel.org
> Suggested-by: David Laight <david.laight.linux@gmail.com>
> Suggested-by: Qingfang Deng <qingfang.deng@linux.dev>
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> Acked-by: Michael Neuling <mikey@neuling.org>
Tested-by: Troy Mitchell <troy.mitchell@linux.dev>
--
Troy Mitchell
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]
[-- Attachment #2: Type: text/plain, Size: 161 bytes --]
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-09-22 3:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 7:26 [PATCH v4] riscv: lib: Fix ZBB strnlen wrap-around regression on huge counts shao.mingyin
2026-09-22 3:48 ` Troy Mitchell [this message]
2026-09-25 20:54 ` Aurelien Jarno
2026-09-28 3:35 ` shao.mingyin
2026-10-05 17:13 ` Paul Walmsley
2026-10-05 17:00 ` patchwork-bot+linux-riscv
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=DLLJDLKPZ4S3.1KQ5O4OQBBTEW@linux.dev \
--to=troy.mitchell@linux.dev \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=david.laight.linux@gmail.com \
--cc=jiangfeng@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv-bounces@lists.infradead.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mikey@neuling.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=qingfang.deng@linux.dev \
--cc=shao.mingyin@zte.com.cn \
--cc=zhang.yue5@zte.com.cn \
/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.