include/vdso/unaligned.h:23:9: warning: '__builtin_memcpy' reading 4 bytes from a region of size 0
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: bfe62a454542cfad3379f6ef5680b125f41e20f4 commit: a339671db64b12bb02492557d2b0658811286277 vdso: Switch get/put_unaligned() from packed struct to memcpy() date: 3 months ago config: mips-randconfig-r111-20260406 (https://download.01.org/0day-ci/archive/20260407/[email protected]/config) compiler: mips-linux-gcc (GCC) 13.4.0 sparse: v0.6.5-rc1 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260407/[email protected]/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
| Fixes: a339671db64b ("vdso: Switch get/put_unaligned() from packed struct to memcpy()")
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
In file included from include/linux/byteorder/little_endian.h:5,
from arch/mips/include/uapi/asm/byteorder.h:15,
from arch/mips/include/asm/bitops.h:21,
from include/linux/bitops.h:67,
from include/linux/kernel.h:23,
from arch/mips/boot/compressed/decompress.c:14:
In function 'get_unaligned_le32',
inlined from 'decompress_kernel' at arch/mips/boot/compressed/decompress.c:113:16:
>> include/vdso/unaligned.h:23:9: warning: '__builtin_memcpy' reading 4 bytes from a region of size 0 [-Wstringop-overread]
23 | __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 | sizeof(__get_unaligned_val)); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/uapi/linux/byteorder/little_endian.h:35:51: note: in definition of macro '__le32_to_cpu'
35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
| ^
include/linux/unaligned.h:23:28: note: in expansion of macro '__get_unaligned_t'
23 | return le32_to_cpu(__get_unaligned_t(__le32, p));
| ^~~~~~~~~~~~~~~~~
In file included from arch/mips/boot/compressed/decompress.c:22:
arch/mips/boot/compressed/decompress.h: In function 'decompress_kernel':
arch/mips/boot/compressed/decompress.h:6:39: note: at offset -4 into source object '__image_end' of size [0, 2147483647]
6 | extern unsigned char __image_begin[], __image_end[];
| ^~~~~~~~~~~vim +/__builtin_memcpy +23 include/vdso/unaligned.h
6
7 /**
8 * __get_unaligned_t - read an unaligned value from memory.
9 * @type: the type to load from the pointer.
10 * @ptr: the pointer to load from.
11 *
12 * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
13 * from approaches like type punning that require -fno-strict-aliasing in order
14 * to be correct. As type may be const, use __unqual_scalar_typeof to map to a
15 * non-const type - you can't memcpy into a const type. The
16 * __get_unaligned_ctrl_type gives __unqual_scalar_typeof its required
17 * expression rather than type, a pointer is used to avoid warnings about mixing
18 * the use of 0 and NULL. The void* cast silences ubsan warnings.
19 */
20 #define __get_unaligned_t(type, ptr) ({ \
21 type *__get_unaligned_ctrl_type __always_unused = NULL; \
22 __unqual_scalar_typeof(*__get_unaligned_ctrl_type) __get_unaligned_val; \
> 23 __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \
24 sizeof(__get_unaligned_val)); \
25 __get_unaligned_val; \
26 })
27 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 27 lines · kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: bfe62a454542cfad3379f6ef5680b125f41e20f4 commit: a339671db64b12bb02492557d2b0658811286277 vdso: Switch get/put_unaligned() from packed struct to memcpy() date: 3 months ago config: mips-randconfig-r111-20260406 (https://download.01.org/0day-ci/archive/20260407/[email protected]/config) compiler: mips-linux-gcc (GCC) 13.4.0 sparse: v0.6.5-rc1 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260407/[email protected]/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
| Fixes: a339671db64b ("vdso: Switch get/put_unaligned() from packed struct to memcpy()") | Reported-by: kernel test robot <[email protected]> | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
In file included from
include/linux/byteorder/little_endian.h:5,
fromarch/mips/include/uapi/asm/byteorder.h:15,
fromarch/mips/include/asm/bitops.h:21,
frominclude/linux/bitops.h:67,
frominclude/linux/kernel.h:23,
fromarch/mips/boot/compressed/decompress.c:14:
In function 'get_unaligned_le32',
inlined from 'decompress_kernel' atarch/mips/boot/compressed/decompress.c:113:16:Quoted 1 line
Quoted 1 line
include/vdso/unaligned.h:23:9: warning: '__builtin_memcpy' reading 4 bytes from a region of size 0 [-Wstringop-overread]
Quoted 15 lines
23 | __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 | sizeof(__get_unaligned_val)); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/uapi/linux/byteorder/little_endian.h:35:51: note: in definition of macro '__le32_to_cpu'
35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
| ^
include/linux/unaligned.h:23:28: note: in expansion of macro '__get_unaligned_t'
23 | return le32_to_cpu(__get_unaligned_t(__le32, p));
| ^~~~~~~~~~~~~~~~~
In file included from arch/mips/boot/compressed/decompress.c:22:
arch/mips/boot/compressed/decompress.h: In function 'decompress_kernel':
arch/mips/boot/compressed/decompress.h:6:39: note: at offset -4 into source object '__image_end' of size [0, 2147483647]
6 | extern unsigned char __image_begin[], __image_end[];
| ^~~~~~~~~~~I wonder if in:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/mips/boot/compressed/decompress.c#n113
``` image_size = get_unaligned_le32((void *)__image_end - 4); ``` would be better as: ``` image_size = get_unaligned_le32((void *)__image_begin + zimage_size - 4); ```
so that the code isn't negatively indexing an array.
Thanks,
Ian
Quoted 29 lines
vim +/__builtin_memcpy +23
include/vdso/unaligned.h6
7 /**
8 *__get_unaligned_t- read an unaligned value from memory.
9 * @type: the type to load from the pointer.
10 * @ptr: the pointer to load from.
11 *
12 * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
13 * from approaches like type punning that require -fno-strict-aliasing in order
14 * to be correct. As type may be const, use__unqual_scalar_typeofto map to a
15 * non-const type - you can't memcpy into a const type. The
16 *__get_unaligned_ctrl_typegives__unqual_scalar_typeofits required
17 * expression rather than type, a pointer is used to avoid warnings about mixing
18 * the use of 0 and NULL. The void* cast silences ubsan warnings.
19 */
20 #define__get_unaligned_t(type, ptr)({ \
21 type*__get_unaligned_ctrl_type__always_unused= NULL; \
22__unqual_scalar_typeof(*__get_unaligned_ctrl_type)__get_unaligned_val; \Quoted 1 line
23 __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \
24 sizeof(__get_unaligned_val)); \ 25 __get_unaligned_val; \ 26 }) 27--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki