From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF7CF242D9B for ; Thu, 23 Apr 2026 14:54:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776956067; cv=none; b=hyzBd2CEnzsUiWl8vW4TcRagQP8RPGug+2D/JY8wRLban/1QPIwpPeSPrK+1QbGLSzYZWPxnk4upvbLa79EJ9azlJQJLWH6QEw3r5apJc4oUS4ItfSkRjJgVNIx88wA/Pd0Ic/Fpq1la6Wy/zQizOmXS9ENQ7dw602khQyYGrIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776956067; c=relaxed/simple; bh=zU+tj/df5c0qGETZJCIieQCwXEKc5AyaT/+uQoqdivw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lx+sFBw313E198M5j5IfjAgDgabWoYBtQWxQjdyqu2tFh9j5PiJXhHSrFxEHGbxps+b2YpDbuZaAYirLBCelRT/koli/46sZe4gnumsJ9LOpn0weAaT9YBILJU5eBt6mB7gvD4EPn9M2rVeknXkeHRPM2gPbpg6XVY3Z+ZQEn3c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=arFKnJ3+; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="arFKnJ3+" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b62da7602a0so3549598a12.2 for ; Thu, 23 Apr 2026 07:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776956065; x=1777560865; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=z4reAZlMsUrVzum9p0YSA33pO2Ve/EDZX4eovaEjQdk=; b=arFKnJ3+saCpBFqYBmQhQk2mIimD1bTyFzTqsrrVB063AiTOmmdSlaPSXnVvTo0Gxd r3pwYigBvVDhTMbfuDRYZpkRoxZTloRVMyhcDQLCMa4+79ecI9FbcQIf/zPNz+nN2snb WU9hR/DfHLfFjflWBnRlUM4X+XTJKhaokzul93GS5btudi0eEqPfCgtIuiEXrCiQ/XTv 6+5VTOaUnEi4TnOBpOsXKFkfvxkKh15DkgD4dQL8qtXQ0xFO/uDfMOX8D15wjoA6V/hC iqweNsgWBDO0n+TtwU5raTaO/jKFoWad5WFJEGq/LFOOXZgwf336Ly6dUXVktYHkA1Ex g9Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776956065; x=1777560865; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=z4reAZlMsUrVzum9p0YSA33pO2Ve/EDZX4eovaEjQdk=; b=pTS399O+Yk4hMhtXTr+DYaY+IljWCS1qtuYxlthPD3rDucHD4TyTNgepgCpruzYI2e gqLVozLNpv9PXbfuMn3ieMmWN0ME8y68H1wbpTxoAbMsBwxaQPz87wAf22yW2HOqVCFy s68Z1OD/o/Dwlf0blGJTTR2U0Abzq3VfrSXQsSnRxSCAS+tIgCFcMceUBbnE66J0dcmt v7sEPGB39A/KMxYadnuXSynFgw8aZkGTuxZc5w5200WYCoZvJRbCMCMEFs0IslPA1NEF BwmhftbFHwzZNOdJZ1ViGn0t1EnKZpE+r5+TDbOKkgBBdtcJLhoLJ6bX7bCVQORiTDN/ 9vzw== X-Gm-Message-State: AOJu0YyYFdxCH2NNivbi3SHmqRMcbTmWh1ZaSjiDvNs6EhFvDb8bBUt1 EF5H/rKwREMuKEccfLnRpszOZWa6lkOr4oij4PlCDa/ym/aj/ZUOPGZ8B9Slx3r/gt6sb+4p4cf SLSMIgQ== X-Received: from pgib18.prod.google.com ([2002:a63:e712:0:b0:c73:cc95:c0d7]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:a12b:b0:3a2:dafd:3c02 with SMTP id adf61e73a8af0-3a2dafd4cd8mr19691115637.19.1776956064896; Thu, 23 Apr 2026 07:54:24 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 23 Apr 2026 07:54:17 -0700 In-Reply-To: <20260423145419.459988-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260423145419.459988-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260423145419.459988-2-seanjc@google.com> Subject: [PATCH v2 1/2] x86/bug: Add printf() validation to HAVE_ARCH_BUG_FORMAT_ARGS WARNs From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: linux-kernel@vger.kernel.org, Yan Zhao , Peter Zijlstra , Sean Christopherson Content-Type: text/plain; charset="UTF-8" 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); Lack of validation is especially problematic for code that is 64-bit-only, as blatant goofs can easily go unnoticed, as they (somewhat ironically) will only be noticed by CONFIG_BUG=n builds. Cc: Yan Zhao Cc: Peter Zijlstra (Intel) Link: https://lore.kernel.org/all/adc1IrD8uqWdaOKv@yzhao56-desk.sh.intel.com Fixes: 5b472b6e5bd9 ("x86_64/bug: Implement __WARN_printf()") Fixes: 11bb4944f014 ("x86/bug: Implement WARN_ONCE()") Signed-off-by: Sean Christopherson --- arch/x86/include/asm/bug.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index 80c1696d8d59..bf3c802654d1 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -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) -- 2.54.0.545.g6539524ca2-goog