Skip to content

Commit 10f4c9b

Browse files
vwaxIngo Molnar
authored andcommitted
x86/asm: Fix build of UML with KASAN
Building UML with KASAN fails since commit 69d4c0d ("entry, kasan, x86: Disallow overriding mem*() functions") with the following errors: $ tools/testing/kunit/kunit.py run --kconfig_add CONFIG_KASAN=y ... ld: mm/kasan/shadow.o: in function `memset': shadow.c:(.text+0x40): multiple definition of `memset'; arch/x86/lib/memset_64.o:(.noinstr.text+0x0): first defined here ld: mm/kasan/shadow.o: in function `memmove': shadow.c:(.text+0x90): multiple definition of `memmove'; arch/x86/lib/memmove_64.o:(.noinstr.text+0x0): first defined here ld: mm/kasan/shadow.o: in function `memcpy': shadow.c:(.text+0x110): multiple definition of `memcpy'; arch/x86/lib/memcpy_64.o:(.noinstr.text+0x0): first defined here UML does not use GENERIC_ENTRY and is still supposed to be allowed to override the mem*() functions, so use weak aliases in that case. Fixes: 69d4c0d ("entry, kasan, x86: Disallow overriding mem*() functions") Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lore.kernel.org/r/20230918-uml-kasan-v3-1-7ad6db477df6@axis.com
1 parent 34cf99c commit 10f4c9b

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

arch/x86/include/asm/linkage.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@
105105
CFI_POST_PADDING \
106106
SYM_FUNC_END(__cfi_##name)
107107

108+
/* UML needs to be able to override memcpy() and friends for KASAN. */
109+
#ifdef CONFIG_UML
110+
# define SYM_FUNC_ALIAS_MEMFUNC SYM_FUNC_ALIAS_WEAK
111+
#else
112+
# define SYM_FUNC_ALIAS_MEMFUNC SYM_FUNC_ALIAS
113+
#endif
114+
108115
/* SYM_TYPED_FUNC_START -- use for indirectly called globals, w/ CFI type */
109116
#define SYM_TYPED_FUNC_START(name) \
110117
SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_F_ALIGN) \

arch/x86/lib/memcpy_64.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ SYM_TYPED_FUNC_START(__memcpy)
4040
SYM_FUNC_END(__memcpy)
4141
EXPORT_SYMBOL(__memcpy)
4242

43-
SYM_FUNC_ALIAS(memcpy, __memcpy)
43+
SYM_FUNC_ALIAS_MEMFUNC(memcpy, __memcpy)
4444
EXPORT_SYMBOL(memcpy)
4545

4646
SYM_FUNC_START_LOCAL(memcpy_orig)

arch/x86/lib/memmove_64.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,5 @@ SYM_FUNC_START(__memmove)
212212
SYM_FUNC_END(__memmove)
213213
EXPORT_SYMBOL(__memmove)
214214

215-
SYM_FUNC_ALIAS(memmove, __memmove)
215+
SYM_FUNC_ALIAS_MEMFUNC(memmove, __memmove)
216216
EXPORT_SYMBOL(memmove)

arch/x86/lib/memset_64.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ SYM_FUNC_START(__memset)
4040
SYM_FUNC_END(__memset)
4141
EXPORT_SYMBOL(__memset)
4242

43-
SYM_FUNC_ALIAS(memset, __memset)
43+
SYM_FUNC_ALIAS_MEMFUNC(memset, __memset)
4444
EXPORT_SYMBOL(memset)
4545

4646
SYM_FUNC_START_LOCAL(memset_orig)

0 commit comments

Comments
 (0)