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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 40353C433DB for ; Mon, 22 Mar 2021 08:18:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC4D461967 for ; Mon, 22 Mar 2021 08:18:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC4D461967 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 877D68D0006; Mon, 22 Mar 2021 03:59:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8025B8D0001; Mon, 22 Mar 2021 03:59:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62DE18D0006; Mon, 22 Mar 2021 03:59:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id 433EA8D0001 for ; Mon, 22 Mar 2021 03:59:19 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8C54C18000DA0 for ; Mon, 22 Mar 2021 08:18:09 +0000 (UTC) X-FDA: 77946807498.03.A69FADA Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) by imf15.hostedemail.com (Postfix) with ESMTP id 0EF8DA0009E0 for ; Mon, 22 Mar 2021 08:18:08 +0000 (UTC) Received: by mail-ot1-f41.google.com with SMTP id v24-20020a9d69d80000b02901b9aec33371so15105448oto.2 for ; Mon, 22 Mar 2021 01:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Sk5nXZmNrPBhnu290SRFE/AaX0zXvxqhg24fy7HJRik=; b=UsoPckqy/cBUBbKkWG7iVBL06TORbtJfQyHbYe8pqPWyQh5dez8eGB3IQJEvHOmg7G ZMmlbJljicTOw9XSZNbt1qAZc3Ur+4ZDG11DBj0gtsRxDM8bgvJwy5qesu2zrTnJUvmd u4Aw3PiSfzfqkzwffdfqKKIlriCizZHLJPPi7BK9KTYZVUJYflke8Z/fFMVHGrr7+D5v Nw1yV+N4pVB6UyYAhV98yvt8euaZ74R03+HjtyWE+4z384GtTMTA3pKxGrnG7uyCQRxc wtI07Y5BoxRPev2GwNJSwhzmFzExRkw2QIfJeCouKPL35isVkA2epjzCeJdFlBvEJJME jyHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Sk5nXZmNrPBhnu290SRFE/AaX0zXvxqhg24fy7HJRik=; b=aVB6c4kPCWixRhdt4MOSxYfNbUV8JTtU+GaAR2xzyUpSnnaxuxk6aVlJIyRsDl3I0c Zt+b29jcKkHOb/iVdC/GifgCcNaiPEU0wzpb26QogZQOUq6NhGU6sP0j5uBUo+oJibtd mDEvJicExS7UPAY2n+B8T2qj7ArpgXMNCDin3NLBrpfEW46Zx0P5ttykwxXCwqorzEfl CDKFFCShjZyft4QxfjpeyvcdBZjAjaBkJYwoodqXTfmvp5O7NnVfD+3J7k0YlPJe+5mc Fr+2F1EObCFQ8CIasBfG/87wSSdkBrvDXJNO+VhT3Q3whd+aOJxIXDhyy/lr2Acx3ymA Ek0g== X-Gm-Message-State: AOAM533hvSATle/JkB0zgMgO82CwnfRuU0AnwWBMw1nmFkKHrQnihB9z lJ4BKjl6zW255gbzRR5atMjRUNFOfz12qR9gUO6rtA== X-Google-Smtp-Source: ABdhPJzvbElyZZDDIxpenI8cVDVzjmJITxV9NKesMpuZ8BW6GJm0JmhCXcsj5hWyJduf0shx2QAG0j6jEips7rMEgHY= X-Received: by 2002:a05:6830:1c6e:: with SMTP id s14mr10905818otg.17.1616401087131; Mon, 22 Mar 2021 01:18:07 -0700 (PDT) MIME-Version: 1.0 References: <20210319144058.772525-1-dja@axtens.net> <20210319144058.772525-3-dja@axtens.net> In-Reply-To: <20210319144058.772525-3-dja@axtens.net> From: Marco Elver Date: Mon, 22 Mar 2021 09:17:55 +0100 Message-ID: Subject: Re: [PATCH v11 2/6] kasan: allow architectures to provide an outline readiness check To: Daniel Axtens Cc: LKML , Linux Memory Management List , linuxppc-dev@lists.ozlabs.org, kasan-dev , Christophe Leroy , aneesh.kumar@linux.ibm.com, Balbir Singh , "Aneesh Kumar K . V" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0EF8DA0009E0 X-Stat-Signature: ztn6c81mj4p7epy6p65cngmmtahjm5wz Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=mail-ot1-f41.google.com; client-ip=209.85.210.41 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616401088-841569 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: On Fri, 19 Mar 2021 at 15:41, Daniel Axtens wrote: > 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 > Cc: Aneesh Kumar K.V > Suggested-by: Christophe Leroy > Signed-off-by: Daniel Axtens > > -- > > 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 Does kasan_arch_is_ready() need to be defined in the public interface of KASAN? Could it instead be moved to mm/kasan/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 > 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; > + While it probably doesn't matter much, it seems this check could be moved up, rather than having it in the middle here. > 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 > > -- > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20210319144058.772525-3-dja%40axtens.net.