Skip to content

Commit ba54d19

Browse files
ramosian-gliderakpm00
authored andcommitted
x86/traps: avoid KMSAN bugs originating from handle_bug()
There is a case in exc_invalid_op handler that is executed outside the irqentry_enter()/irqentry_exit() region when an UD2 instruction is used to encode a call to __warn(). In that case the `struct pt_regs` passed to the interrupt handler is never unpoisoned by KMSAN (this is normally done in irqentry_enter()), which leads to false positives inside handle_bug(). Use kmsan_unpoison_entry_regs() to explicitly unpoison those registers before using them. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Alexander Potapenko <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Kees Cook <[email protected]> Cc: Marco Elver <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 83d0edf commit ba54d19

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/kernel/traps.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/context_tracking.h>
1616
#include <linux/interrupt.h>
1717
#include <linux/kallsyms.h>
18+
#include <linux/kmsan.h>
1819
#include <linux/spinlock.h>
1920
#include <linux/kprobes.h>
2021
#include <linux/uaccess.h>
@@ -301,6 +302,12 @@ static noinstr bool handle_bug(struct pt_regs *regs)
301302
{
302303
bool handled = false;
303304

305+
/*
306+
* Normally @regs are unpoisoned by irqentry_enter(), but handle_bug()
307+
* is a rare case that uses @regs without passing them to
308+
* irqentry_enter().
309+
*/
310+
kmsan_unpoison_entry_regs(regs);
304311
if (!is_valid_bugaddr(regs->ip))
305312
return handled;
306313

0 commit comments

Comments
 (0)