linux-stable/arch
Ahmed S. Darwish 62af778005 x86/cpu: Sanitize CPUID(0x80000000) output
[ Upstream commit cc663ba3fe ]

CPUID(0x80000000).EAX returns the max extended CPUID leaf available.  On
x86-32 machines without an extended CPUID range, a CPUID(0x80000000)
query will just repeat the output of the last valid standard CPUID leaf
on the CPU; i.e., a garbage values.  Current tip:x86/cpu code protects against
this by doing:

	eax = cpuid_eax(0x80000000);
	c->extended_cpuid_level = eax;

	if ((eax & 0xffff0000) == 0x80000000) {
		// CPU has an extended CPUID range. Check for 0x80000001
		if (eax >= 0x80000001) {
			cpuid(0x80000001, ...);
		}
	}

This is correct so far.  Afterwards though, the same possibly broken EAX
value is used to check the availability of other extended CPUID leaves:

	if (c->extended_cpuid_level >= 0x80000007)
		...
	if (c->extended_cpuid_level >= 0x80000008)
		...
	if (c->extended_cpuid_level >= 0x8000000a)
		...
	if (c->extended_cpuid_level >= 0x8000001f)
		...

which is invalid.  Fix this by immediately setting the CPU's max extended
CPUID leaf to zero if CPUID(0x80000000).EAX doesn't indicate a valid
CPUID extended range.

While at it, add a comment, similar to kernel/head_32.S, clarifying the
CPUID(0x80000000) sanity check.

References: 8a50e5135a ("x86-32: Use symbolic constants, safer CPUID when enabling EFER.NX")
Fixes: 3da99c9776 ("x86: make (early)_identify_cpu more the same between 32bit and 64 bit")
Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: x86-cpuid@lists.linux.dev
Link: https://lore.kernel.org/r/20250506050437.10264-3-darwi@linutronix.de
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-06-19 15:28:02 +02:00
..
alpha
arc
arm ARM: at91: pm: fix at91_suspend_finish for ZQ calibration 2025-06-04 14:42:03 +02:00
arm64 arm64: dts: ti: k3-am68-sk: Fix regulator hierarchy 2025-06-04 14:42:24 +02:00
csky
hexagon
ia64
loongarch LoongArch: Explicitly specify code model in Makefile 2025-05-22 14:12:25 +02:00
m68k
microblaze
mips MIPS: pm-cps: Use per-CPU variables as per-CPU, not per-core 2025-06-04 14:42:06 +02:00
nios2
openrisc
parisc parisc: Fix double SIGFPE crash 2025-05-09 09:43:50 +02:00
powerpc powerpc/crash: Fix non-smp kexec preparation 2025-06-19 15:28:02 +02:00
riscv riscv: Allow NOMMU kernels to access all of RAM 2025-06-04 14:41:54 +02:00
s390 hypfs_create_cpu_files(): add missing check for hypfs_mkdir() failure 2025-06-04 14:41:57 +02:00
sh
sparc
um um: let 'make clean' properly clean underlying SUBARCH as well 2025-06-04 14:42:25 +02:00
x86 x86/cpu: Sanitize CPUID(0x80000000) output 2025-06-19 15:28:02 +02:00
xtensa
.gitignore
Kconfig