From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2152C64E7A for ; Tue, 1 Dec 2020 16:53:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 09C542076C for ; Tue, 1 Dec 2020 16:53:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09C542076C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=csgroup.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 221448D0002; Tue, 1 Dec 2020 11:53:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D0318D0001; Tue, 1 Dec 2020 11:53:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BFFA8D0002; Tue, 1 Dec 2020 11:53:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id EA40C8D0001 for ; Tue, 1 Dec 2020 11:53:18 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7B4343629 for ; Tue, 1 Dec 2020 16:53:18 +0000 (UTC) X-FDA: 77545308876.20.desk91_1a0ed50273ac Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 4F7E1180C07AF for ; Tue, 1 Dec 2020 16:53:18 +0000 (UTC) X-HE-Tag: desk91_1a0ed50273ac X-Filterd-Recvd-Size: 5879 Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Dec 2020 16:53:17 +0000 (UTC) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4Clp7s63DZz9v400; Tue, 1 Dec 2020 17:53:13 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id wq3KDCIGPUsp; Tue, 1 Dec 2020 17:53:13 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4Clp7s52ZQz9v3yy; Tue, 1 Dec 2020 17:53:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 161398B7BD; Tue, 1 Dec 2020 17:53:15 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 7Dn2a6jQZQ1y; Tue, 1 Dec 2020 17:53:14 +0100 (CET) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A77558B7B7; Tue, 1 Dec 2020 17:53:08 +0100 (CET) Subject: Re: [PATCH v9 2/6] kasan: allow architectures to provide an outline readiness check To: Daniel Axtens , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, christophe.leroy@c-s.fr, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com Cc: "Aneesh Kumar K . V" References: <20201201161632.1234753-1-dja@axtens.net> <20201201161632.1234753-3-dja@axtens.net> From: Christophe Leroy Message-ID: Date: Tue, 1 Dec 2020 17:53:02 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20201201161632.1234753-3-dja@axtens.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Le 01/12/2020 =C3=A0 17:16, Daniel Axtens a =C3=A9crit=C2=A0: > 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. >=20 > This will only work in outline mode, so an arch must specify > HAVE_ARCH_NO_KASAN_INLINE if it requires this. >=20 > Cc: Balbir Singh > Cc: Aneesh Kumar K.V > Signed-off-by: Christophe Leroy Did I signed that off one day ? I can't remember. Please update my email address, and maybe change it to a Suggested-by: ? = I think the first=20 Signed-off-by: has to be the author of the patch. > Signed-off-by: Daniel Axtens >=20 > -- >=20 > 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 | 10 ++++++++++ > mm/kasan/generic.c | 3 +++ > 3 files changed, 17 insertions(+) >=20 > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index 30d343b4a40a..3df66fdf6662 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -20,6 +20,10 @@ struct kunit_kasan_expectation { > bool report_found; > }; > =20 > +#ifndef kasan_arch_is_ready > +static inline bool kasan_arch_is_ready(void) { return true; } > +#endif > + > extern unsigned char kasan_early_shadow_page[PAGE_SIZE]; > extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE]; > extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD]; > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 950fd372a07e..ba7744d3e319 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -117,6 +117,9 @@ void kasan_poison_shadow(const void *address, size_= t size, u8 value) > { > void *shadow_start, *shadow_end; > =20 > + if (!kasan_arch_is_ready()) > + return; > + > /* > * Perform shadow offset calculation based on untagged address, as > * some of the callers (e.g. kasan_poison_object_data) pass tagged > @@ -134,6 +137,9 @@ void kasan_unpoison_shadow(const void *address, siz= e_t size) > { > u8 tag =3D get_tag(address); > =20 > + if (!kasan_arch_is_ready()) > + return; > + > /* > * Perform shadow offset calculation based on untagged address, as > * some of the callers (e.g. kasan_unpoison_object_data) pass tagged > @@ -406,6 +412,10 @@ static bool __kasan_slab_free(struct kmem_cache *c= ache, void *object, > if (unlikely(cache->flags & SLAB_TYPESAFE_BY_RCU)) > return false; > =20 > + /* We can't read the shadow byte if the arch isn't ready */ > + if (!kasan_arch_is_ready()) > + return false; > + > shadow_byte =3D READ_ONCE(*(s8 *)kasan_mem_to_shadow(object)); > if (shadow_invalid(tag, shadow_byte)) { > kasan_report_invalid_free(tagged_object, ip); > diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c > index 248264b9cb76..e87404026b2b 100644 > --- a/mm/kasan/generic.c > +++ b/mm/kasan/generic.c > @@ -169,6 +169,9 @@ static __always_inline bool check_memory_region_inl= ine(unsigned long addr, > size_t size, bool write, > unsigned long ret_ip) > { > + if (!kasan_arch_is_ready()) > + return true; > + > if (unlikely(size =3D=3D 0)) > return true; > =20 >=20