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] [day] [month] [year] [list]
Message-ID: <20250723140301.277089-1-rakagunarto@gmail.com>
Date: Wed, 23 Jul 2025 15:03:01 +0100
From: Raka Gunarto <rakagunarto@...il.com>
To: linux-kernel@...r.kernel.org
Cc: Raka Gunarto <rakagunarto@...il.com>
Subject: [RFC PATCH 1/1] compiler_types.h: introduce ASSUME_NONNULL macro for static analysis

This macro suppresses false positives for Clang's static analyzer
by asserting a pointer is invariably non-null. It has no side-effects
in normal conditions by including a guard to check for the
analyzer's presence.

Signed-off-by: Raka Gunarto <rakagunarto@...il.com>
---
 include/linux/compiler-clang.h | 10 ++++++++++
 include/linux/compiler_types.h |  5 +++++
 2 files changed, 15 insertions(+)

diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index 4fc8e26914ad..c25bb1a855c4 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -136,3 +136,13 @@
  * rely on the auto-detected CONFIG_CC_HAS_TYPEOF_UNQUAL.
  */
 #define CC_HAS_TYPEOF_UNQUAL (__clang_major__ >= 19)
+
+/*
+ * Tell static code analysis tools that this pointer is
+ * invariably non-null
+ */
+#if defined(__clang_analyzer__) && __has_builtin(__builtin_assume)
+  #define ASSUME_NONNULL(ptr) do { __builtin_assume((ptr) != NULL); } while (0)
+#else
+  #define ASSUME_NONNULL(ptr) do { } while (0)
+#endif
\ No newline at end of file
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 2b77d12e07b2..26126fd915be 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -594,4 +594,9 @@ struct ftrace_likely_data {
 #define __diag_ignore_all(option, comment)
 #endif

+/* Provide no-op for non-null static code analysis hint if unsupported */
+#ifndef ASSUME_NONNULL
+# define ASSUME_NONNULL(ptr) do { } while (0)
+#endif
+
 #endif /* __LINUX_COMPILER_TYPES_H */
--
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ