From nobody Mon Sep 28 18:35:51 2026 Received: from mxct.zte.com.cn (mxct.zte.com.cn [58.251.27.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C17B40DB48 for ; Wed, 19 Aug 2026 08:28:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=58.251.27.85 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787128132; cv=none; b=bBA2eS5OWiju5Ke7MqhRDjVSNDbTXP3yM0L/uXUZZHNOQOe0c81NXraOZZC/uWBKpJrPkipfwAevU2EpgUdoirNAk+Ua7+aFXYEZDkQey/37NZ9KRatBiRpNFRYffN6DvBFfrHv2Qy3J1wos6ih5+7JoYKQirAR1Emwrm/2Ui3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787128132; c=relaxed/simple; bh=YGx42g+NHAFuJiJ9d1XdDpf/av0r1CKeU5SFFZ7Dcfs=; h=Message-ID:Date:Mime-Version:From:To:Cc:Subject:Content-Type; b=kHzp1V3iu79uZvUKjYRDXKAY2sw4iozb/Ciaw7v9kTF2LxEtLRFhSpI69a0whysW1VTUfPjtdpIgVIrJ3nodMdBH+pBZz7SPdWpeW2xFw5fMItGuaGMRfNHzzpjjCAEk04g+iwTSAnZSwCXzRyZWuOzR9BIxqy1iMj8/y2ZUiPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=58.251.27.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mxde.zte.com.cn (unknown [10.35.20.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4hPzx63Zspz2wWm for ; Wed, 19 Aug 2026 16:18:50 +0800 (CST) Received: from mxhk.zte.com.cn (unknown [192.168.250.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxde.zte.com.cn (FangMail) with ESMTPS id 4hPzwx1lhXzBlsfw for ; Wed, 19 Aug 2026 16:18:41 +0800 (CST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4hPzwl3PFnz8XrrJ; Wed, 19 Aug 2026 16:18:31 +0800 (CST) Received: from szxl2zmapp06.zte.com.cn ([10.1.32.108]) by mse-fl2.zte.com.cn with SMTP id 67J8IIsJ026318; Wed, 19 Aug 2026 16:18:18 +0800 (+08) (envelope-from gao.rui@zte.com.cn) Received: from mapi (szxl2zmapp07[null]) by mapi (Zmail) with MAPI id mid12; Wed, 19 Aug 2026 16:18:21 +0800 (CST) X-Zmail-TransId: 2b096a8566cd883-ab3fa X-Mailer: Zmail v1.0 Message-ID: <20260819161821053fNUWuvdGIo4HUBmxlcNfG@zte.com.cn> Date: Wed, 19 Aug 2026 16:18:21 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , , , , Cc: , Subject: =?UTF-8?B?W1BBVENIXSByaXNjdjogbGliOiBGaXggYWRkcmVzcyBvdmVyZmxvdyBkdWUgdG8gbGFyZ2UgY291bnQgdmFsdWVzIGluIHN0cm5sZW4gWkJCIHBhdGg=?= X-MAIL: mse-fl2.zte.com.cn 67J8IIsJ026318 X-TLS: YES X-ENVELOPE-SENDER: gao.rui@zte.com.cn X-SOURCE-IP: 10.35.20.121 unknown Wed, 19 Aug 2026 16:18:50 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A8566E9.001/4hPzx63Zspz2wWm Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hi all, This patch fixes an issue in the RISC-V ZBB optimized strnlen implementatio= n. Problem description: When using the ZBB optimized strnlen implementation, p= assing very large count values (such as SIZE_MAX) can cause address overflo= w 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-ma= pper operations. Patch summary: - Explicitly introduce the strnlen_generic label. - Simplify the generic implementation loop. - 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. Fixes: 5ba15d419fab ("riscv: lib: add strnlen() implementation") Signed-off-by: Gao Rui --- arch/riscv/lib/strnlen.S | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/riscv/lib/strnlen.S b/arch/riscv/lib/strnlen.S index a8911605c248..04016e51e8b5 100644 --- a/arch/riscv/lib/strnlen.S +++ b/arch/riscv/lib/strnlen.S @@ -17,6 +17,7 @@ SYM_FUNC_START(strnlen) __ALTERNATIVE_CFG("nop", "j strnlen_zbb", 0, RISCV_ISA_EXT_ZBB, IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) +strnlen_generic: /* * Returns @@ -27,15 +28,17 @@ SYM_FUNC_START(strnlen) * a1 - Max length of string * * Clobbers - * t0, t1, t2 + * t0, t1 */ - addi t1, a0, -1 - add t2, a0, a1 + mv t1, a0 + 1: - addi t1, t1, 1 - beq t1, t2, 2f + beqz a1, 2f + addi a1, a1, -1 lbu t0, 0(t1) - bnez t0, 1b + beqz t0, 2f + addi t1, t1, 1 + j 1b 2: sub a0, t1, a0 ret @@ -73,6 +76,13 @@ strnlen_zbb: /* If maxlen is 0, return 0. */ beqz a1, 3f + /* + * Fallback to generic implementation when count is large enough to + * cause address overflow in the ZBB optimized path + */ + add t4, a0, a1 + bltu t4, a0, strnlen_generic /* a0 + a1 overflow */ + /* Number of irrelevant bytes in the first word. */ andi t2, a0, SZREG-1 --=20 2.27.0