Skip to content

[PW_SID:1080440] riscv: lib: Fix ZBB strnlen reading past count boundary#1756

Closed
linux-riscv-bot wants to merge 1 commit into
workflow__riscv__for-nextfrom
pw1080440
Closed

[PW_SID:1080440] riscv: lib: Fix ZBB strnlen reading past count boundary#1756
linux-riscv-bot wants to merge 1 commit into
workflow__riscv__for-nextfrom
pw1080440

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

PR for series 1080440 applied to workflow__riscv__for-next

Name: riscv: lib: Fix ZBB strnlen reading past count boundary
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1080440
Version: 1

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.

Fixes: 5ba15d4 ("riscv: lib: add strnlen() implementation")
Signed-off-by: Michael Neuling <mikey@neuling.org>
Assisted-by: Claude Opus4.6 High Thinking
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 137.02 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 994.60 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1357.90 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.06 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 26.37 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.77 seconds
Result: ERROR
Output:

WARNING: Non-standard signature: Assisted-by:
#35: 
Assisted-by: Claude Opus4.6 High Thinking

ERROR: Unrecognized email address: 'Claude Opus4.6 High Thinking'
#35: 
Assisted-by: Claude Opus4.6 High Thinking

total: 1 errors, 1 warnings, 0 checks, 23 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit ba25ce4cf55e ("riscv: lib: Fix ZBB strnlen reading past count boundary") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
ERROR: Unrecognized email address: 'Claude Opus4.6 High Thinking'
WARNING: Non-standard signature: Assisted-by:


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 83.63 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
kdoc
Desc: Detects for kdoc errors
Duration: 0.87 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
module-param
Desc: Detect module_param changes
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.28 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: lib: Fix ZBB strnlen reading past count boundary"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot deleted the pw1080440 branch April 21, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants