x86/mce: Zero the injected error record before logging it
Subsystems (3)
PATCH 1/1 x86/mce: Zero the injected error record before logging it
do_inject() declares a struct mce_hw_err on the stack and, for a software injection, fills in only err.m from i_mce before calling mce_log(&err). The err.vendor union (synd1/synd2, 16 bytes) is never initialized, so it holds whatever was left on the kernel stack.
Those bytes are not dropped: the mce_record tracepoint copies err->vendor verbatim into its v_data dynamic array, so a sw-injected record publishes 16 bytes of stale stack to anything reading the tracepoint. rasdaemon decodes v_data as MCA_SYND1/SYND2 supplemental error info (e.g. FRU text), so sw injection - whose whole purpose is to exercise the decode path - feeds the decoder nondeterministic garbage instead of a clean record.
Every other mce_log() caller builds its record through mce_prep_record(), which memsets the whole struct mce_hw_err first. do_inject() is the only one that skips it.
Zero-initialize the record so the vendor data of an injected MCE is always well defined. err.m is still fully overwritten by i_mce immediately afterwards, so the injected machine check fields are unchanged.
Reproduced with CONFIG_X86_MCE_INJECT: writing "sw" to flags and injecting a bank/status makes the mce_record tracepoint print random vendor data, e.g.
vendor data: {0xb3,0x8a,0xb5,0x41,0x0,0x0,0x0,0x0,
0x67,0x93,0xbc,0xa8,0xff,0xff,0xff,0xff}--- arch/x86/kernel/cpu/mce/inject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/inject.c +1 -1
@@ -504,7 +504,7 @@ static void prepare_msrs(void *info)static void do_inject (void ) {unsigned int cpu = i_mce.extcpu; -struct mce_hw_err err; +struct mce_hw_err err = {};u64 mcg_status =0 ;u8 b = i_mce.bank;
Signature · 1 line
2.43.5
Borislav Petkov
maintainerQuoted 6 lines · Yifei Chu
Reproduced with
CONFIG_X86_MCE_INJECT: writing "sw" to flags and injecting a bank/status makes themce_recordtracepoint print random vendor data, e.g.vendor data: {0xb3,0x8a,0xb5,0x41,0x0,0x0,0x0,0x0, 0x67,0x93,0xbc,0xa8,0xff,0xff,0xff,0xff}
And? Who cares?
Quoted 2 lines
Fixes d4fca1358ea9 ("x86/MCE/AMD: Add support for new MCA_SYND{1,2} registers")
Backport it everywhere? A MCE injection fix?
You must be joking.
Quoted 2 lines
Reported-by Abaci <[email protected]>Assisted-by abaci:qwen3.8-max
This is now
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette