2022-09-09 07:54:29

by Marco Elver

[permalink] [raw]
Subject: [PATCH v2 1/3] s390: Always declare __mem functions

Like other architectures, always declare __mem*() functions if the
architecture defines __HAVE_ARCH_MEM*.

For example, this is required by sanitizer runtimes to unambiguously
refer to the arch versions of the mem-functions, and the compiler not
attempting any "optimizations" such as replacing the calls with builtins
(which may later be inlined etc.).

Signed-off-by: Marco Elver <[email protected]>
---
v2:
* New patch.
---
arch/s390/include/asm/string.h | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/s390/include/asm/string.h b/arch/s390/include/asm/string.h
index 3fae93ddb322..2c3c48d526b9 100644
--- a/arch/s390/include/asm/string.h
+++ b/arch/s390/include/asm/string.h
@@ -20,8 +20,11 @@
#define __HAVE_ARCH_MEMSET64 /* arch function */

void *memcpy(void *dest, const void *src, size_t n);
+void *__memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
+void *__memset(void *s, int c, size_t n);
void *memmove(void *dest, const void *src, size_t n);
+void *__memmove(void *dest, const void *src, size_t n);

#ifndef CONFIG_KASAN
#define __HAVE_ARCH_MEMCHR /* inline & arch function */
@@ -55,10 +58,6 @@ char *strstr(const char *s1, const char *s2);

#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)

-extern void *__memcpy(void *dest, const void *src, size_t n);
-extern void *__memset(void *s, int c, size_t n);
-extern void *__memmove(void *dest, const void *src, size_t n);
-
/*
* For files that are not instrumented (e.g. mm/slub.c) we
* should use not instrumented version of mem* functions.
--
2.37.2.789.g6183377224-goog


2022-09-09 08:29:14

by Marco Elver

[permalink] [raw]
Subject: [PATCH v2 3/3] objtool, kcsan: Add volatile read/write instrumentation to whitelist

Adds KCSAN's volatile instrumentation to objtool's uaccess whitelist.

Recent kernel change have shown that this was missing from the uaccess
whitelist (since the first upstreamed version of KCSAN):

mm/gup.o: warning: objtool: fault_in_readable+0x101: call to __tsan_volatile_write1() with UACCESS enabled

Fixes: 75d75b7a4d54 ("kcsan: Support distinguishing volatile accesses")
Signed-off-by: Marco Elver <[email protected]>
---
v2:
* Fix commit message.
---
tools/objtool/check.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index e55fdf952a3a..67afdce3421f 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -999,6 +999,16 @@ static const char *uaccess_safe_builtin[] = {
"__tsan_read_write4",
"__tsan_read_write8",
"__tsan_read_write16",
+ "__tsan_volatile_read1",
+ "__tsan_volatile_read2",
+ "__tsan_volatile_read4",
+ "__tsan_volatile_read8",
+ "__tsan_volatile_read16",
+ "__tsan_volatile_write1",
+ "__tsan_volatile_write2",
+ "__tsan_volatile_write4",
+ "__tsan_volatile_write8",
+ "__tsan_volatile_write16",
"__tsan_atomic8_load",
"__tsan_atomic16_load",
"__tsan_atomic32_load",
--
2.37.2.789.g6183377224-goog

2022-09-09 08:41:12

by Dmitry Vyukov

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] s390: Always declare __mem functions

On Fri, 9 Sept 2022 at 09:38, Marco Elver <[email protected]> wrote:
>
> Like other architectures, always declare __mem*() functions if the
> architecture defines __HAVE_ARCH_MEM*.
>
> For example, this is required by sanitizer runtimes to unambiguously
> refer to the arch versions of the mem-functions, and the compiler not
> attempting any "optimizations" such as replacing the calls with builtins
> (which may later be inlined etc.).
>
> Signed-off-by: Marco Elver <[email protected]>

Acked-by: Dmitry Vyukov <[email protected]>

> ---
> v2:
> * New patch.
> ---
> arch/s390/include/asm/string.h | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/arch/s390/include/asm/string.h b/arch/s390/include/asm/string.h
> index 3fae93ddb322..2c3c48d526b9 100644
> --- a/arch/s390/include/asm/string.h
> +++ b/arch/s390/include/asm/string.h
> @@ -20,8 +20,11 @@
> #define __HAVE_ARCH_MEMSET64 /* arch function */
>
> void *memcpy(void *dest, const void *src, size_t n);
> +void *__memcpy(void *dest, const void *src, size_t n);
> void *memset(void *s, int c, size_t n);
> +void *__memset(void *s, int c, size_t n);
> void *memmove(void *dest, const void *src, size_t n);
> +void *__memmove(void *dest, const void *src, size_t n);
>
> #ifndef CONFIG_KASAN
> #define __HAVE_ARCH_MEMCHR /* inline & arch function */
> @@ -55,10 +58,6 @@ char *strstr(const char *s1, const char *s2);
>
> #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
>
> -extern void *__memcpy(void *dest, const void *src, size_t n);
> -extern void *__memset(void *s, int c, size_t n);
> -extern void *__memmove(void *dest, const void *src, size_t n);
> -
> /*
> * For files that are not instrumented (e.g. mm/slub.c) we
> * should use not instrumented version of mem* functions.
> --
> 2.37.2.789.g6183377224-goog
>

2022-09-09 08:54:27

by Dmitry Vyukov

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] objtool, kcsan: Add volatile read/write instrumentation to whitelist

On Fri, 9 Sept 2022 at 09:38, Marco Elver <[email protected]> wrote:
>
> Adds KCSAN's volatile instrumentation to objtool's uaccess whitelist.
>
> Recent kernel change have shown that this was missing from the uaccess
> whitelist (since the first upstreamed version of KCSAN):
>
> mm/gup.o: warning: objtool: fault_in_readable+0x101: call to __tsan_volatile_write1() with UACCESS enabled
>
> Fixes: 75d75b7a4d54 ("kcsan: Support distinguishing volatile accesses")
> Signed-off-by: Marco Elver <[email protected]>

Reviewed-by: Dmitry Vyukov <[email protected]>

> ---
> v2:
> * Fix commit message.
> ---
> tools/objtool/check.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index e55fdf952a3a..67afdce3421f 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -999,6 +999,16 @@ static const char *uaccess_safe_builtin[] = {
> "__tsan_read_write4",
> "__tsan_read_write8",
> "__tsan_read_write16",
> + "__tsan_volatile_read1",
> + "__tsan_volatile_read2",
> + "__tsan_volatile_read4",
> + "__tsan_volatile_read8",
> + "__tsan_volatile_read16",
> + "__tsan_volatile_write1",
> + "__tsan_volatile_write2",
> + "__tsan_volatile_write4",
> + "__tsan_volatile_write8",
> + "__tsan_volatile_write16",
> "__tsan_atomic8_load",
> "__tsan_atomic16_load",
> "__tsan_atomic32_load",
> --
> 2.37.2.789.g6183377224-goog
>