openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: uaccess: Fix KASAN false-positives
@ 2023-02-15  2:37 Zev Weiss
  2023-02-15 10:07 ` Arnd Bergmann
  0 siblings, 1 reply; 2+ messages in thread
From: Zev Weiss @ 2023-02-15  2:37 UTC (permalink / raw)
  To: linux-arm-kernel, kasan-dev
  Cc: Zev Weiss, Arnd Bergmann, Anshuman Khandual, Andrew Jeffery,
	openbmc, Russell King, linux-kernel, Dinh Nguyen,
	Andrey Ryabinin, Alexander Potapenko, Stafford Horne,
	Vincenzo Frascino, Sam Ravnborg, Dmitry Vyukov, Andrey Konovalov

From: Andrew Jeffery <andrew@aj.id.au>

__copy_to_user_memcpy() and __clear_user_memset() had been calling
memcpy() and memset() respectively, leading to false-positive KASAN
reports when starting userspace:

    [   10.707901] Run /init as init process
    [   10.731892] process '/bin/busybox' started with executable stack
    [   10.745234] ==================================================================
    [   10.745796] BUG: KASAN: user-memory-access in __clear_user_memset+0x258/0x3ac
    [   10.747260] Write of size 2687 at addr 000de581 by task init/1

Use __memcpy() and __memset() instead to allow userspace access, which
is of course the intent of these functions.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 arch/arm/lib/uaccess_with_memcpy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
index 14eecaaf295f..e4c2677cc1e9 100644
--- a/arch/arm/lib/uaccess_with_memcpy.c
+++ b/arch/arm/lib/uaccess_with_memcpy.c
@@ -116,7 +116,7 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
 			tocopy = n;
 
 		ua_flags = uaccess_save_and_enable();
-		memcpy((void *)to, from, tocopy);
+		__memcpy((void *)to, from, tocopy);
 		uaccess_restore(ua_flags);
 		to += tocopy;
 		from += tocopy;
@@ -178,7 +178,7 @@ __clear_user_memset(void __user *addr, unsigned long n)
 			tocopy = n;
 
 		ua_flags = uaccess_save_and_enable();
-		memset((void *)addr, 0, tocopy);
+		__memset((void *)addr, 0, tocopy);
 		uaccess_restore(ua_flags);
 		addr += tocopy;
 		n -= tocopy;
-- 
2.39.1.438.g79fd386332e5.dirty


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ARM: uaccess: Fix KASAN false-positives
  2023-02-15  2:37 [PATCH] ARM: uaccess: Fix KASAN false-positives Zev Weiss
@ 2023-02-15 10:07 ` Arnd Bergmann
  0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2023-02-15 10:07 UTC (permalink / raw)
  To: Zev Weiss, linux-arm-kernel, kasan-dev
  Cc: Anshuman Khandual, Andrew Jeffery, openbmc, Russell King,
	linux-kernel, Dinh Nguyen, Andrey Ryabinin, Alexander Potapenko,
	Stafford Horne, Vincenzo Frascino, Sam Ravnborg, Dmitry Vyukov,
	Andrey Konovalov

On Wed, Feb 15, 2023, at 03:37, Zev Weiss wrote:
> From: Andrew Jeffery <andrew@aj.id.au>
>
> __copy_to_user_memcpy() and __clear_user_memset() had been calling
> memcpy() and memset() respectively, leading to false-positive KASAN
> reports when starting userspace:
>
>     [   10.707901] Run /init as init process
>     [   10.731892] process '/bin/busybox' started with executable stack
>     [   10.745234] 
> ==================================================================
>     [   10.745796] BUG: KASAN: user-memory-access in 
> __clear_user_memset+0x258/0x3ac
>     [   10.747260] Write of size 2687 at addr 000de581 by task init/1
>
> Use __memcpy() and __memset() instead to allow userspace access, which
> is of course the intent of these functions.
>
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>

Looks good to me. I've added it to my randconfig build tree to
see if there are any build time regressions in odd configurations.
If you don't hear back from me until tomorrow, please add this to
Russell's patch system at 

https://www.arm.linux.org.uk/developer/patches/info.php

with my

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-15 10:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15  2:37 [PATCH] ARM: uaccess: Fix KASAN false-positives Zev Weiss
2023-02-15 10:07 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).