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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 CE8E2C433DB for ; Wed, 3 Feb 2021 12:00:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3E08364F77 for ; Wed, 3 Feb 2021 12:00:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E08364F77 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C2B596B0073; Wed, 3 Feb 2021 07:00:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C00D56B0074; Wed, 3 Feb 2021 07:00:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B15526B0075; Wed, 3 Feb 2021 07:00:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id A15DE6B0073 for ; Wed, 3 Feb 2021 07:00:05 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 661BD181AEF21 for ; Wed, 3 Feb 2021 12:00:05 +0000 (UTC) X-FDA: 77776813170.23.art24_4008fa6275d3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id C3CC03760C for ; Wed, 3 Feb 2021 12:00:04 +0000 (UTC) X-HE-Tag: art24_4008fa6275d3 X-Filterd-Recvd-Size: 5944 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Feb 2021 12:00:04 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id d13so14305907plg.0 for ; Wed, 03 Feb 2021 04:00:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zyIIbH1s6hkgFOvACSv5XJQgDv/VgHDX59KWA+Xvn8M=; b=HdaU2YkxBUv1ZQR72BHZhNkDi9aMeisLhesX6nItVNhnXwXnpSlW8tjDBNGyV9f3OE sH6r/X/3vzUef/ZF5pej/AWK61WfBFSyZULpvCKysllaA4ZSobhfIFeKiW10Lma8b5k+ rnIrhYQM+0aORW7YgvIpqsBbEDSLMKyOkXMuI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zyIIbH1s6hkgFOvACSv5XJQgDv/VgHDX59KWA+Xvn8M=; b=Qwwy9M7xsW+72L4dWuj7fG/E4gy7RSpLsGHlwdm63SJgWZEjWXH61SjbqZ8lDHItSe tGSfrw8yDcP09QWVuNWGO6uHHf7FQWbj45EIpcjyNr3BVpUuKrfWZh5uOB0HyPDvqvZB NbD+WuOrlTPJxOXR7ik8HODPV8XQRf+eG9qDKHGj4luBN7kVUIwzPE1QN5SEVs6gSeFO iSVEjaGTsEOHTaVfWwv0ztbO+pQFMhC0rK6XmIcUGsL2RnNwVGyIkoMrwVbvOHHR4hZv konivKwtMu8WHK38+XTkpnHU6QFzunh1R6u0cLfDjJpRmgkLHjohcBawkuk0tj/zGtgR ByIg== X-Gm-Message-State: AOAM532585rpoVXXQAeAcqgHQQFTmwCa+5VUL9rAyF/0mvjKIhjQrUHt 0FNpZbolryjQ2dqdOq9rRypW8A== X-Google-Smtp-Source: ABdhPJyjM8vsAjheEdTSAR8cEAxQiCmcXh8BHUMRbBe0TFX01V8qpKG9NVluj//d9mOMzxXjK3QhpA== X-Received: by 2002:a17:90b:198d:: with SMTP id mv13mr2893257pjb.68.1612353602855; Wed, 03 Feb 2021 04:00:02 -0800 (PST) Received: from localhost (2001-44b8-1113-6700-1c59-4eca-f876-fd51.static.ipv6.internode.on.net. [2001:44b8:1113:6700:1c59:4eca:f876:fd51]) by smtp.gmail.com with ESMTPSA id b65sm2750037pga.54.2021.02.03.04.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 04:00:02 -0800 (PST) From: Daniel Axtens 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 , "Aneesh Kumar K . V" Subject: [PATCH v10 2/6] kasan: allow architectures to provide an outline readiness check Date: Wed, 3 Feb 2021 22:59:42 +1100 Message-Id: <20210203115946.663273-3-dja@axtens.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210203115946.663273-1-dja@axtens.net> References: <20210203115946.663273-1-dja@axtens.net> MIME-Version: 1.0 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: 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 bb862d1f0e15..d314c0fa5804 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -23,6 +23,10 @@ struct kunit_kasan_expectation { =20 #endif =20 +#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) =20 #include diff --git a/mm/kasan/common.c b/mm/kasan/common.c index a390fae9d64b..871ceefd723d 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -348,6 +348,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; + 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 2e55e0f82f39..718c171584e3 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -163,6 +163,9 @@ static __always_inline bool check_region_inline(unsig= ned 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 diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index de6b3f074742..0aafc2d5138f 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -85,6 +85,10 @@ void kasan_poison(const void *address, size_t size, u8= value) address =3D kasan_reset_tag(address); size =3D round_up(size, KASAN_GRANULE_SIZE); =20 + /* 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(address)) return; --=20 2.27.0