mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* include/linux/fortify-string.h:293:25: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()?
@ 2025-01-21  5:30 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2025-01-21  5:30 UTC (permalink / raw)
  To: Kees Cook; +Cc: oe-kbuild-all, linux-kernel

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   3d3a9c8b89d4f8a3785e06ffd15405c670696f02
commit: ba38961a069b0d8d03b53218a6c29d737577d448 um: Enable FORTIFY_SOURCE
date:   2 years, 4 months ago
config: um-randconfig-r133-20240603 (https://download.01.org/0day-ci/archive/20250121/202501211321.ZolvnwaP-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250121/202501211321.ZolvnwaP-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501211321.ZolvnwaP-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/string.h:253,
                    from include/linux/bitmap.h:11,
                    from include/linux/cpumask.h:12,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/spinlock.h:62,
                    from include/linux/mmzone.h:8,
                    from include/linux/gfp.h:7,
                    from include/linux/slab.h:15,
                    from fs/ocfs2/dlmglue.c:11:
   In function 'fortify_memset_chk',
       inlined from 'ocfs2_lock_res_free' at fs/ocfs2/dlmglue.c:790:2:
>> include/linux/fortify-string.h:293:25: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
     293 |                         __write_overflow_field(p_size_field, size);
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/__write_overflow_field +293 include/linux/fortify-string.h

a28a6e860c6cf2 Francis Laniel 2021-02-25  275  
28e77cc1c06866 Kees Cook      2021-06-16  276  __FORTIFY_INLINE void fortify_memset_chk(__kernel_size_t size,
28e77cc1c06866 Kees Cook      2021-06-16  277  					 const size_t p_size,
28e77cc1c06866 Kees Cook      2021-06-16  278  					 const size_t p_size_field)
a28a6e860c6cf2 Francis Laniel 2021-02-25  279  {
28e77cc1c06866 Kees Cook      2021-06-16  280  	if (__builtin_constant_p(size)) {
28e77cc1c06866 Kees Cook      2021-06-16  281  		/*
28e77cc1c06866 Kees Cook      2021-06-16  282  		 * Length argument is a constant expression, so we
28e77cc1c06866 Kees Cook      2021-06-16  283  		 * can perform compile-time bounds checking where
28e77cc1c06866 Kees Cook      2021-06-16  284  		 * buffer sizes are known.
28e77cc1c06866 Kees Cook      2021-06-16  285  		 */
a28a6e860c6cf2 Francis Laniel 2021-02-25  286  
28e77cc1c06866 Kees Cook      2021-06-16  287  		/* Error when size is larger than enclosing struct. */
28e77cc1c06866 Kees Cook      2021-06-16  288  		if (p_size > p_size_field && p_size < size)
a28a6e860c6cf2 Francis Laniel 2021-02-25  289  			__write_overflow();
28e77cc1c06866 Kees Cook      2021-06-16  290  
28e77cc1c06866 Kees Cook      2021-06-16  291  		/* Warn when write size is larger than dest field. */
28e77cc1c06866 Kees Cook      2021-06-16  292  		if (p_size_field < size)
28e77cc1c06866 Kees Cook      2021-06-16 @293  			__write_overflow_field(p_size_field, size);
a28a6e860c6cf2 Francis Laniel 2021-02-25  294  	}
28e77cc1c06866 Kees Cook      2021-06-16  295  	/*
28e77cc1c06866 Kees Cook      2021-06-16  296  	 * At this point, length argument may not be a constant expression,
28e77cc1c06866 Kees Cook      2021-06-16  297  	 * so run-time bounds checking can be done where buffer sizes are
28e77cc1c06866 Kees Cook      2021-06-16  298  	 * known. (This is not an "else" because the above checks may only
28e77cc1c06866 Kees Cook      2021-06-16  299  	 * be compile-time warnings, and we want to still warn for run-time
28e77cc1c06866 Kees Cook      2021-06-16  300  	 * overflows.)
28e77cc1c06866 Kees Cook      2021-06-16  301  	 */
28e77cc1c06866 Kees Cook      2021-06-16  302  
28e77cc1c06866 Kees Cook      2021-06-16  303  	/*
28e77cc1c06866 Kees Cook      2021-06-16  304  	 * Always stop accesses beyond the struct that contains the
28e77cc1c06866 Kees Cook      2021-06-16  305  	 * field, when the buffer's remaining size is known.
311fb40aa0569a Kees Cook      2022-09-02  306  	 * (The SIZE_MAX test is to optimize away checks where the buffer
28e77cc1c06866 Kees Cook      2021-06-16  307  	 * lengths are unknown.)
28e77cc1c06866 Kees Cook      2021-06-16  308  	 */
311fb40aa0569a Kees Cook      2022-09-02  309  	if (p_size != SIZE_MAX && p_size < size)
28e77cc1c06866 Kees Cook      2021-06-16  310  		fortify_panic("memset");
28e77cc1c06866 Kees Cook      2021-06-16  311  }
28e77cc1c06866 Kees Cook      2021-06-16  312  

:::::: The code at line 293 was first introduced by commit
:::::: 28e77cc1c0686621a4d416f599cee5ab369daa0a fortify: Detect struct member overflows in memset() at compile-time

:::::: TO: Kees Cook <keescook@chromium.org>
:::::: CC: Kees Cook <keescook@chromium.org>

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-21  5:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-21  5:30 include/linux/fortify-string.h:293:25: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®