Skip to content

Commit 284e35a

Browse files
bysuiSasha Levin
authored andcommitted
x86/bug: Handle __WARN_printf() trap in early_fixup_exception()
[ Upstream commit a0cb371 ] The commit 5b472b6 ("x86_64/bug: Implement __WARN_printf()") implemented __WARN_printf(), which changed the mechanism to use UD1 instead of UD2. However, it only handles the trap in the runtime IDT handler, while the early booting IDT handler lacks this handling. As a result, the usage of WARN() before the runtime IDT setup can lead to kernel crashes. Since KMSAN is enabled after the runtime IDT setup, it is safe to use handle_bug() directly in early_fixup_exception() to address this issue. Fixes: 5b472b6 ("x86_64/bug: Implement __WARN_printf()") Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/c4fb3645f60d3a78629d9870e8fcc8535281c24f.1768016713.git.houwenlong.hwl@antgroup.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 92caa52 commit 284e35a

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

arch/x86/include/asm/traps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern int ibt_selftest_noendbr(void);
2525
void handle_invalid_op(struct pt_regs *regs);
2626
#endif
2727

28+
noinstr bool handle_bug(struct pt_regs *regs);
29+
2830
static inline int get_si_code(unsigned long condition)
2931
{
3032
if (condition & DR_STEP)

arch/x86/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static inline void handle_invalid_op(struct pt_regs *regs)
397397
ILL_ILLOPN, error_get_trap_addr(regs));
398398
}
399399

400-
static noinstr bool handle_bug(struct pt_regs *regs)
400+
noinstr bool handle_bug(struct pt_regs *regs)
401401
{
402402
unsigned long addr = regs->ip;
403403
bool handled = false;

arch/x86/mm/extable.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,11 @@ void __init early_fixup_exception(struct pt_regs *regs, int trapnr)
411411
return;
412412

413413
if (trapnr == X86_TRAP_UD) {
414-
if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN) {
415-
/* Skip the ud2. */
416-
regs->ip += LEN_UD2;
414+
if (handle_bug(regs))
417415
return;
418-
}
419416

420417
/*
421-
* If this was a BUG and report_bug returns or if this
418+
* If this was a BUG and handle_bug returns or if this
422419
* was just a normal #UD, we want to continue onward and
423420
* crash.
424421
*/

0 commit comments

Comments
 (0)