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>] [day] [month] [year] [list]
Message-Id: <20260116-printf-kunit-printf-attr-v2-1-3dd7fefc3207@kernel.org>
Date: Fri, 16 Jan 2026 11:27:03 -0500
From: Tamir Duberstein <tamird@...nel.org>
To: Petr Mladek <pmladek@...e.com>, Steven Rostedt <rostedt@...dmis.org>, 
 Andy Shevchenko <andriy.shevchenko@...ux.intel.com>, 
 Rasmus Villemoes <linux@...musvillemoes.dk>, 
 Sergey Senozhatsky <senozhatsky@...omium.org>, 
 Nathan Chancellor <nathan@...nel.org>, 
 Nick Desaulniers <nick.desaulniers+lkml@...il.com>, 
 Bill Wendling <morbo@...gle.com>, Justin Stitt <justinstitt@...gle.com>
Cc: Kees Cook <kees@...nel.org>, linux-kernel@...r.kernel.org, 
 oe-kbuild-all@...ts.linux.dev, llvm@...ts.linux.dev, 
 kernel test robot <lkp@...el.com>, Tamir Duberstein <tamird@...nel.org>
Subject: [PATCH v2] printf: convert test_hashed into macro

This allows the compiler to check the arguments against the __printf
attribute on __test. This produces better diagnostics when incorrect
inputs are passed.

Reported-by: kernel test robot <lkp@...el.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202512061600.89CKQ3ag-lkp@intel.com/
Signed-off-by: Tamir Duberstein <tamird@...nel.org>
---
Changes in v2:
- Convert test_hashed to macro rather than try to annotate it in a way
  that is compatible with both clang and gcc.
- Link to v1: https://patch.msgid.link/20251206-printf-kunit-printf-attr-v1-1-1682808b51d0@gmail.com
---
 lib/tests/printf_kunit.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c
index 7617e5b8b02c..1d96cea8af65 100644
--- a/lib/tests/printf_kunit.c
+++ b/lib/tests/printf_kunit.c
@@ -266,15 +266,17 @@ hash_pointer(struct kunit *kunittest)
 	KUNIT_EXPECT_MEMNEQ(kunittest, buf, PTR_STR, PTR_WIDTH);
 }
 
-static void
-test_hashed(struct kunit *kunittest, const char *fmt, const void *p)
-{
-	char buf[PLAIN_BUF_SIZE];
-
-	plain_hash_to_buffer(kunittest, p, buf, PLAIN_BUF_SIZE);
-
-	test(buf, fmt, p);
-}
+/*
+ * This is a macro so that the compiler can compare its arguments to the
+ * __printf attribute on __test. This cannot be a function with a __printf
+ * attribute because GCC requires __printf functions to be variadic.
+ */
+#define test_hashed(kunittest, fmt, p)                                   \
+	do {                                                             \
+		char buf[PLAIN_BUF_SIZE];                                \
+		plain_hash_to_buffer(kunittest, p, buf, PLAIN_BUF_SIZE); \
+		test(buf, fmt, p);                                       \
+	} while (0)
 
 /*
  * NULL pointers aren't hashed.

---
base-commit: 983d014aafb14ee5e4915465bf8948e8f3a723b5
change-id: 20251206-printf-kunit-printf-attr-19369fc57bf0

Best regards,
--  
Tamir Duberstein <tamird@...nel.org>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ