]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/bug: Add printf() validation to HAVE_ARCH_BUG_FORMAT_ARGS WARNs
authorSean Christopherson <seanjc@google.com>
Thu, 23 Apr 2026 14:54:17 +0000 (07:54 -0700)
committerDave Hansen <dave.hansen@linux.intel.com>
Mon, 27 Apr 2026 19:02:40 +0000 (12:02 -0700)
Add explicit printf() validation for x86-64's newfangled WARN
implementation, as most (all?) compilers fail to detect basic formatting
issues without the annotation.  E.g. even goofs like printing a u64 as a
string aren't detected:

  WARN_ONCE(1, "Bad message, %s", vcpu->arch.last_guest_tsc);

32-bit x86 doesn't support HAVE_ARCH_BUG_FORMAT_ARGS and uses generic
implementations that provide printf() validation. This means there's
now a big blind spot is code that is strictly x86-64. Inconveniently,
new features are also frequently x86-64-only.

Fix the blind 64-bit blind spot.

[ dhansen: changelog tweaks to flesh out the 64-bit-only details ]

Fixes: 5b472b6e5bd9 ("x86_64/bug: Implement __WARN_printf()")
Fixes: 11bb4944f014 ("x86/bug: Implement WARN_ONCE()")
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: https://lore.kernel.org/all/adc1IrD8uqWdaOKv@yzhao56-desk.sh.intel.com
Link: https://patch.msgid.link/20260423145419.459988-2-seanjc@google.com
arch/x86/include/asm/bug.h

index 80c1696d8d5978df2f6663cb56cc59687530caf6..bf3c802654d18a86f32771df1a36c71b6c9fcb5b 100644 (file)
@@ -153,6 +153,7 @@ struct arch_va_list {
        struct sysv_va_list args;
 };
 extern void *__warn_args(struct arch_va_list *args, struct pt_regs *regs);
+static __always_inline __printf(1, 2) void __WARN_validate_printf(const char *fmt, ...) { }
 #endif /* __ASSEMBLER__ */
 
 #define __WARN_bug_entry(flags, format) ({                             \
@@ -172,6 +173,7 @@ extern void *__warn_args(struct arch_va_list *args, struct pt_regs *regs);
 #define __WARN_print_arg(flags, format, arg...)                                \
 do {                                                                   \
        int __flags = (flags) | BUGFLAG_WARNING | BUGFLAG_ARGS ;        \
+       __WARN_validate_printf(format, ## arg);                         \
        static_call_mod(WARN_trap)(__WARN_bug_entry(__flags, format), ## arg); \
        asm (""); /* inhibit tail-call optimization */                  \
 } while (0)