From: Daniel Axtens <dja@axtens.net> To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, christophe.leroy@csgroup.eu, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com Cc: Daniel Axtens <dja@axtens.net>, "Aneesh Kumar K . V" <aneesh.kumar@linux.vnet.ibm.com> Subject: [PATCH v11 2/6] kasan: allow architectures to provide an outline readiness check Date: Sat, 20 Mar 2021 01:40:54 +1100 [thread overview] Message-ID: <20210319144058.772525-3-dja@axtens.net> (raw) In-Reply-To: <20210319144058.772525-1-dja@axtens.net> Allow architectures to define a kasan_arch_is_ready() hook that bails out of any function that's about to touch the shadow unless the arch says that it is ready for the memory to be accessed. This is fairly uninvasive and should have a negligible performance penalty. This will only work in outline mode, so an arch must specify ARCH_DISABLE_KASAN_INLINE if it requires this. Cc: Balbir Singh <bsingharora@gmail.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Suggested-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Daniel Axtens <dja@axtens.net> -- I discuss the justfication for this later in the series. Also, both previous RFCs for ppc64 - by 2 different people - have needed this trick! See: - https://lore.kernel.org/patchwork/patch/592820/ # ppc64 hash series - https://patchwork.ozlabs.org/patch/795211/ # ppc radix series --- include/linux/kasan.h | 4 ++++ mm/kasan/common.c | 4 ++++ mm/kasan/generic.c | 3 +++ mm/kasan/shadow.c | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 8b3b99d659b7..6bd8343f0033 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -23,6 +23,10 @@ struct kunit_kasan_expectation { #endif +#ifndef kasan_arch_is_ready +static inline bool kasan_arch_is_ready(void) { return true; } +#endif + #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #include <linux/pgtable.h> diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 6bb87f2acd4e..f23a9e2dce9f 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -345,6 +345,10 @@ static inline bool ____kasan_slab_free(struct kmem_cache *cache, void *object, if (unlikely(cache->flags & SLAB_TYPESAFE_BY_RCU)) return false; + /* We can't read the shadow byte if the arch isn't ready */ + if (!kasan_arch_is_ready()) + return false; + if (!kasan_byte_accessible(tagged_object)) { kasan_report_invalid_free(tagged_object, ip); return true; diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 53cbf28859b5..c3f5ba7a294a 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -163,6 +163,9 @@ static __always_inline bool check_region_inline(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { + if (!kasan_arch_is_ready()) + return true; + if (unlikely(size == 0)) return true; diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 727ad4629173..1f650c521037 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -80,6 +80,10 @@ void kasan_poison(const void *addr, size_t size, u8 value, bool init) */ addr = kasan_reset_tag(addr); + /* Don't touch the shadow memory if arch isn't ready */ + if (!kasan_arch_is_ready()) + return; + /* Skip KFENCE memory if called explicitly outside of sl*b. */ if (is_kfence_address(addr)) return; -- 2.27.0
WARNING: multiple messages have this Message-ID (diff)
From: Daniel Axtens <dja@axtens.net> To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, christophe.leroy@csgroup.eu, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com Cc: "Aneesh Kumar K . V" <aneesh.kumar@linux.vnet.ibm.com>, Daniel Axtens <dja@axtens.net> Subject: [PATCH v11 2/6] kasan: allow architectures to provide an outline readiness check Date: Sat, 20 Mar 2021 01:40:54 +1100 [thread overview] Message-ID: <20210319144058.772525-3-dja@axtens.net> (raw) In-Reply-To: <20210319144058.772525-1-dja@axtens.net> Allow architectures to define a kasan_arch_is_ready() hook that bails out of any function that's about to touch the shadow unless the arch says that it is ready for the memory to be accessed. This is fairly uninvasive and should have a negligible performance penalty. This will only work in outline mode, so an arch must specify ARCH_DISABLE_KASAN_INLINE if it requires this. Cc: Balbir Singh <bsingharora@gmail.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Suggested-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Daniel Axtens <dja@axtens.net> -- I discuss the justfication for this later in the series. Also, both previous RFCs for ppc64 - by 2 different people - have needed this trick! See: - https://lore.kernel.org/patchwork/patch/592820/ # ppc64 hash series - https://patchwork.ozlabs.org/patch/795211/ # ppc radix series --- include/linux/kasan.h | 4 ++++ mm/kasan/common.c | 4 ++++ mm/kasan/generic.c | 3 +++ mm/kasan/shadow.c | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 8b3b99d659b7..6bd8343f0033 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -23,6 +23,10 @@ struct kunit_kasan_expectation { #endif +#ifndef kasan_arch_is_ready +static inline bool kasan_arch_is_ready(void) { return true; } +#endif + #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #include <linux/pgtable.h> diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 6bb87f2acd4e..f23a9e2dce9f 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -345,6 +345,10 @@ static inline bool ____kasan_slab_free(struct kmem_cache *cache, void *object, if (unlikely(cache->flags & SLAB_TYPESAFE_BY_RCU)) return false; + /* We can't read the shadow byte if the arch isn't ready */ + if (!kasan_arch_is_ready()) + return false; + if (!kasan_byte_accessible(tagged_object)) { kasan_report_invalid_free(tagged_object, ip); return true; diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 53cbf28859b5..c3f5ba7a294a 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -163,6 +163,9 @@ static __always_inline bool check_region_inline(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { + if (!kasan_arch_is_ready()) + return true; + if (unlikely(size == 0)) return true; diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 727ad4629173..1f650c521037 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -80,6 +80,10 @@ void kasan_poison(const void *addr, size_t size, u8 value, bool init) */ addr = kasan_reset_tag(addr); + /* Don't touch the shadow memory if arch isn't ready */ + if (!kasan_arch_is_ready()) + return; + /* Skip KFENCE memory if called explicitly outside of sl*b. */ if (is_kfence_address(addr)) return; -- 2.27.0
next prev parent reply other threads:[~2021-03-19 14:41 UTC|newest] Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-19 14:40 [PATCH v11 0/6] KASAN for powerpc64 radix Daniel Axtens 2021-03-19 14:40 ` [PATCH v11 1/6] kasan: allow an architecture to disable inline instrumentation Daniel Axtens 2021-03-20 1:46 ` Balbir Singh 2021-03-20 1:46 ` Balbir Singh 2021-03-22 0:29 ` Daniel Axtens 2021-03-22 0:29 ` Daniel Axtens 2021-03-22 11:08 ` Michael Ellerman 2021-03-22 11:08 ` Michael Ellerman 2021-03-22 8:18 ` Marco Elver 2021-03-22 8:18 ` Marco Elver 2021-03-22 8:18 ` Marco Elver 2021-03-19 14:40 ` Daniel Axtens [this message] 2021-03-19 14:40 ` [PATCH v11 2/6] kasan: allow architectures to provide an outline readiness check Daniel Axtens 2021-03-22 8:17 ` Marco Elver 2021-03-22 8:17 ` Marco Elver 2021-03-22 8:17 ` Marco Elver 2021-03-19 14:40 ` [PATCH v11 3/6] kasan: define and use MAX_PTRS_PER_* for early shadow tables Daniel Axtens 2021-03-19 14:40 ` [PATCH v11 4/6] kasan: Document support on 32-bit powerpc Daniel Axtens 2021-03-19 14:40 ` [PATCH v11 5/6] powerpc/mm/kasan: rename kasan_init_32.c to init_32.c Daniel Axtens 2021-03-19 14:40 ` [PATCH v11 6/6] powerpc: Book3S 64-bit outline-only KASAN support Daniel Axtens 2021-03-20 6:02 ` Balbir Singh 2021-03-20 6:02 ` Balbir Singh 2021-03-22 0:55 ` Daniel Axtens 2021-03-22 0:55 ` Daniel Axtens 2021-03-22 2:59 ` Balbir Singh 2021-03-22 2:59 ` Balbir Singh 2021-03-22 5:52 ` Daniel Axtens 2021-03-22 5:52 ` Daniel Axtens 2021-03-22 15:14 ` Christophe Leroy 2021-04-21 12:29 ` Christophe Leroy 2021-03-20 1:40 ` [PATCH v11 0/6] KASAN for powerpc64 radix Balbir Singh 2021-03-20 1:40 ` Balbir Singh 2021-03-22 14:32 ` Christophe Leroy 2021-03-23 1:21 ` Daniel Axtens 2021-03-23 13:27 ` Christophe Leroy 2021-03-29 23:53 ` Michael Ellerman
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=20210319144058.772525-3-dja@axtens.net \ --to=dja@axtens.net \ --cc=aneesh.kumar@linux.ibm.com \ --cc=aneesh.kumar@linux.vnet.ibm.com \ --cc=bsingharora@gmail.com \ --cc=christophe.leroy@csgroup.eu \ --cc=kasan-dev@googlegroups.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=linuxppc-dev@lists.ozlabs.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.