2023-11-30 04:03:29

by kernel test robot

[permalink] [raw]
Subject: include/linux/fortify-string.h:52:29: warning: '__builtin_strcpy' source argument is the same as destination

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 3b47bc037bd44f142ac09848e8d3ecccc726be99
commit: ba38961a069b0d8d03b53218a6c29d737577d448 um: Enable FORTIFY_SOURCE
date: 1 year, 3 months ago
config: um-randconfig-r034-20230830 (https://download.01.org/0day-ci/archive/20231130/[email protected]/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231130/[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
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

kernel/kallsyms.c:570:12: warning: no previous prototype for 'arch_get_kallsym' [-Wmissing-prototypes]
570 | int __weak arch_get_kallsym(unsigned int symnum, unsigned long *value,
| ^~~~~~~~~~~~~~~~
In file included from include/linux/string.h:253,
from include/linux/bitmap.h:11,
from include/linux/cpumask.h:12,
from include/linux/mm_types_task.h:14,
from include/linux/mm_types.h:5,
from include/linux/buildid.h:5,
from include/linux/kallsyms.h:10,
from kernel/kallsyms.c:15:
kernel/kallsyms.c: In function '__sprint_symbol.isra.0':
>> include/linux/fortify-string.h:52:29: warning: '__builtin_strcpy' source argument is the same as destination [-Wrestrict]
52 | #define __underlying_strcpy __builtin_strcpy
| ^
include/linux/fortify-string.h:567:10: note: in expansion of macro '__underlying_strcpy'
567 | return __underlying_strcpy(p, q);
| ^~~~~~~~~~~~~~~~~~~


vim +/__builtin_strcpy +52 include/linux/fortify-string.h

3009f891bb9f32 Kees Cook 2021-08-02 33
a28a6e860c6cf2 Francis Laniel 2021-02-25 34 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
a28a6e860c6cf2 Francis Laniel 2021-02-25 35 extern void *__underlying_memchr(const void *p, int c, __kernel_size_t size) __RENAME(memchr);
a28a6e860c6cf2 Francis Laniel 2021-02-25 36 extern int __underlying_memcmp(const void *p, const void *q, __kernel_size_t size) __RENAME(memcmp);
a28a6e860c6cf2 Francis Laniel 2021-02-25 37 extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t size) __RENAME(memcpy);
a28a6e860c6cf2 Francis Laniel 2021-02-25 38 extern void *__underlying_memmove(void *p, const void *q, __kernel_size_t size) __RENAME(memmove);
a28a6e860c6cf2 Francis Laniel 2021-02-25 39 extern void *__underlying_memset(void *p, int c, __kernel_size_t size) __RENAME(memset);
a28a6e860c6cf2 Francis Laniel 2021-02-25 40 extern char *__underlying_strcat(char *p, const char *q) __RENAME(strcat);
a28a6e860c6cf2 Francis Laniel 2021-02-25 41 extern char *__underlying_strcpy(char *p, const char *q) __RENAME(strcpy);
a28a6e860c6cf2 Francis Laniel 2021-02-25 42 extern __kernel_size_t __underlying_strlen(const char *p) __RENAME(strlen);
a28a6e860c6cf2 Francis Laniel 2021-02-25 43 extern char *__underlying_strncat(char *p, const char *q, __kernel_size_t count) __RENAME(strncat);
a28a6e860c6cf2 Francis Laniel 2021-02-25 44 extern char *__underlying_strncpy(char *p, const char *q, __kernel_size_t size) __RENAME(strncpy);
a28a6e860c6cf2 Francis Laniel 2021-02-25 45 #else
a28a6e860c6cf2 Francis Laniel 2021-02-25 46 #define __underlying_memchr __builtin_memchr
a28a6e860c6cf2 Francis Laniel 2021-02-25 47 #define __underlying_memcmp __builtin_memcmp
a28a6e860c6cf2 Francis Laniel 2021-02-25 48 #define __underlying_memcpy __builtin_memcpy
a28a6e860c6cf2 Francis Laniel 2021-02-25 49 #define __underlying_memmove __builtin_memmove
a28a6e860c6cf2 Francis Laniel 2021-02-25 50 #define __underlying_memset __builtin_memset
a28a6e860c6cf2 Francis Laniel 2021-02-25 51 #define __underlying_strcat __builtin_strcat
a28a6e860c6cf2 Francis Laniel 2021-02-25 @52 #define __underlying_strcpy __builtin_strcpy
a28a6e860c6cf2 Francis Laniel 2021-02-25 53 #define __underlying_strlen __builtin_strlen
a28a6e860c6cf2 Francis Laniel 2021-02-25 54 #define __underlying_strncat __builtin_strncat
a28a6e860c6cf2 Francis Laniel 2021-02-25 55 #define __underlying_strncpy __builtin_strncpy
a28a6e860c6cf2 Francis Laniel 2021-02-25 56 #endif
a28a6e860c6cf2 Francis Laniel 2021-02-25 57

:::::: The code at line 52 was first introduced by commit
:::::: a28a6e860c6cf231cf3c5171c75c342adcd00406 string.h: move fortified functions definitions in a dedicated header.

:::::: TO: Francis Laniel <[email protected]>
:::::: CC: Linus Torvalds <[email protected]>

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


2023-11-30 22:12:08

by Kees Cook

[permalink] [raw]
Subject: Re: include/linux/fortify-string.h:52:29: warning: '__builtin_strcpy' source argument is the same as destination

On Thu, Nov 30, 2023 at 12:02:50PM +0800, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 3b47bc037bd44f142ac09848e8d3ecccc726be99
> commit: ba38961a069b0d8d03b53218a6c29d737577d448 um: Enable FORTIFY_SOURCE
> date: 1 year, 3 months ago
> config: um-randconfig-r034-20230830 (https://download.01.org/0day-ci/archive/20231130/[email protected]/config)
> compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231130/[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
> | Reported-by: kernel test robot <[email protected]>
> | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>
> [...]
> kernel/kallsyms.c: In function '__sprint_symbol.isra.0':
> >> include/linux/fortify-string.h:52:29: warning: '__builtin_strcpy' source argument is the same as destination [-Wrestrict]
> 52 | #define __underlying_strcpy __builtin_strcpy
> | ^
> include/linux/fortify-string.h:567:10: note: in expansion of macro '__underlying_strcpy'
> 567 | return __underlying_strcpy(p, q);
> | ^~~~~~~~~~~~~~~~~~~

The only strcpy() in __sprint_symbol() is:

if (name != buffer)
strcpy(buffer, name);

Which is explicitly not the same address...

This appears to be a GCC 9 false positive, maybe?

--
Kees Cook

2023-12-20 06:25:38

by kernel test robot

[permalink] [raw]
Subject: Re: include/linux/fortify-string.h:52:29: warning: '__builtin_strcpy' source argument is the same as destination

Hi Kees,

On Thu, Nov 30, 2023 at 02:11:54PM -0800, Kees Cook wrote:
> On Thu, Nov 30, 2023 at 12:02:50PM +0800, kernel test robot wrote:
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head: 3b47bc037bd44f142ac09848e8d3ecccc726be99
> > commit: ba38961a069b0d8d03b53218a6c29d737577d448 um: Enable FORTIFY_SOURCE
> > date: 1 year, 3 months ago
> > config: um-randconfig-r034-20230830 (https://download.01.org/0day-ci/archive/20231130/[email protected]/config)
> > compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231130/[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
> > | Reported-by: kernel test robot <[email protected]>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
> >
> > [...]
> > kernel/kallsyms.c: In function '__sprint_symbol.isra.0':
> > >> include/linux/fortify-string.h:52:29: warning: '__builtin_strcpy' source argument is the same as destination [-Wrestrict]
> > 52 | #define __underlying_strcpy __builtin_strcpy
> > | ^
> > include/linux/fortify-string.h:567:10: note: in expansion of macro '__underlying_strcpy'
> > 567 | return __underlying_strcpy(p, q);
> > | ^~~~~~~~~~~~~~~~~~~
>
> The only strcpy() in __sprint_symbol() is:
>
> if (name != buffer)
> strcpy(buffer, name);
>
> Which is explicitly not the same address...
>
> This appears to be a GCC 9 false positive, maybe?

Sorry for our late reply. We tested this with various versions of gcc,
and this error disappeared when building with GCC 10 and 11, so it is
very likely to be a GCC 9 false positive. We will configure the bot to
use compilers newer than GCC 9 to test um arch.

Thanks,
Yujie

2023-12-20 06:47:19

by kernel test robot

[permalink] [raw]
Subject: Re: include/linux/fortify-string.h:52:29: warning: '__builtin_strcpy' source argument is the same as destination

On Wed, Dec 20, 2023 at 02:20:52PM +0800, Yujie Liu wrote:
> Hi Kees,
>
> On Thu, Nov 30, 2023 at 02:11:54PM -0800, Kees Cook wrote:
> > On Thu, Nov 30, 2023 at 12:02:50PM +0800, kernel test robot wrote:
> > > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > > head: 3b47bc037bd44f142ac09848e8d3ecccc726be99
> > > commit: ba38961a069b0d8d03b53218a6c29d737577d448 um: Enable FORTIFY_SOURCE
> > > date: 1 year, 3 months ago
> > > config: um-randconfig-r034-20230830 (https://download.01.org/0day-ci/archive/20231130/[email protected]/config)
> > > compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> > > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231130/[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
> > > | Reported-by: kernel test robot <[email protected]>
> > > | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
> > >
> > > [...]
> > > kernel/kallsyms.c: In function '__sprint_symbol.isra.0':
> > > >> include/linux/fortify-string.h:52:29: warning: '__builtin_strcpy' source argument is the same as destination [-Wrestrict]
> > > 52 | #define __underlying_strcpy __builtin_strcpy
> > > | ^
> > > include/linux/fortify-string.h:567:10: note: in expansion of macro '__underlying_strcpy'
> > > 567 | return __underlying_strcpy(p, q);
> > > | ^~~~~~~~~~~~~~~~~~~
> >
> > The only strcpy() in __sprint_symbol() is:
> >
> > if (name != buffer)
> > strcpy(buffer, name);
> >
> > Which is explicitly not the same address...
> >
> > This appears to be a GCC 9 false positive, maybe?
>
> Sorry for our late reply. We tested this with various versions of gcc,
> and this error disappeared when building with GCC 10 and 11, so it is
> very likely to be a GCC 9 false positive. We will configure the bot to
> use compilers newer than GCC 9 to test um arch.

Sorry, we will keep testing um with GCC 9 and configure the bot to
ignore this specific warning.