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: <87v7h23cb0.ffs@tglx>
Date: Thu, 15 Jan 2026 20:28:51 +0100
From: Thomas Gleixner <tglx@...nel.org>
To: kernel test robot <lkp@...el.com>, Ian Rogers <irogers@...gle.com>
Cc: oe-kbuild-all@...ts.linux.dev, linux-kernel@...r.kernel.org,
 x86@...nel.org, sparse@...isli.org, linux-sparse@...r.kernel.org, Peter
 Zijlstra <peterz@...radead.org>, Marco Elver <elver@...gle.com>
Subject: Re: [tip:timers/vdso 12/14] net/rds/ib_cm.c:96:35: sparse: sparse:
 incorrect type in argument 1 (different modifiers)

On Thu, Jan 15 2026 at 00:36, kernel test robot wrote:

Cc+ sparse folks.

> sparse warnings: (new ones prefixed by >>)
>>> net/rds/ib_cm.c:96:35: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected void * @@     got restricted __be64 const * @@
>    net/rds/ib_cm.c:96:35: sparse:     expected void *
>    net/rds/ib_cm.c:96:35: sparse:     got restricted __be64 const *
>    net/rds/ib_cm.c:103:27: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected void * @@     got restricted __be64 const * @@
>    net/rds/ib_cm.c:103:27: sparse:     expected void *
>    net/rds/ib_cm.c:103:27: sparse:     got restricted __be64 const *

After staring a while at it, it turns out that get_unaligned_t(), which
uses __unqual_scalar_typeof() to get an unqualified type makes sparse
unhappy when the data type is __be64 (or any other __beNN variant).

__beNN is annotated with __attribute__((bitwise)) when sparse is invoked
(#ifdef CHECKER). That allows sparse to detect incompatible math
operations with __beNN variables.

That annotation also causes the type comparison in the sparse _Generic()
evaluation to fail so that it ends up with the default, i.e. the
original qualified type of a 'const __beNN' pointer. That then ends up as
the first pointer argument to builtin_memcpy(), which obviously causes
the above sparse warnings.

The easiest solution would be to force cast the pointer to void * when
CHECKER is defined, but that reduces coverage.

I've come up with the below, but it's clearly a hack... __CAST_SPARSE()
is required as sparse otherwise complains about storing __u64 in __be64.

Thanks,

        tglx
---
 include/linux/compiler_types.h |   10 ++++++++++
 include/vdso/unaligned.h       |   16 +++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -577,6 +577,15 @@ struct ftrace_likely_data {
 		unsigned type:	(unsigned type)0,			\
 		signed type:	(signed type)0
 
+#ifdef __CHECKER__
+#define __be_types_expr_cases()						\
+	__be16: (__u16)0,						\
+	__be32: (__u32)0,						\
+	__be64: (__u64)0,
+#else
+#define __be_types_expr_cases()
+#endif
+
 #define __unqual_scalar_typeof(x) typeof(				\
 		_Generic((x),						\
 			 char:	(char)0,				\
@@ -585,6 +594,7 @@ struct ftrace_likely_data {
 			 __scalar_type_to_expr_cases(int),		\
 			 __scalar_type_to_expr_cases(long),		\
 			 __scalar_type_to_expr_cases(long long),	\
+			 __be_types_expr_cases()			\
 			 default: (x)))
 
 /* Is this type a native word size -- useful for atomic operations */
--- a/include/vdso/unaligned.h
+++ b/include/vdso/unaligned.h
@@ -4,6 +4,12 @@
 
 #include <linux/compiler_types.h>
 
+#ifdef __CHECKER__
+#define __CAST_SPARSE(type) (type __force)
+#else
+#define __CAST_SPARSE(type)
+#endif
+
 /**
  * __get_unaligned_t - read an unaligned value from memory.
  * @type:	the type to load from the pointer.
@@ -17,12 +23,12 @@
  * expression rather than type, a pointer is used to avoid warnings about mixing
  * the use of 0 and NULL. The void* cast silences ubsan warnings.
  */
-#define __get_unaligned_t(type, ptr) ({					\
-	type *__get_unaligned_ctrl_type __always_unused = NULL;		\
+#define __get_unaligned_t(type, ptr) ({						\
+	type *__get_unaligned_ctrl_type __always_unused = NULL;			\
 	__unqual_scalar_typeof(*__get_unaligned_ctrl_type) __get_unaligned_val; \
-	__builtin_memcpy(&__get_unaligned_val, (void *)(ptr),		\
-			 sizeof(__get_unaligned_val));			\
-	__get_unaligned_val;						\
+	__builtin_memcpy(&__get_unaligned_val, (void *)(ptr),			\
+			 sizeof(__get_unaligned_val));				\
+	__CAST_SPARSE(type) __get_unaligned_val;				\
 })
 
 /**




    

      

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ