lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250320180926.4002817-7-andriy.shevchenko@linux.intel.com>
Date: Thu, 20 Mar 2025 20:04:27 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Petr Mladek <pmladek@...e.com>,
	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
	Christophe JAILLET <christophe.jaillet@...adoo.fr>,
	Kees Cook <kees@...nel.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	"Masami Hiramatsu (Google)" <mhiramat@...nel.org>,
	linux-kernel@...r.kernel.org,
	linux-hardening@...r.kernel.org,
	linux-trace-kernel@...r.kernel.org
Cc: John Ogness <john.ogness@...utronix.de>,
	Sergey Senozhatsky <senozhatsky@...omium.org>,
	Andy Shevchenko <andy@...nel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: [PATCH v1 6/6] vsnprintf: Mark va_format() with __printf() attribute

va_format() is using printf() type of format, and GCC compiler
(Debian 14.2.0-17) is not happy about this:

lib/vsprintf.c:1704:9: error: function ‘va_format’ might be a candidate for ‘gnu_print ’ format attribute [-Werror=suggest-attribute=format]

Fix the compilation errors (`make W=1` when CONFIG_WERROR=y, which is default)                                   by adding __printf() attribute. This, unfortunately, requires to reconsider
the type of the parameter used for that. That's why I added static_assert()
and used explicit casting. Any other solution I tried failed with the similar
or other error.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
---
 include/linux/printk.h | 5 ++++-
 lib/vsprintf.c         | 7 ++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 4217a9f412b2..182d48b4930f 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -2,12 +2,13 @@
 #ifndef __KERNEL_PRINTK__
 #define __KERNEL_PRINTK__
 
-#include <linux/stdarg.h>
 #include <linux/init.h>
 #include <linux/kern_levels.h>
 #include <linux/linkage.h>
 #include <linux/ratelimit_types.h>
 #include <linux/once_lite.h>
+#include <linux/stdarg.h>
+#include <linux/stddef.h>
 
 struct console;
 
@@ -87,6 +88,8 @@ struct va_format {
 	va_list *va;
 };
 
+static_assert(offsetof(struct va_format, fmt) == 0);
+
 /*
  * FW_BUG
  * Add this to a message where you are sure the firmware is buggy or behaves
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 8ebb5f866b08..ebb3c563a7ee 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1692,9 +1692,10 @@ char *escaped_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
 	return buf;
 }
 
-static char *va_format(char *buf, char *end, struct va_format *va_fmt,
-		       struct printf_spec spec, const char *fmt)
+static __printf(3, 0)
+char *va_format(char *buf, char *end, const char *fmt, struct printf_spec spec)
 {
+	struct va_format *va_fmt = (struct va_format *)fmt;
 	va_list va;
 
 	if (check_pointer(&buf, end, va_fmt, spec))
@@ -2462,7 +2463,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 	case 'U':
 		return uuid_string(buf, end, ptr, spec, fmt);
 	case 'V':
-		return va_format(buf, end, ptr, spec, fmt);
+		return va_format(buf, end, ptr, spec);
 	case 'K':
 		return restricted_pointer(buf, end, ptr, spec);
 	case 'N':
-- 
2.47.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ