From: sashiko-bot@kernel.org
To: "Stian Halseth" <stian@itx.no>, sparclinux@vger.kernel.org
Subject: Re: [PATCH] sparc64: Read qemu,hwcap-list from the OF cpu node on sun4u
Date: Tue, 17 Nov 2026 11:46:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-218725@kernel.org> (raw)
In-Reply-To: <20261117112914.2300417-1-stian@itx.no>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] sparc64: of_cpu_hwcap_list() enables broken sun4u skcipher FPU
usage
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] sparc: infinite loop and out-of-bounds read in
mdesc_cpu_hwcap_list() [1]
--
commit 2ca1536e272cd67392d1c65939db77b50052beab
Author: Stian Halseth <stian@itx.no>
sparc64: Read qemu,hwcap-list from the OF cpu node on sun4u
This commit factors out the hwcap-list string parser and uses it to read
CPU capabilities from the OpenFirmware cpu node's qemu,hwcap-list property
when no sun4v machine description is present.
> diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
> index 48abee4eee29d..f63a05360150e 100644
> --- a/arch/sparc/kernel/setup_64.c
> +++ b/arch/sparc/kernel/setup_64.c
[ ... ]
> @@ -479,25 +480,9 @@ static void __init report_hwcaps(unsigned long caps)
> printk(KERN_CONT "]\n");
> }
>
> -static unsigned long __init mdesc_cpu_hwcap_list(void)
> +static unsigned long __init hwcap_list_caps(const char *prop, int len)
> {
> - struct mdesc_handle *hp;
> unsigned long caps = 0;
> - const char *prop;
> - int len;
> - u64 pn;
> -
> - hp = mdesc_grab();
> - if (!hp)
> - return 0;
> -
> - pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "cpu");
> - if (pn == MDESC_NODE_NULL)
> - goto out;
> -
> - prop = mdesc_get_property(hp, pn, "hwcap-list", &len);
> - if (!prop)
> - goto out;
>
> while (len) {
> int i, plen;
> @@ -520,11 +505,53 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
> len -= plen;
> }
>
> + return caps;
> +}
[Severity: High]
This problem wasn't introduced by this patch, but can hwcap_list_caps()
read out of bounds and loop forever [1] if the property buffer is not
null-terminated?
If the final entry in prop lacks a terminating NUL byte within len bytes,
strlen(prop) reads past the end of the property buffer and plen exceeds
len. len -= plen then underflows the signed int len to a negative value,
so while (len) never terminates and hangs the boot. Bounding the string
length with strnlen(prop, len) and checking while (len > 0) would avoid the
overread and underflow.
[ ... ]
> @@ -562,6 +589,8 @@ static void __init init_sparc64_elf_hwcap(void)
> cap |= (AV_SPARC_MUL32 | AV_SPARC_DIV32 | AV_SPARC_V8PLUS);
>
> mdesc_caps = mdesc_cpu_hwcap_list();
> + if (!mdesc_caps)
> + mdesc_caps = of_cpu_hwcap_list();
> if (!mdesc_caps) {
> if (tlb_type == spitfire)
> cap |= AV_SPARC_VIS;
[Severity: High]
Does setting HWCAP_SPARC_CRYPTO in sparc64_elf_hwcap on sun4u cause a
regression where the sparc64 skcipher drivers corrupt FPU state and round
keys across skcipher_walk_done()?
When HWCAP_SPARC_CRYPTO is set, the sparc64 AES, DES, and Camellia skcipher
drivers in arch/sparc/crypto/ register at priority 300. Their encryption
and decryption loops load expanded keys into FPU registers with FPRS_FEF
enabled once before the walk loop and keep them live across
skcipher_walk_done():
arch/sparc/crypto/aes_glue.c:ecb_encrypt() {
...
ctx->ops->load_encrypt_keys(&ctx->key[0]);
while ((nbytes = walk.nbytes) != 0) {
ctx->ops->ecb_encrypt(&ctx->key[0], walk.src.virt.addr,
walk.dst.virt.addr,
round_down(nbytes, AES_BLOCK_SIZE));
err = skcipher_walk_done(&walk, nbytes % AES_BLOCK_SIZE);
}
fprs_write(0);
...
}
Unlike sun4v's NG4memcpy/M7memcpy (which use VISEntryHalfFast and fall back
to integer copies when FPRS_FEF is already set), sun4u uses U1memcpy or
U3memcpy, which unconditionally execute VISEntry/VISEntryHalf and VISExit
for copies above the VIS threshold. When skcipher_walk_done() calls
memcpy() on unaligned or multi-step walks, VISenter saves the expanded
cipher round keys over the current task's user FPU state in
current_thread_info()->fpregs[0], and U1memcpy/U3memcpy overwrite the FPU
registers and clear FPRS_FEF, causing boot-time crypto self-test failures
and silent data or user FPU corruption.
[1] https://sashiko.dev/#/bug/linux-93078b7c-14ab-4a50-a56f-abb0c72ca6f5
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117112914.2300417-1-stian@itx.no?part=1
next prev parent reply other threads:[~2026-11-17 11:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 11:29 [PATCH] sparc64: Read qemu,hwcap-list from the OF cpu node on sun4u Stian Halseth
2026-11-17 11:46 ` sashiko-bot [this message]
2026-11-17 12:44 ` Stian Halseth
2026-11-18 4:38 ` Eric Biggers
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=sashiko-outbox-218725@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sparclinux@vger.kernel.org \
--cc=stian@itx.no \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.