Skip to contentSkip to conversation

CVE-2026-74751: riscv: lib: Fix ZBB strnlen reading past count boundary

DISCUSSION Greg Kroah-Hartman 1 participant 1 message Aug 26

lore
Share & tools
lore
#0 lore raw

From: Greg Kroah-Hartman <[email protected]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

riscv: lib: Fix ZBB strnlen reading past count boundary

The ZBB-optimized strnlen loop loads one word ahead before checking the aligned boundary:

    REG_L   t1, SZREG(t0)       // load next word
    addi    t0, t0, SZREG       // advance
    orc.b   t1, t1
    bgeu    t0, t4, 4f          // boundary check AFTER load

where t4 = (s + count) & -SZREG. When s is aligned and count is a multiple of SZREG, t4 equals s + count and the loop loads a full word starting at exactly s + count. If s + count falls on a page boundary with the next page unmapped, this faults.

Fix by computing the aligned boundary from the last valid byte (s + count - 1) instead of s + count. This makes the loop stop at the word containing the last valid byte rather than potentially loading the word after it. The count == 0 case is already handled by the beqz early exit.

Also add a pre-loop guard (bgeu t0, t4) for the case where all valid bytes fit within the first word. With the adjusted boundary, t4 can equal t0, and entering the loop with stale register state from the first-word processing would produce incorrect results.

The final minu clamp ensures the result is still correct when the last loaded word extends past s + count - 1 within the same aligned word.

The Linux kernel CVE team has assigned CVE-2026-74751 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 7.1 with commit 5ba15d419fab848a3813eb56bbcad00e291fbc49 and fixed in 7.1.10 with commit e697e30f3dd2da3a1df7dc0980546d5b53aea4b6
	Issue introduced in 7.1 with commit 5ba15d419fab848a3813eb56bbcad00e291fbc49 and fixed in 7.2 with commit 5d588c684833e678a0008eb69c33190f01a65f4b

Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at

	https://cve.org/CVERecord/?id=CVE-2026-74751

will be updated if fixes are backported, please check that for the most up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
arch/riscv/lib/strnlen.S

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits:

	https://git.kernel.org/stable/c/e697e30f3dd2da3a1df7dc0980546d5b53aea4b6
	https://git.kernel.org/stable/c/5d588c684833e678a0008eb69c33190f01a65f4b