2023-06-09 11:51:08

by Vincent Whitchurch

[permalink] [raw]
Subject: [PATCH] x86: Fix build of UML with KASAN

Building UML with KASAN fails since commit 69d4c0d32186 ("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

If I'm reading that commit right, the !GENERIC_ENTRY case is still
supposed to be allowed to override the mem*() functions, so use weak
aliases in that case.

Fixes: 69d4c0d32186 ("entry, kasan, x86: Disallow overriding mem*() functions")
Signed-off-by: Vincent Whitchurch <[email protected]>
---
arch/x86/lib/memcpy_64.S | 4 ++++
arch/x86/lib/memmove_64.S | 4 ++++
arch/x86/lib/memset_64.S | 4 ++++
3 files changed, 12 insertions(+)

diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
index 8f95fb267caa7..5dc265b36ef0b 100644
--- a/arch/x86/lib/memcpy_64.S
+++ b/arch/x86/lib/memcpy_64.S
@@ -40,7 +40,11 @@ SYM_TYPED_FUNC_START(__memcpy)
SYM_FUNC_END(__memcpy)
EXPORT_SYMBOL(__memcpy)

+#ifdef CONFIG_GENERIC_ENTRY
SYM_FUNC_ALIAS(memcpy, __memcpy)
+#else
+SYM_FUNC_ALIAS_WEAK(memcpy, __memcpy)
+#endif
EXPORT_SYMBOL(memcpy)

SYM_FUNC_START_LOCAL(memcpy_orig)
diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
index 02661861e5dd9..3b1a02357fb29 100644
--- a/arch/x86/lib/memmove_64.S
+++ b/arch/x86/lib/memmove_64.S
@@ -215,5 +215,9 @@ SYM_FUNC_START(__memmove)
SYM_FUNC_END(__memmove)
EXPORT_SYMBOL(__memmove)

+#ifdef CONFIG_GENERIC_ENTRY
SYM_FUNC_ALIAS(memmove, __memmove)
+#else
+SYM_FUNC_ALIAS_WEAK(memmove, __memmove)
+#endif
EXPORT_SYMBOL(memmove)
diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
index 7c59a704c4584..fe27538a355db 100644
--- a/arch/x86/lib/memset_64.S
+++ b/arch/x86/lib/memset_64.S
@@ -40,7 +40,11 @@ SYM_FUNC_START(__memset)
SYM_FUNC_END(__memset)
EXPORT_SYMBOL(__memset)

+#ifdef CONFIG_GENERIC_ENTRY
SYM_FUNC_ALIAS(memset, __memset)
+#else
+SYM_FUNC_ALIAS_WEAK(memset, __memset)
+#endif
EXPORT_SYMBOL(memset)

SYM_FUNC_START_LOCAL(memset_orig)

---
base-commit: 9561de3a55bed6bdd44a12820ba81ec416e705a7
change-id: 20230609-uml-kasan-2392dd4c3858

Best regards,
--
Vincent Whitchurch <[email protected]>



2023-06-10 08:42:41

by David Gow

[permalink] [raw]
Subject: Re: [PATCH] x86: Fix build of UML with KASAN

On Fri, 9 Jun 2023 at 19:19, Vincent Whitchurch
<[email protected]> wrote:
>
> Building UML with KASAN fails since commit 69d4c0d32186 ("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
>
> If I'm reading that commit right, the !GENERIC_ENTRY case is still
> supposed to be allowed to override the mem*() functions, so use weak
> aliases in that case.
>
> Fixes: 69d4c0d32186 ("entry, kasan, x86: Disallow overriding mem*() functions")
> Signed-off-by: Vincent Whitchurch <[email protected]>
> ---

Thanks: I stumbled into this the other day and ran out of time to debug it.

I've tested that it works here.

Tested-by: David Gow <[email protected]>

Cheers,
-- David

> arch/x86/lib/memcpy_64.S | 4 ++++
> arch/x86/lib/memmove_64.S | 4 ++++
> arch/x86/lib/memset_64.S | 4 ++++
> 3 files changed, 12 insertions(+)
>
> diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
> index 8f95fb267caa7..5dc265b36ef0b 100644
> --- a/arch/x86/lib/memcpy_64.S
> +++ b/arch/x86/lib/memcpy_64.S
> @@ -40,7 +40,11 @@ SYM_TYPED_FUNC_START(__memcpy)
> SYM_FUNC_END(__memcpy)
> EXPORT_SYMBOL(__memcpy)
>
> +#ifdef CONFIG_GENERIC_ENTRY
> SYM_FUNC_ALIAS(memcpy, __memcpy)
> +#else
> +SYM_FUNC_ALIAS_WEAK(memcpy, __memcpy)
> +#endif
> EXPORT_SYMBOL(memcpy)
>
> SYM_FUNC_START_LOCAL(memcpy_orig)
> diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
> index 02661861e5dd9..3b1a02357fb29 100644
> --- a/arch/x86/lib/memmove_64.S
> +++ b/arch/x86/lib/memmove_64.S
> @@ -215,5 +215,9 @@ SYM_FUNC_START(__memmove)
> SYM_FUNC_END(__memmove)
> EXPORT_SYMBOL(__memmove)
>
> +#ifdef CONFIG_GENERIC_ENTRY
> SYM_FUNC_ALIAS(memmove, __memmove)
> +#else
> +SYM_FUNC_ALIAS_WEAK(memmove, __memmove)
> +#endif
> EXPORT_SYMBOL(memmove)
> diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
> index 7c59a704c4584..fe27538a355db 100644
> --- a/arch/x86/lib/memset_64.S
> +++ b/arch/x86/lib/memset_64.S
> @@ -40,7 +40,11 @@ SYM_FUNC_START(__memset)
> SYM_FUNC_END(__memset)
> EXPORT_SYMBOL(__memset)
>
> +#ifdef CONFIG_GENERIC_ENTRY
> SYM_FUNC_ALIAS(memset, __memset)
> +#else
> +SYM_FUNC_ALIAS_WEAK(memset, __memset)
> +#endif
> EXPORT_SYMBOL(memset)
>
> SYM_FUNC_START_LOCAL(memset_orig)
>
> ---
> base-commit: 9561de3a55bed6bdd44a12820ba81ec416e705a7
> change-id: 20230609-uml-kasan-2392dd4c3858
>
> Best regards,
> --
> Vincent Whitchurch <[email protected]>
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20230609-uml-kasan-v1-1-5fac8d409d4f%40axis.com.


Attachments:
smime.p7s (3.91 kB)
S/MIME Cryptographic Signature