mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/mce: Zero the injected error record before logging it
@ 2026-09-10  3:32 Yifei Chu
  2026-09-10  3:59 ` Borislav Petkov
  0 siblings, 1 reply; 2+ messages in thread
From: Yifei Chu @ 2026-09-10  3:32 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Tony Luck, Avadhut Naik, Yazen Ghannam, linux-edac, x86, linux-kernel

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}

Fixes: d4fca1358ea9 ("x86/MCE/AMD: Add support for new MCA_SYND{1,2} registers")
Cc: stable@vger.kernel.org
Reported-by: Abaci <abaci@linux.alibaba.com>
Assisted-by: abaci:qwen3.8-max
Signed-off-by: Yifei Chu <Chuyf26@linux.alibaba.com>
---
 arch/x86/kernel/cpu/mce/inject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mce/inject.c b/arch/x86/kernel/cpu/mce/inject.c
index 6f8a49d..a6d8f8e 100644
--- a/arch/x86/kernel/cpu/mce/inject.c
+++ b/arch/x86/kernel/cpu/mce/inject.c
@@ -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;
 
-- 
2.43.5

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-10  3:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-10  3:32 [PATCH] x86/mce: Zero the injected error record before logging it Yifei Chu
2026-09-10  3:59 ` Borislav Petkov

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®