Re: [PATCH] riscv: lib: Fix address overflow due to large count values in strnlen ZBB path

Aurelien Jarno <[email protected]>
Newsgroups org.infradead.lists.linux-riscv,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Hi,

On 2026-08-19 16:18, [email protected] wrote:
> Hi all,
> 
> This patch fixes an issue in the RISC-V ZBB optimized strnlen implementation.
> 
> Problem description: When using the ZBB optimized strnlen implementation, passing very large count values (such as SIZE_MAX) can cause address overflow and return incorrect results.
> 
> This issue was observed in device-mapper tests:
> 
> sh-5.2# dmsetup create testname9 --table "0 8 zero"
> sh-5.2# cat /sys/block/dm-*/dm/name
> testname
> sh-5.2# dmsetup remove testname9
> 
> The overflow in strnlen caused failures in string handling during device-mapper operations.
> 
> Patch summary:
> - Explicitly introduce the strnlen_generic label.
> - Simplify the generic implementation loop.

This part should be in a separate patch, separated from the bug fix, and 
if possible with some benchmark.

> - Add fallback logic in strnlen_zbb to redirect to the generic path when a0 + a1 overflows.
> This ensures correct behavior for large count values and SIZE_MAX cases.

Is there a way to instead to fix the strnlen_zbb to avoid the fallback?

Regards
Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                     http://aurel32.net

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.