mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stian Halseth <stian@itx.no>
To: sparclinux@vger.kernel.org
Cc: Andreas Larsson <andreas@gaisler.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Biggers <ebiggers@kernel.org>,
	Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
	linux-kernel@vger.kernel.org, Stian Halseth <stian@itx.no>
Subject: [PATCH v2 1/2] sparc64: Stop the hwcap-list parser at an unterminated entry
Date: Wed, 18 Nov 2026 12:55:36 +0100	[thread overview]
Message-ID: <20261118115537.160675-2-stian@itx.no> (raw)
In-Reply-To: <20261118115537.160675-1-stian@itx.no>

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@itx.no>
---
 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


  reply	other threads:[~2026-11-18 11:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 11:55 [PATCH v2 0/2] sparc64: Read qemu,hwcap-list on sun4u Stian Halseth
2026-11-18 11:55 ` Stian Halseth [this message]
2026-11-18 11:55 ` [PATCH v2 2/2] sparc64: Read qemu,hwcap-list from the OF cpu node " Stian Halseth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118115537.160675-2-stian@itx.no \
    --to=stian@itx.no \
    --cc=andreas@gaisler.com \
    --cc=davem@davemloft.net \
    --cc=ebiggers@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=sparclinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®