-Wmacro-redefined in include/linux/fortify-string.h
Subsystems (4)
Hi all,
I am seeing the following set of warnings when building an x86_64 configuration that has CONFIG_FORTIFY_SOURCE=y and CONFIG_KMSAN=y:
In file included from scripts/mod/devicetable-offsets.c:3:
In file included from ./include/linux/mod_devicetable.h:13:
In file included from ./include/linux/uuid.h:12:
In file included from ./include/linux/string.h:253:
./include/linux/fortify-string.h:496:9: error: 'memcpy' macro redefined [-Werror,-Wmacro-redefined]
#define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \
^
./arch/x86/include/asm/string_64.h:17:9: note: previous definition is here
#define memcpy __msan_memcpy
^
In file included from scripts/mod/devicetable-offsets.c:3:
In file included from ./include/linux/mod_devicetable.h:13:
In file included from ./include/linux/uuid.h:12:
In file included from ./include/linux/string.h:253:
./include/linux/fortify-string.h:500:9: error: 'memmove' macro redefined [-Werror,-Wmacro-redefined]
#define memmove(p, q, s) __fortify_memcpy_chk(p, q, s, \
^
./arch/x86/include/asm/string_64.h:73:9: note: previous definition is here
#define memmove __msan_memmove
^2 errors generated.
I can see that commit ff901d80fff6 ("x86: kmsan: use __msan_ string functions where possible.") appears to include a fix up for this warning with memset() but not memcpy() or memmove(). If I apply a similar fix up like so:
include/linux/fortify-string.h +2 -0
@@ -493,6 +493,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size,* __struct_size() vs __member_size() must be captured here to avoid * evaluating argument side-effects further into the macro layers. */ +#ifndef CONFIG_KMSAN #define memcpy (p, q, s) __fortify_memcpy_chk(p, q, s, \ __struct_size(p), __struct_size(q), \ __member_size(p), __member_size(q), \
@@ -501,6 +502,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size, __struct_size(p), __struct_size(q), \ __member_size(p), __member_size(q), \ memmove) +#endif extern void *__real_memscan (void *,int ,__kernel_size_t )__RENAME (memscan); __FORTIFY_INLINE void *memscan(void * const POS0 p, int c, __kernel_size_t size)
Then the instances of -Wmacro-redefined disappear but the fortify tests no longer pass for somewhat obvious reasons:
warning: unsafe memcpy() usage lacked '__read_overflow2' symbol in lib/test_fortify/read_overflow2-memcpy.c
warning: unsafe memmove() usage lacked '__read_overflow2' symbol in lib/test_fortify/read_overflow2-memmove.c
warning: unsafe memcpy() usage lacked '__read_overflow2_field' symbol in lib/test_fortify/read_overflow2_field-memcpy.c
warning: unsafe memmove() usage lacked '__read_overflow2_field' symbol in lib/test_fortify/read_overflow2_field-memmove.c
warning: unsafe memcpy() usage lacked '__write_overflow' symbol in lib/test_fortify/write_overflow-memcpy.c
warning: unsafe memmove() usage lacked '__write_overflow' symbol in lib/test_fortify/write_overflow-memmove.c
warning: unsafe memset() usage lacked '__write_overflow' symbol in lib/test_fortify/write_overflow-memset.c
warning: unsafe memcpy() usage lacked '__write_overflow_field' symbol in lib/test_fortify/write_overflow_field-memcpy.c
warning: unsafe memmove() usage lacked '__write_overflow_field' symbol in lib/test_fortify/write_overflow_field-memmove.c
warning: unsafe memset() usage lacked '__write_overflow_field' symbol in lib/test_fortify/write_overflow_field-memset.c
Should CONFIG_KMSAN depend on CONFIG_FORTIFY_SOURCE=n like so? It seems like the two features are incompatible if I am reading ff901d80fff6 correctly.
lib/Kconfig.kmsan +1 -1
@@ -11,7 +11,7 @@ config HAVE_KMSAN_COMPILER config KMSAN bool "KMSAN: detector of uninitialized values use" depends on HAVE_ARCH_KMSAN && HAVE_KMSAN_COMPILER - depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN + depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN && !FORTIFY_SOURCE select STACKDEPOT select STACKDEPOT_ALWAYS_INIT help
or is there a different obvious fix that I am missing?
Cheers,
Nathan
Alexander Potapenko
maintainerQuoted 5 lines · Nathan Chancellor
Hi all,
I am seeing the following set of warnings when building an
x86_64configuration that hasCONFIG_FORTIFY_SOURCE=yandCONFIG_KMSAN=y:
I was also looking into this issue recently, because people start running into it: https://github.com/google/kmsan/issues/89
I have a solution that redefines __underlying_memXXX to __msan_memXXX under __SANITIZE_MEMORY__ in fortify-string.h and skips #define memXXX __msan_memXXX in string_64.h, making KMSAN kinda work with FORTIFY_SOURCE.
Dunno if that's necessary though: KMSAN is a debugging tool anyway, and supporting it in fortify-string.h sounds excessive.
So I'm fine with disabling FORTIFY_STRING under KMSAN, unless someone objects.
Quoted 80 lines
In file included from
scripts/mod/devicetable-offsets.c:3:
In file included from./include/linux/mod_devicetable.h:13:
In file included from./include/linux/uuid.h:12:
In file included from./include/linux/string.h:253:
./include/linux/fortify-string.h:496:9: error: 'memcpy' macro redefined [-Werror,-Wmacro-redefined]#define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \ ^ ./arch/x86/include/asm/string_64.h:17:9: note: previous definition is here #define memcpy __msan_memcpy ^ In file included from scripts/mod/devicetable-offsets.c:3: In file included from ./include/linux/mod_devicetable.h:13: In file included from ./include/linux/uuid.h:12: In file included from ./include/linux/string.h:253: ./include/linux/fortify-string.h:500:9: error: 'memmove' macro redefined [-Werror,-Wmacro-redefined] #define memmove(p, q, s) __fortify_memcpy_chk(p, q, s, \ ^ ./arch/x86/include/asm/string_64.h:73:9: note: previous definition is here #define memmove __msan_memmove ^2 errors generated.
I can see that commit
ff901d80fff6("x86: kmsan: use__msan_string functions where possible.") appears to include a fix up for this warning withmemset()but notmemcpy()ormemmove(). If I apply a similar fix up like so:include/linux/fortify-string.h +2
-0@@ -493,6 +493,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size,* __struct_size() vs __member_size() must be captured here to avoid * evaluating argument side-effects further into the macro layers. */ +#ifndef CONFIG_KMSAN #define memcpy (p, q, s) __fortify_memcpy_chk(p, q, s, \ __struct_size(p), __struct_size(q), \ __member_size(p), __member_size(q), \@@ -501,6 +502,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size, __struct_size(p), __struct_size(q), \ __member_size(p), __member_size(q), \ memmove) +#endif extern void *__real_memscan (void *,int ,__kernel_size_t )__RENAME (memscan); __FORTIFY_INLINE void *memscan(void * const POS0 p, int c, __kernel_size_t size)Then the instances of -Wmacro-redefined disappear but the fortify tests no longer pass for somewhat obvious reasons:
warning: unsafe
memcpy()usage lacked '__read_overflow2' symbol inlib/test_fortify/read_overflow2-memcpy.c
warning: unsafememmove()usage lacked '__read_overflow2' symbol inlib/test_fortify/read_overflow2-memmove.c
warning: unsafememcpy()usage lacked '__read_overflow2_field' symbol inlib/test_fortify/read_overflow2_field-memcpy.c
warning: unsafememmove()usage lacked '__read_overflow2_field' symbol inlib/test_fortify/read_overflow2_field-memmove.c
warning: unsafememcpy()usage lacked '__write_overflow' symbol inlib/test_fortify/write_overflow-memcpy.c
warning: unsafememmove()usage lacked '__write_overflow' symbol inlib/test_fortify/write_overflow-memmove.c
warning: unsafememset()usage lacked '__write_overflow' symbol inlib/test_fortify/write_overflow-memset.c
warning: unsafememcpy()usage lacked '__write_overflow_field' symbol inlib/test_fortify/write_overflow_field-memcpy.c
warning: unsafememmove()usage lacked '__write_overflow_field' symbol inlib/test_fortify/write_overflow_field-memmove.c
warning: unsafememset()usage lacked '__write_overflow_field' symbol inlib/test_fortify/write_overflow_field-memset.cShould
CONFIG_KMSANdepend onCONFIG_FORTIFY_SOURCE=nlike so? It seems like the two features are incompatible if I am readingff901d80fff6correctly.lib/Kconfig.kmsan +1
-1@@ -11,7 +11,7 @@ config HAVE_KMSAN_COMPILER config KMSAN bool "KMSAN: detector of uninitialized values use" depends on HAVE_ARCH_KMSAN && HAVE_KMSAN_COMPILER - depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN + depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN && !FORTIFY_SOURCE select STACKDEPOT select STACKDEPOT_ALWAYS_INIT help
Quoted 4 lines
or is there a different obvious fix that I am missing?
Cheers,
Nathan
--
Alexander Potapenko
Software Engineer
Google Germany GmbH
Erika-Mann-Straße, 33
80636 München
Geschäftsführer: Paul Manicle, Liana Sebastian
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Quoted 7 lines · Alexander Potapenko
Quoted 5 lines · Nathan Chancellor
Hi all,
I am seeing the following set of warnings when building an
x86_64configuration that hasCONFIG_FORTIFY_SOURCE=yandCONFIG_KMSAN=y:
Quoted 7 lines
I was also looking into this issue recently, because people start running into it: https://github.com/google/kmsan/issues/89
I have a solution that redefines
__underlying_memXXXto__msan_memXXXunder__SANITIZE_MEMORY__infortify-string.hand skips#define memXXX __msan_memXXXinstring_64.h, making KMSAN kinda work withFORTIFY_SOURCE.
Oh good!
Quoted 2 lines
Dunno if that's necessary though: KMSAN is a debugging tool anyway, and supporting it in
fortify-string.hsounds excessive.
I'd much prefer letting them still work together.
Signature · 1 line
Kees Cook
Quoted 83 lines · Nathan Chancellor
I am seeing the following set of warnings when building an
x86_64configuration that hasCONFIG_FORTIFY_SOURCE=yandCONFIG_KMSAN=y:In file included from
scripts/mod/devicetable-offsets.c:3:
In file included from./include/linux/mod_devicetable.h:13:
In file included from./include/linux/uuid.h:12:
In file included from./include/linux/string.h:253:
./include/linux/fortify-string.h:496:9: error: 'memcpy' macro redefined [-Werror,-Wmacro-redefined]#define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \ ^ ./arch/x86/include/asm/string_64.h:17:9: note: previous definition is here #define memcpy __msan_memcpy ^ In file included from scripts/mod/devicetable-offsets.c:3: In file included from ./include/linux/mod_devicetable.h:13: In file included from ./include/linux/uuid.h:12: In file included from ./include/linux/string.h:253: ./include/linux/fortify-string.h:500:9: error: 'memmove' macro redefined [-Werror,-Wmacro-redefined] #define memmove(p, q, s) __fortify_memcpy_chk(p, q, s, \ ^ ./arch/x86/include/asm/string_64.h:73:9: note: previous definition is here #define memmove __msan_memmove ^2 errors generated.
I can see that commit
ff901d80fff6("x86: kmsan: use__msan_string functions where possible.") appears to include a fix up for this warning withmemset()but notmemcpy()ormemmove(). If I apply a similar fix up like so:include/linux/fortify-string.h +2
-0@@ -493,6 +493,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size,* __struct_size() vs __member_size() must be captured here to avoid * evaluating argument side-effects further into the macro layers. */ +#ifndef CONFIG_KMSAN #define memcpy (p, q, s) __fortify_memcpy_chk(p, q, s, \ __struct_size(p), __struct_size(q), \ __member_size(p), __member_size(q), \@@ -501,6 +502,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size, __struct_size(p), __struct_size(q), \ __member_size(p), __member_size(q), \ memmove) +#endif extern void *__real_memscan (void *,int ,__kernel_size_t )__RENAME (memscan); __FORTIFY_INLINE void *memscan(void * const POS0 p, int c, __kernel_size_t size)Then the instances of -Wmacro-redefined disappear but the fortify tests no longer pass for somewhat obvious reasons:
warning: unsafe
memcpy()usage lacked '__read_overflow2' symbol inlib/test_fortify/read_overflow2-memcpy.c
warning: unsafememmove()usage lacked '__read_overflow2' symbol inlib/test_fortify/read_overflow2-memmove.c
warning: unsafememcpy()usage lacked '__read_overflow2_field' symbol inlib/test_fortify/read_overflow2_field-memcpy.c
warning: unsafememmove()usage lacked '__read_overflow2_field' symbol inlib/test_fortify/read_overflow2_field-memmove.c
warning: unsafememcpy()usage lacked '__write_overflow' symbol inlib/test_fortify/write_overflow-memcpy.c
warning: unsafememmove()usage lacked '__write_overflow' symbol inlib/test_fortify/write_overflow-memmove.c
warning: unsafememset()usage lacked '__write_overflow' symbol inlib/test_fortify/write_overflow-memset.c
warning: unsafememcpy()usage lacked '__write_overflow_field' symbol inlib/test_fortify/write_overflow_field-memcpy.c
warning: unsafememmove()usage lacked '__write_overflow_field' symbol inlib/test_fortify/write_overflow_field-memmove.c
warning: unsafememset()usage lacked '__write_overflow_field' symbol inlib/test_fortify/write_overflow_field-memset.cShould
CONFIG_KMSANdepend onCONFIG_FORTIFY_SOURCE=nlike so? It seems like the two features are incompatible if I am readingff901d80fff6correctly.lib/Kconfig.kmsan +1
-1@@ -11,7 +11,7 @@ config HAVE_KMSAN_COMPILER config KMSAN bool "KMSAN: detector of uninitialized values use" depends on HAVE_ARCH_KMSAN && HAVE_KMSAN_COMPILER - depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN + depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN && !FORTIFY_SOURCE select STACKDEPOT select STACKDEPOT_ALWAYS_INIT help
Quoted 1 line
or is there a different obvious fix that I am missing?
Hm, why can't KMSAN use the same thing KASAN does, and compose correctly with FORTIFY? (i.e. redefine the "__underlaying_mem*" macros?)
Signature · 1 line
Kees Cook