From patchwork Tue Jun 15 01:47:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 12320383 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,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 26C71C2B9F4 for ; Tue, 15 Jun 2021 01:47:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B38646140B for ; Tue, 15 Jun 2021 01:47:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B38646140B 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 5834C6B0070; Mon, 14 Jun 2021 21:47:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 50B6D6B0071; Mon, 14 Jun 2021 21:47:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 387B66B0072; Mon, 14 Jun 2021 21:47:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0032.hostedemail.com [216.40.44.32]) by kanga.kvack.org (Postfix) with ESMTP id 016F66B0070 for ; Mon, 14 Jun 2021 21:47:20 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9EB27BBC8 for ; Tue, 15 Jun 2021 01:47:20 +0000 (UTC) X-FDA: 78254270640.13.EDDFF27 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf07.hostedemail.com (Postfix) with ESMTP id E119EA0001CF for ; Tue, 15 Jun 2021 01:47:10 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id o88-20020a17090a0a61b029016eeb2adf66so586590pjo.4 for ; Mon, 14 Jun 2021 18:47:19 -0700 (PDT) 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=9yfG43b2K5TzVk5ZU+QSFD/NukUJWMplQuDr+tXNhQQ=; b=Zp8KnLUSatybticlxZJApD0i9G8GXZx7RpoNRl1/7XodZnv+q2U9g29MDo5vvrQxLQ 7Y/gzsANS6ZqQigBUlcKaa7bQlBiMlZ6WyHTlqx9NI+D6nSRIgUkUIPH5IEvWv+o+xOX R+avk3QSGA1U5XWfPL50c0h907VeEKM8o1Qvo= 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=9yfG43b2K5TzVk5ZU+QSFD/NukUJWMplQuDr+tXNhQQ=; b=cdHHj+9pwXEduDg5W6CLJL8XUQmTL35AopapZ2CJAUkJlvPJSGfo7/lx3DxYTbgBH3 F1AVRBT6shFpZhvV/N9zVooJkeb6kGciI7qo0rQk0yLQ+KsF5MNeMMlOdixbge0lbKK3 RpkhYPDSPXeUrMix3/zcq8QML/4MrijA4jc82kJKxI29hocyl3AQQh1Jv9oyfzlGOaV2 StE7LVRPM1kVrwLmtmABuXSzv4YrAos0bpmrONz10D6WPxBV6GLx3kZ2GpRMmlZhkwdY W2K0vLuoEqnjkoLI6T5s03thWJD+c81QqQpbgcKO4WCsfMm/tLRbzPjryd1rmvTyupNE zyHA== X-Gm-Message-State: AOAM530AMOs7rXGTDm/FamgIp/s8iZ9akolKDKn/uGKXDab7qxtmnzVt JaaWSdZNS6QCbGZHDst3m5T2Og== X-Google-Smtp-Source: ABdhPJwayJvIluspopg5KlfYC5uZhjdSK6RLrVbRnbo5dYy82BcNvz2/dLQevVxTLK0wqyDRuuEEFA== X-Received: by 2002:a17:902:d888:b029:11c:1010:f0ea with SMTP id b8-20020a170902d888b029011c1010f0eamr1621088plz.68.1623721639363; Mon, 14 Jun 2021 18:47:19 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id n14sm13096115pfa.138.2021.06.14.18.47.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 18:47:18 -0700 (PDT) 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: elver@google.com, Daniel Axtens , "Aneesh Kumar K . V" Subject: [PATCH v12 2/6] kasan: allow architectures to provide an outline readiness check Date: Tue, 15 Jun 2021 11:47:01 +1000 Message-Id: <20210615014705.2234866-3-dja@axtens.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210615014705.2234866-1-dja@axtens.net> References: <20210615014705.2234866-1-dja@axtens.net> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E119EA0001CF Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=axtens.net header.s=google header.b=Zp8KnLUS; spf=pass (imf07.hostedemail.com: domain of dja@axtens.net designates 209.85.216.42 as permitted sender) smtp.mailfrom=dja@axtens.net; dmarc=none X-Stat-Signature: ywwd6qim9kyye9sst43649efcy6dwp4q X-HE-Tag: 1623721630-137007 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 --- mm/kasan/common.c | 4 ++++ mm/kasan/generic.c | 3 +++ mm/kasan/kasan.h | 4 ++++ mm/kasan/shadow.c | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 10177cc26d06..0ad615f3801d 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -331,6 +331,10 @@ static inline bool ____kasan_slab_free(struct kmem_cache *cache, void *object, u8 tag; void *tagged_object; + /* Bail if the arch isn't ready */ + if (!kasan_arch_is_ready()) + return false; + tag = get_tag(object); tagged_object = object; object = kasan_reset_tag(object); 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/kasan.h b/mm/kasan/kasan.h index 8f450bc28045..19323a3d5975 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -449,6 +449,10 @@ static inline void kasan_poison_last_granule(const void *address, size_t size) { #endif /* CONFIG_KASAN_GENERIC */ +#ifndef kasan_arch_is_ready +static inline bool kasan_arch_is_ready(void) { return true; } +#endif + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations. diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 082ee5b6d9a1..74134b657d7d 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -73,6 +73,10 @@ void kasan_poison(const void *addr, size_t size, u8 value, bool init) { void *shadow_start, *shadow_end; + /* Don't touch the shadow memory if arch isn't ready */ + 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