Skip to content

Commit a7bed27

Browse files
keestorvalds
authored andcommitted
bug: fix "cut here" location for __WARN_TAINT architectures
Prior to v4.11, x86 used warn_slowpath_fmt() for handling WARN()s. After WARN() was moved to using UD0 on x86, the warning text started appearing _before_ the "cut here" line. This appears to have been a long-standing bug on architectures that used __WARN_TAINT, but it didn't get fixed. v4.11 and earlier on x86: ------------[ cut here ]------------ WARNING: CPU: 0 PID: 2956 at drivers/misc/lkdtm_bugs.c:65 lkdtm_WARNING+0x21/0x30 This is a warning message Modules linked in: v4.12 and later on x86: This is a warning message ------------[ cut here ]------------ WARNING: CPU: 1 PID: 2982 at drivers/misc/lkdtm_bugs.c:68 lkdtm_WARNING+0x15/0x20 Modules linked in: With this fix: ------------[ cut here ]------------ This is a warning message WARNING: CPU: 3 PID: 3009 at drivers/misc/lkdtm_bugs.c:67 lkdtm_WARNING+0x15/0x20 Since the __FILE__ reporting happens as part of the UD0 handler, it isn't trivial to move the message to after the WARNING line, but at least we can fix the position of the "cut here" line so all the various logging tools will start including the actual runtime warning message again, when they follow the instruction and "cut here". Link: http://lkml.kernel.org/r/1510100869-73751-4-git-send-email-keescook@chromium.org Fixes: 9a93848 ("x86/debug: Implement __WARN() using UD0") Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Fengguang Wu <fengguang.wu@intel.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Ingo Molnar <mingo@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2a8358d commit a7bed27

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎include/asm-generic/bug.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ extern void warn_slowpath_null(const char *file, const int line);
9292
#define __WARN_printf_taint(taint, arg...) \
9393
warn_slowpath_fmt_taint(__FILE__, __LINE__, taint, arg)
9494
#else
95+
extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
9596
#define __WARN() __WARN_TAINT(TAINT_WARN)
96-
#define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
97+
#define __WARN_printf(arg...) do { __warn_printk(arg); __WARN(); } while (0)
9798
#define __WARN_printf_taint(taint, arg...) \
98-
do { printk(arg); __WARN_TAINT(taint); } while (0)
99+
do { __warn_printk(arg); __WARN_TAINT(taint); } while (0)
99100
#endif
100101

101102
/* used internally by panic.c */

‎kernel/panic.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
520520
{
521521
disable_trace_on_warning();
522522

523-
pr_warn(CUT_HERE);
523+
if (args)
524+
pr_warn(CUT_HERE);
524525

525526
if (file)
526527
pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
@@ -584,9 +585,22 @@ EXPORT_SYMBOL(warn_slowpath_fmt_taint);
584585

585586
void warn_slowpath_null(const char *file, int line)
586587
{
588+
pr_warn(CUT_HERE);
587589
__warn(file, line, __builtin_return_address(0), TAINT_WARN, NULL, NULL);
588590
}
589591
EXPORT_SYMBOL(warn_slowpath_null);
592+
#else
593+
void __warn_printk(const char *fmt, ...)
594+
{
595+
va_list args;
596+
597+
pr_warn(CUT_HERE);
598+
599+
va_start(args, fmt);
600+
vprintk(fmt, args);
601+
va_end(args);
602+
}
603+
EXPORT_SYMBOL(__warn_printk);
590604
#endif
591605

592606
#ifdef CONFIG_BUG

0 commit comments

Comments
 (0)