Hi Kees, I love your patch! Perhaps something to improve: [auto build test WARNING on kees/for-next/hardening] [also build test WARNING on next-20220928] [cannot apply to drm-tip/drm-tip drm-intel/for-linux-next drm-misc/drm-misc-next linus/master v6.0-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Kees-Cook/overflow-Introduce-overflows_type-and-castable_to_type/20220927-094847 base: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening config: i386-randconfig-a013 compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/ffc9129a19eb65b2d20780558b0c1af24d66434a git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Kees-Cook/overflow-Introduce-overflows_type-and-castable_to_type/20220927-094847 git checkout ffc9129a19eb65b2d20780558b0c1af24d66434a # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/gpu/drm/i915/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot All warnings (new ones prefixed by >>): drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: invalid operands to binary expression ('typeof (ext)' (aka 'struct i915_user_extension *') and 'unsigned int') overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:132:9: note: expanded from macro '__overflows_type_constexpr' (x) > type_max(typeof(T)) ? 1 : 0 \ ^~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:34:27: note: expanded from macro 'type_max' #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) ^~~~~~~~~~~~~~~~~~ include/linux/overflow.h:33:40: note: expanded from macro '__type_half_max' #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: invalid operands to binary expression ('typeof (ext)' (aka 'struct i915_user_extension *') and 'unsigned int') overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:132:9: note: expanded from macro '__overflows_type_constexpr' (x) > type_max(typeof(T)) ? 1 : 0 \ ^~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:34:53: note: expanded from macro 'type_max' #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) ^~~~~~~~~~~~~~~~~~ include/linux/overflow.h:33:40: note: expanded from macro '__type_half_max' #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> drivers/gpu/drm/i915/i915_user_extensions.c:54:7: warning: ordered comparison between pointer and integer ('u64' (aka 'unsigned long long') and 'typeof (ext)' (aka 'struct i915_user_extension *')) overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:132:7: note: expanded from macro '__overflows_type_constexpr' (x) > type_max(typeof(T)) ? 1 : 0 \ ~~~ ^ ~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: invalid operands to binary expression ('typeof (ext)' (aka 'struct i915_user_extension *') and 'unsigned int') overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:134:20: note: expanded from macro '__overflows_type_constexpr' (x) < 0 || (x) > type_max(typeof(T)) ? 1 : 0 \ ^~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:34:27: note: expanded from macro 'type_max' #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) ^~~~~~~~~~~~~~~~~~ include/linux/overflow.h:33:40: note: expanded from macro '__type_half_max' #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: invalid operands to binary expression ('typeof (ext)' (aka 'struct i915_user_extension *') and 'unsigned int') overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:134:20: note: expanded from macro '__overflows_type_constexpr' (x) < 0 || (x) > type_max(typeof(T)) ? 1 : 0 \ ^~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:34:53: note: expanded from macro 'type_max' #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) ^~~~~~~~~~~~~~~~~~ include/linux/overflow.h:33:40: note: expanded from macro '__type_half_max' #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> drivers/gpu/drm/i915/i915_user_extensions.c:54:7: warning: ordered comparison between pointer and integer ('u64' (aka 'unsigned long long') and 'typeof (ext)' (aka 'struct i915_user_extension *')) overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:134:18: note: expanded from macro '__overflows_type_constexpr' (x) < 0 || (x) > type_max(typeof(T)) ? 1 : 0 \ ~~~ ^ ~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: invalid operands to binary expression ('typeof (ext)' (aka 'struct i915_user_extension *') and 'unsigned int') overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:135:11: note: expanded from macro '__overflows_type_constexpr' : (x) < type_min(typeof(T)) || \ ^~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:35:30: note: expanded from macro 'type_min' #define type_min(T) ((T)((T)-type_max(T)-(T)1)) ^~~~~~~~~~~ include/linux/overflow.h:34:27: note: expanded from macro 'type_max' #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) ^~~~~~~~~~~~~~~~~~ include/linux/overflow.h:33:40: note: expanded from macro '__type_half_max' #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: invalid operands to binary expression ('typeof (ext)' (aka 'struct i915_user_extension *') and 'unsigned int') overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:135:11: note: expanded from macro '__overflows_type_constexpr' : (x) < type_min(typeof(T)) || \ ^~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:35:30: note: expanded from macro 'type_min' #define type_min(T) ((T)((T)-type_max(T)-(T)1)) ^~~~~~~~~~~ include/linux/overflow.h:34:53: note: expanded from macro 'type_max' #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) ^~~~~~~~~~~~~~~~~~ include/linux/overflow.h:33:40: note: expanded from macro '__type_half_max' #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: invalid argument type 'typeof (ext)' (aka 'struct i915_user_extension *') to unary expression overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:135:11: note: expanded from macro '__overflows_type_constexpr' : (x) < type_min(typeof(T)) || \ ^~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:35:29: note: expanded from macro 'type_min' #define type_min(T) ((T)((T)-type_max(T)-(T)1)) ^~~~~~~~~~~~ >> drivers/gpu/drm/i915/i915_user_extensions.c:54:7: warning: ordered comparison between pointer and integer ('u64' (aka 'unsigned long long') and 'typeof (ext)' (aka 'struct i915_user_extension *')) overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:135:9: note: expanded from macro '__overflows_type_constexpr' : (x) < type_min(typeof(T)) || \ ~~~ ^ ~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: invalid operands to binary expression ('typeof (ext)' (aka 'struct i915_user_extension *') and 'unsigned int') overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:136:11: note: expanded from macro '__overflows_type_constexpr' (x) > type_max(typeof(T)) ? 1 : 0) ^~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:34:27: note: expanded from macro 'type_max' #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) ^~~~~~~~~~~~~~~~~~ include/linux/overflow.h:33:40: note: expanded from macro '__type_half_max' #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: invalid operands to binary expression ('typeof (ext)' (aka 'struct i915_user_extension *') and 'unsigned int') overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:136:11: note: expanded from macro '__overflows_type_constexpr' (x) > type_max(typeof(T)) ? 1 : 0) ^~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:34:53: note: expanded from macro 'type_max' #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) ^~~~~~~~~~~~~~~~~~ include/linux/overflow.h:33:40: note: expanded from macro '__type_half_max' #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> drivers/gpu/drm/i915/i915_user_extensions.c:54:7: warning: ordered comparison between pointer and integer ('u64' (aka 'unsigned long long') and 'typeof (ext)' (aka 'struct i915_user_extension *')) overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:159:10: note: expanded from macro 'overflows_type' __overflows_type_constexpr(n, T), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:136:9: note: expanded from macro '__overflows_type_constexpr' (x) > type_max(typeof(T)) ? 1 : 0) ~~~ ^ ~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_user_extensions.c:54:7: error: operand argument to overflow builtin must be an integer ('typeof (ext)' (aka 'struct i915_user_extension *') invalid) overflows_type(next, ext)) ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:160:10: note: expanded from macro 'overflows_type' __overflows_type(n, T)) ^~~~~~~~~~~~~~~~~~~~~~ include/linux/overflow.h:140:26: note: expanded from macro '__overflows_type' check_add_overflow((x), v, &v); \ ^ include/linux/overflow.h:67:50: note: expanded from macro 'check_add_overflow' __must_check_overflow(__builtin_add_overflow(a, b, d)) ^ 4 warnings and 10 errors generated. vim +54 drivers/gpu/drm/i915/i915_user_extensions.c 9d1305ef80b95d Chris Wilson 2019-03-22 15 9d1305ef80b95d Chris Wilson 2019-03-22 16 int i915_user_extensions(struct i915_user_extension __user *ext, 9d1305ef80b95d Chris Wilson 2019-03-22 17 const i915_user_extension_fn *tbl, 9d1305ef80b95d Chris Wilson 2019-03-22 18 unsigned int count, 9d1305ef80b95d Chris Wilson 2019-03-22 19 void *data) 9d1305ef80b95d Chris Wilson 2019-03-22 20 { 9d1305ef80b95d Chris Wilson 2019-03-22 21 unsigned int stackdepth = 512; 9d1305ef80b95d Chris Wilson 2019-03-22 22 9d1305ef80b95d Chris Wilson 2019-03-22 23 while (ext) { 9d1305ef80b95d Chris Wilson 2019-03-22 24 int i, err; 9d1305ef80b95d Chris Wilson 2019-03-22 25 u32 name; 9d1305ef80b95d Chris Wilson 2019-03-22 26 u64 next; 9d1305ef80b95d Chris Wilson 2019-03-22 27 9d1305ef80b95d Chris Wilson 2019-03-22 28 if (!stackdepth--) /* recursion vs useful flexibility */ 9d1305ef80b95d Chris Wilson 2019-03-22 29 return -E2BIG; 9d1305ef80b95d Chris Wilson 2019-03-22 30 9d1305ef80b95d Chris Wilson 2019-03-22 31 err = check_user_mbz(&ext->flags); 9d1305ef80b95d Chris Wilson 2019-03-22 32 if (err) 9d1305ef80b95d Chris Wilson 2019-03-22 33 return err; 9d1305ef80b95d Chris Wilson 2019-03-22 34 9d1305ef80b95d Chris Wilson 2019-03-22 35 for (i = 0; i < ARRAY_SIZE(ext->rsvd); i++) { 9d1305ef80b95d Chris Wilson 2019-03-22 36 err = check_user_mbz(&ext->rsvd[i]); 9d1305ef80b95d Chris Wilson 2019-03-22 37 if (err) 9d1305ef80b95d Chris Wilson 2019-03-22 38 return err; 9d1305ef80b95d Chris Wilson 2019-03-22 39 } 9d1305ef80b95d Chris Wilson 2019-03-22 40 9d1305ef80b95d Chris Wilson 2019-03-22 41 if (get_user(name, &ext->name)) 9d1305ef80b95d Chris Wilson 2019-03-22 42 return -EFAULT; 9d1305ef80b95d Chris Wilson 2019-03-22 43 9d1305ef80b95d Chris Wilson 2019-03-22 44 err = -EINVAL; 9d1305ef80b95d Chris Wilson 2019-03-22 45 if (name < count) { 9d1305ef80b95d Chris Wilson 2019-03-22 46 name = array_index_nospec(name, count); 9d1305ef80b95d Chris Wilson 2019-03-22 47 if (tbl[name]) 9d1305ef80b95d Chris Wilson 2019-03-22 48 err = tbl[name](ext, data); 9d1305ef80b95d Chris Wilson 2019-03-22 49 } 9d1305ef80b95d Chris Wilson 2019-03-22 50 if (err) 9d1305ef80b95d Chris Wilson 2019-03-22 51 return err; 9d1305ef80b95d Chris Wilson 2019-03-22 52 9d1305ef80b95d Chris Wilson 2019-03-22 53 if (get_user(next, &ext->next_extension) || 9d1305ef80b95d Chris Wilson 2019-03-22 @54 overflows_type(next, ext)) -- 0-DAY CI Kernel Test Service https://01.org/lkp