Skip to content

Commit 1db2728

Browse files
novitollakpm00
authored andcommitted
x86/traps: move kmsan check after instrumentation_begin
During x86_64 kernel build with CONFIG_KMSAN, the objtool warns following: AR built-in.a AR vmlinux.a LD vmlinux.o vmlinux.o: warning: objtool: handle_bug+0x4: call to kmsan_unpoison_entry_regs() leaves .noinstr.text section OBJCOPY modules.builtin.modinfo GEN modules.builtin MODPOST Module.symvers CC .vmlinux.export.o Moving kmsan_unpoison_entry_regs() _after_ instrumentation_begin() fixes the warning. There is decode_bug(regs->ip, &imm) is left before KMSAN unpoisoining, but it has the return condition and if we include it after instrumentation_begin() it results the warning "return with instrumentation enabled", hence, I'm concerned that regs will not be KMSAN unpoisoned if `ud_type == BUG_NONE` is true. Link: https://lkml.kernel.org/r/20241016152407.3149001-1-snovitoll@gmail.com Fixes: ba54d19 ("x86/traps: avoid KMSAN bugs originating from handle_bug()") Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com> Reviewed-by: Alexander Potapenko <glider@google.com> Cc: Borislav Petkov (AMD) <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b7c5f9a commit 1db2728

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

arch/x86/kernel/traps.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,6 @@ static noinstr bool handle_bug(struct pt_regs *regs)
261261
int ud_type;
262262
u32 imm;
263263

264-
/*
265-
* Normally @regs are unpoisoned by irqentry_enter(), but handle_bug()
266-
* is a rare case that uses @regs without passing them to
267-
* irqentry_enter().
268-
*/
269-
kmsan_unpoison_entry_regs(regs);
270264
ud_type = decode_bug(regs->ip, &imm);
271265
if (ud_type == BUG_NONE)
272266
return handled;
@@ -275,6 +269,12 @@ static noinstr bool handle_bug(struct pt_regs *regs)
275269
* All lies, just get the WARN/BUG out.
276270
*/
277271
instrumentation_begin();
272+
/*
273+
* Normally @regs are unpoisoned by irqentry_enter(), but handle_bug()
274+
* is a rare case that uses @regs without passing them to
275+
* irqentry_enter().
276+
*/
277+
kmsan_unpoison_entry_regs(regs);
278278
/*
279279
* Since we're emulating a CALL with exceptions, restore the interrupt
280280
* state to what it was at the exception site.

0 commit comments

Comments
 (0)