[PATCH v2 1/2] sparc64: Stop the hwcap-list parser at an unterminated entry

From: Stian Halseth

Date: Wed Nov 18 2026 - 06:55:55 EST


mdesc_cpu_hwcap_list() walks the hwcap-list strings with strlen() and
strcmp(). If the last entry has no NUL within the property, both read
past its end. len then goes negative, and while (len) does not stop.

Measure each entry with strnlen() first, and stop at one that does not
fit, as of_property_read_string_helper() does.

Signed-off-by: Stian Halseth <stian@xxxxxx>
---
arch/sparc/kernel/setup_64.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
index 63615f5c99b47..96de9fe84cd44 100644
--- a/arch/sparc/kernel/setup_64.c
+++ b/arch/sparc/kernel/setup_64.c
@@ -489,6 +489,10 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
while (len) {
int i, plen;

+ plen = strnlen(prop, len) + 1;
+ if (plen > len)
+ break;
+
for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
unsigned long bit = 1UL << i;

@@ -502,7 +506,6 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
caps |= HWCAP_SPARC_CRYPTO;
}

- plen = strlen(prop) + 1;
prop += plen;
len -= plen;
}
--
2.43.0