From: Mark Rutland <mark.rutland@arm.com>
To: Marco Elver <elver@google.com>
Cc: linux-kernel@vger.kernel.org,
Andrey Ryabinin <aryabinin@virtuozzo.com>,
Dmitry Vyukov <dvyukov@google.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@google.com>,
Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>,
kasan-dev@googlegroups.com, linux-mm@kvack.org
Subject: Re: [PATCH v3 1/5] mm/kasan: Introduce __kasan_check_{read,write}
Date: Wed, 26 Jun 2019 17:17:48 +0100 [thread overview]
Message-ID: <20190626161748.GH20635@lakrids.cambridge.arm.com> (raw)
In-Reply-To: <20190626142014.141844-2-elver@google.com>
On Wed, Jun 26, 2019 at 04:20:10PM +0200, Marco Elver wrote:
> This introduces __kasan_check_{read,write}. __kasan_check functions may
> be used from anywhere, even compilation units that disable
> instrumentation selectively.
>
> This change eliminates the need for the __KASAN_INTERNAL definition.
>
> Signed-off-by: Marco Elver <elver@google.com>
> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: Alexander Potapenko <glider@google.com>
> Cc: Andrey Konovalov <andreyknvl@google.com>
> Cc: Christoph Lameter <cl@linux.com>
> Cc: Pekka Enberg <penberg@kernel.org>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: kasan-dev@googlegroups.com
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-mm@kvack.org
Logically this makes sense to me, so FWIW:
Acked-by: Mark Rutland <mark.rutland@arm.com>
Thanks,
Mark.
> ---
> v3:
> * Fix Formatting and split introduction of __kasan_check_* and returning
> bool into 2 patches.
> ---
> include/linux/kasan-checks.h | 31 ++++++++++++++++++++++++++++---
> mm/kasan/common.c | 10 ++++------
> 2 files changed, 32 insertions(+), 9 deletions(-)
>
> diff --git a/include/linux/kasan-checks.h b/include/linux/kasan-checks.h
> index a61dc075e2ce..19a0175d2452 100644
> --- a/include/linux/kasan-checks.h
> +++ b/include/linux/kasan-checks.h
> @@ -2,9 +2,34 @@
> #ifndef _LINUX_KASAN_CHECKS_H
> #define _LINUX_KASAN_CHECKS_H
>
> -#if defined(__SANITIZE_ADDRESS__) || defined(__KASAN_INTERNAL)
> -void kasan_check_read(const volatile void *p, unsigned int size);
> -void kasan_check_write(const volatile void *p, unsigned int size);
> +/*
> + * __kasan_check_*: Always available when KASAN is enabled. This may be used
> + * even in compilation units that selectively disable KASAN, but must use KASAN
> + * to validate access to an address. Never use these in header files!
> + */
> +#ifdef CONFIG_KASAN
> +void __kasan_check_read(const volatile void *p, unsigned int size);
> +void __kasan_check_write(const volatile void *p, unsigned int size);
> +#else
> +static inline void __kasan_check_read(const volatile void *p, unsigned int size)
> +{ }
> +static inline void __kasan_check_write(const volatile void *p, unsigned int size)
> +{ }
> +#endif
> +
> +/*
> + * kasan_check_*: Only available when the particular compilation unit has KASAN
> + * instrumentation enabled. May be used in header files.
> + */
> +#ifdef __SANITIZE_ADDRESS__
> +static inline void kasan_check_read(const volatile void *p, unsigned int size)
> +{
> + __kasan_check_read(p, size);
> +}
> +static inline void kasan_check_write(const volatile void *p, unsigned int size)
> +{
> + __kasan_check_read(p, size);
> +}
> #else
> static inline void kasan_check_read(const volatile void *p, unsigned int size)
> { }
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index 242fdc01aaa9..6bada42cc152 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -14,8 +14,6 @@
> *
> */
>
> -#define __KASAN_INTERNAL
> -
> #include <linux/export.h>
> #include <linux/interrupt.h>
> #include <linux/init.h>
> @@ -89,17 +87,17 @@ void kasan_disable_current(void)
> current->kasan_depth--;
> }
>
> -void kasan_check_read(const volatile void *p, unsigned int size)
> +void __kasan_check_read(const volatile void *p, unsigned int size)
> {
> check_memory_region((unsigned long)p, size, false, _RET_IP_);
> }
> -EXPORT_SYMBOL(kasan_check_read);
> +EXPORT_SYMBOL(__kasan_check_read);
>
> -void kasan_check_write(const volatile void *p, unsigned int size)
> +void __kasan_check_write(const volatile void *p, unsigned int size)
> {
> check_memory_region((unsigned long)p, size, true, _RET_IP_);
> }
> -EXPORT_SYMBOL(kasan_check_write);
> +EXPORT_SYMBOL(__kasan_check_write);
>
> #undef memset
> void *memset(void *addr, int c, size_t len)
> --
> 2.22.0.410.gd8fdbe21b5-goog
>
next prev parent reply other threads:[~2019-06-26 16:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-26 14:20 [PATCH v3 0/5] mm/kasan: Add object validation in ksize() Marco Elver
2019-06-26 14:20 ` [PATCH v3 1/5] mm/kasan: Introduce __kasan_check_{read,write} Marco Elver
2019-06-26 16:17 ` Mark Rutland [this message]
2019-06-26 14:20 ` [PATCH v3 2/5] mm/kasan: Change kasan_check_{read,write} to return boolean Marco Elver
2019-06-26 14:20 ` [PATCH v3 3/5] lib/test_kasan: Add test for double-kzfree detection Marco Elver
2019-06-26 14:20 ` [PATCH v3 4/5] mm/slab: Refactor common ksize KASAN logic into slab_common.c Marco Elver
2019-06-26 22:56 ` Andrew Morton
2019-06-26 14:20 ` [PATCH v3 5/5] mm/kasan: Add object validation in ksize() Marco Elver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190626161748.GH20635@lakrids.cambridge.arm.com \
--to=mark.rutland@arm.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@google.com \
--cc=aryabinin@virtuozzo.com \
--cc=cl@linux.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox