LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] kasan: add no_sanitize attribute for clang builds
@ 2018-04-12 17:29 Andrey Konovalov
2018-04-13 15:31 ` Andrey Ryabinin
0 siblings, 1 reply; 5+ messages in thread
From: Andrey Konovalov @ 2018-04-12 17:29 UTC (permalink / raw)
To: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov,
Andrew Morton, David Rientjes, Thomas Gleixner, Ingo Molnar,
David Woodhouse, Andrey Konovalov, Will Deacon,
Greg Kroah-Hartman, Paul Lawrence, Sandipan Das, Kees Cook,
linux-kernel, kasan-dev, linux-mm
Cc: Kostya Serebryany
KASAN uses the __no_sanitize_address macro to disable instrumentation
of particular functions. Right now it's defined only for GCC build,
which causes false positives when clang is used.
This patch adds a definition for clang.
Note, that clang's revision 329612 or higher is required.
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
include/linux/compiler-clang.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index ceb96ecab96e..5a1d8580febe 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -25,6 +25,11 @@
#define __SANITIZE_ADDRESS__
#endif
+#ifdef CONFIG_KASAN
+#undef __no_sanitize_address
+#define __no_sanitize_address __attribute__((no_sanitize("address")))
+#endif
+
/* Clang doesn't have a way to turn it off per-function, yet. */
#ifdef __noretpoline
#undef __noretpoline
--
2.17.0.484.g0c8726318c-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kasan: add no_sanitize attribute for clang builds
2018-04-12 17:29 [PATCH] kasan: add no_sanitize attribute for clang builds Andrey Konovalov
@ 2018-04-13 15:31 ` Andrey Ryabinin
2018-04-13 17:34 ` Andrey Konovalov
0 siblings, 1 reply; 5+ messages in thread
From: Andrey Ryabinin @ 2018-04-13 15:31 UTC (permalink / raw)
To: Andrey Konovalov, Alexander Potapenko, Dmitry Vyukov,
Andrew Morton, David Rientjes, Thomas Gleixner, Ingo Molnar,
David Woodhouse, Will Deacon, Greg Kroah-Hartman, Paul Lawrence,
Sandipan Das, Kees Cook, linux-kernel, kasan-dev, linux-mm
Cc: Kostya Serebryany
On 04/12/2018 08:29 PM, Andrey Konovalov wrote:
> KASAN uses the __no_sanitize_address macro to disable instrumentation
> of particular functions. Right now it's defined only for GCC build,
> which causes false positives when clang is used.
>
> This patch adds a definition for clang.
>
> Note, that clang's revision 329612 or higher is required.
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
> include/linux/compiler-clang.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
> index ceb96ecab96e..5a1d8580febe 100644
> --- a/include/linux/compiler-clang.h
> +++ b/include/linux/compiler-clang.h
> @@ -25,6 +25,11 @@
> #define __SANITIZE_ADDRESS__
> #endif
>
> +#ifdef CONFIG_KASAN
If, for whatever reason, developer decides to add __no_sanitize_address to some
generic function, guess what will happen next when he/she will try to build CONFIG_KASAN=n kernel?
> +#undef __no_sanitize_address
> +#define __no_sanitize_address __attribute__((no_sanitize("address")))
> +#endif
> +
> /* Clang doesn't have a way to turn it off per-function, yet. */
> #ifdef __noretpoline
> #undef __noretpoline
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kasan: add no_sanitize attribute for clang builds
2018-04-13 15:31 ` Andrey Ryabinin
@ 2018-04-13 17:34 ` Andrey Konovalov
2018-04-13 19:16 ` Andrey Ryabinin
0 siblings, 1 reply; 5+ messages in thread
From: Andrey Konovalov @ 2018-04-13 17:34 UTC (permalink / raw)
To: Andrey Ryabinin
Cc: Alexander Potapenko, Dmitry Vyukov, Andrew Morton,
David Rientjes, Thomas Gleixner, Ingo Molnar, David Woodhouse,
Will Deacon, Greg Kroah-Hartman, Paul Lawrence, Sandipan Das,
Kees Cook, LKML, kasan-dev, Linux Memory Management List,
Kostya Serebryany
On Fri, Apr 13, 2018 at 5:31 PM, Andrey Ryabinin
<aryabinin@virtuozzo.com> wrote:
>
>
> On 04/12/2018 08:29 PM, Andrey Konovalov wrote:
>> KASAN uses the __no_sanitize_address macro to disable instrumentation
>> of particular functions. Right now it's defined only for GCC build,
>> which causes false positives when clang is used.
>>
>> This patch adds a definition for clang.
>>
>> Note, that clang's revision 329612 or higher is required.
>>
>> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
>> ---
>> include/linux/compiler-clang.h | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
>> index ceb96ecab96e..5a1d8580febe 100644
>> --- a/include/linux/compiler-clang.h
>> +++ b/include/linux/compiler-clang.h
>> @@ -25,6 +25,11 @@
>> #define __SANITIZE_ADDRESS__
>> #endif
>>
>> +#ifdef CONFIG_KASAN
>
> If, for whatever reason, developer decides to add __no_sanitize_address to some
> generic function, guess what will happen next when he/she will try to build CONFIG_KASAN=n kernel?
It's defined to nothing in compiler-gcc.h and redefined in
compiler-clang.h only if CONFIG_KASAN is enabled, so everything should
be fine. Am I missing something?
>
>> +#undef __no_sanitize_address
>> +#define __no_sanitize_address __attribute__((no_sanitize("address")))
>> +#endif
>> +
>> /* Clang doesn't have a way to turn it off per-function, yet. */
>> #ifdef __noretpoline
>> #undef __noretpoline
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kasan: add no_sanitize attribute for clang builds
2018-04-13 17:34 ` Andrey Konovalov
@ 2018-04-13 19:16 ` Andrey Ryabinin
2018-04-17 12:27 ` Andrey Konovalov
0 siblings, 1 reply; 5+ messages in thread
From: Andrey Ryabinin @ 2018-04-13 19:16 UTC (permalink / raw)
To: Andrey Konovalov
Cc: Alexander Potapenko, Dmitry Vyukov, Andrew Morton,
David Rientjes, Thomas Gleixner, Ingo Molnar, David Woodhouse,
Will Deacon, Greg Kroah-Hartman, Paul Lawrence, Sandipan Das,
Kees Cook, LKML, kasan-dev, Linux Memory Management List,
Kostya Serebryany
On 04/13/2018 08:34 PM, Andrey Konovalov wrote:
> On Fri, Apr 13, 2018 at 5:31 PM, Andrey Ryabinin
> <aryabinin@virtuozzo.com> wrote:
>>
>>
>> On 04/12/2018 08:29 PM, Andrey Konovalov wrote:
>>> KASAN uses the __no_sanitize_address macro to disable instrumentation
>>> of particular functions. Right now it's defined only for GCC build,
>>> which causes false positives when clang is used.
>>>
>>> This patch adds a definition for clang.
>>>
>>> Note, that clang's revision 329612 or higher is required.
>>>
>>> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
>>> ---
>>> include/linux/compiler-clang.h | 5 +++++
>>> 1 file changed, 5 insertions(+)
>>>
>>> diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
>>> index ceb96ecab96e..5a1d8580febe 100644
>>> --- a/include/linux/compiler-clang.h
>>> +++ b/include/linux/compiler-clang.h
>>> @@ -25,6 +25,11 @@
>>> #define __SANITIZE_ADDRESS__
>>> #endif
>>>
>>> +#ifdef CONFIG_KASAN
>>
>> If, for whatever reason, developer decides to add __no_sanitize_address to some
>> generic function, guess what will happen next when he/she will try to build CONFIG_KASAN=n kernel?
>
> It's defined to nothing in compiler-gcc.h and redefined in
> compiler-clang.h only if CONFIG_KASAN is enabled, so everything should
> be fine. Am I missing something?
No, It's was me missing something ;)
However, "#ifdef CONFIG_KASAN" seems to be redundant, I'd rather remove it.
Anyway:
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kasan: add no_sanitize attribute for clang builds
2018-04-13 19:16 ` Andrey Ryabinin
@ 2018-04-17 12:27 ` Andrey Konovalov
0 siblings, 0 replies; 5+ messages in thread
From: Andrey Konovalov @ 2018-04-17 12:27 UTC (permalink / raw)
To: Andrey Ryabinin
Cc: Alexander Potapenko, Dmitry Vyukov, Andrew Morton,
David Rientjes, Thomas Gleixner, Ingo Molnar, David Woodhouse,
Will Deacon, Greg Kroah-Hartman, Paul Lawrence, Sandipan Das,
Kees Cook, LKML, kasan-dev, Linux Memory Management List,
Kostya Serebryany
On Fri, Apr 13, 2018 at 9:16 PM, Andrey Ryabinin
<aryabinin@virtuozzo.com> wrote:
> However, "#ifdef CONFIG_KASAN" seems to be redundant, I'd rather remove it.
Done, sent v2.
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-04-17 12:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-12 17:29 [PATCH] kasan: add no_sanitize attribute for clang builds Andrey Konovalov
2018-04-13 15:31 ` Andrey Ryabinin
2018-04-13 17:34 ` Andrey Konovalov
2018-04-13 19:16 ` Andrey Ryabinin
2018-04-17 12:27 ` Andrey Konovalov
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).