From patchwork Tue Nov 10 22:10:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895601 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=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 E6B5DC388F7 for ; Tue, 10 Nov 2020 22:14:12 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8CFC420637 for ; Tue, 10 Nov 2020 22:14:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rY9G77Aa"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dcDLFYUo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CFC420637 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PmSV89i0axEUfVxp2l4pz+Xw/B/0f9lUi6QfeagCWf0=; b=rY9G77AaVkVnOHFflbWFnrmLE fVq5qEhNrf7PqHTtzP9VS5RfjaLma18KyadY6ycmG4ns7BRzpSZXNVIFwn4Xq9F4AXhufFGNX6tMv 8ONTUr0h/zmaDDaIP23MuBwXDTSsCAM5u8mm7+u0DwGCBMtc1+W9n45BUk1bmOmqgHgSKvu9cVUwX 95kUCiLlCZLNEAi5t4tTRu5W0c7OOz38mTcDfdOgPB0N3pxw3alzXPUR4FyFTfs9PRwMbtJPcpNin tN88V1lCufV5vojbinf/63VeS5QQiCBsudy4mqhZDIwo/YVQD8cPM+RcDZKtfjXhctR/84psf76uU 3+A4j/fFQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbtV-0005Oz-C7; Tue, 10 Nov 2020 22:13:41 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbrF-0004U8-U3 for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:11:27 +0000 Received: by mail-wr1-x44a.google.com with SMTP id e18so6178812wrs.23 for ; Tue, 10 Nov 2020 14:11:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=1eB/cLd20VDMIOf5D2uQuwyV0kwdvml7t6htObswIuI=; b=dcDLFYUo7ZWAl0w6Ap0g44WLGYOIxW8LfvFE7BVqEs3gAXemhCzpMkfI9vHDfCo5kW G6DfPNHDcMneHDBN1nxH1Eydjd/4oDloko4cSzC5V+MpBFyqz4pUyEnw4JEXd+wUFsDo yHlcQUTwruEFGKeILdN4qETaXVmG1nNvrrBMGhXjq0Btdua3oc8Tdl/uz0fb4xwF3464 fJGVAT98LJmWJ6K2H5kKNrU7pBoLcV+RjVC6O86jwQINLvUqahB2rJYRXbl6uTwBr/ev oygWQe2FPANJPDJBwoKLxN1pCMn1sAlyj3x7qYNiK5EQOmtNG52a6p9o948Ujd5O3Wue W9YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1eB/cLd20VDMIOf5D2uQuwyV0kwdvml7t6htObswIuI=; b=aWKdP/O64O0N8lYSjNoEdaxVzCSJ61UNnIQpcYmG6rp18tsrCA292oYLBMhVOKE8+K XQ4d/zbVXhLhinefw7n+9Jw+teU5vZjuzCEyHq3NRWa7sJKZ/C9syyPerHWB1VGmu+aF vY1kqefU3mO5BnXHi/RXuTpO+V5XJgoOWIpmu+15RXe5b95u0lGNhIXeIK7u+e57Gxaf iT5gUo/i0yRTMrVRge35nhn37tixEyiy0xZXICbkU/FJHFGRx0RHNyksl43aT3iKuEq1 pYh5jMK27ssISu/8w5bwiLlkSYFwCOhsInDJ8PHm+iZBUDYwxJdZ2PK8jq06muVX5p5w RQ7Q== X-Gm-Message-State: AOAM533OOofv/FEf7uLRvOncCQVpClsDhXZthmXmB8SgOBO23lGnFDsR oUhxFNHpU8Hy3I0qxqoQPPLQ0Ka0ZkuN3r7D X-Google-Smtp-Source: ABdhPJwNo9ObkSN2dMHiHZK/63eZNhZwi78i0Byk4gVJTBEP3w/ACtRfoFudjsbUvnKKRJmHq4ATBQVOooK1uHoj X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:7303:: with SMTP id d3mr275192wmb.152.1605046277660; Tue, 10 Nov 2020 14:11:17 -0800 (PST) Date: Tue, 10 Nov 2020 23:10:02 +0100 In-Reply-To: Message-Id: <81fbf12c3455448b2bb4162dd9888d405ee0c00a.1605046192.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v9 05/44] kasan: shadow declarations only for software modes From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_171122_166717_1B70AA96 X-CRM114-Status: GOOD ( 16.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Group shadow-related KASAN function declarations and only define them for the two existing software modes. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver Reviewed-by: Alexander Potapenko --- Change-Id: I864be75a88b91b443c55e9c2042865e15703e164 --- include/linux/kasan.h | 47 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 59538e795df4..26f2ab92e7ca 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -11,7 +11,6 @@ struct task_struct; #ifdef CONFIG_KASAN -#include #include /* kasan_data struct is used in KUnit tests for KASAN expected failures */ @@ -20,6 +19,20 @@ struct kunit_kasan_expectation { bool report_found; }; +#endif + +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) + +#include + +/* Software KASAN implementations use shadow memory. */ + +#ifdef CONFIG_KASAN_SW_TAGS +#define KASAN_SHADOW_INIT 0xFF +#else +#define KASAN_SHADOW_INIT 0 +#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]; @@ -35,6 +48,23 @@ static inline void *kasan_mem_to_shadow(const void *addr) + KASAN_SHADOW_OFFSET; } +int kasan_add_zero_shadow(void *start, unsigned long size); +void kasan_remove_zero_shadow(void *start, unsigned long size); + +#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +static inline int kasan_add_zero_shadow(void *start, unsigned long size) +{ + return 0; +} +static inline void kasan_remove_zero_shadow(void *start, + unsigned long size) +{} + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +#ifdef CONFIG_KASAN + /* Enable reporting bugs after kasan_disable_current() */ extern void kasan_enable_current(void); @@ -75,9 +105,6 @@ struct kasan_cache { int free_meta_offset; }; -int kasan_add_zero_shadow(void *start, unsigned long size); -void kasan_remove_zero_shadow(void *start, unsigned long size); - size_t __ksize(const void *); static inline void kasan_unpoison_slab(const void *ptr) { @@ -143,14 +170,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, return false; } -static inline int kasan_add_zero_shadow(void *start, unsigned long size) -{ - return 0; -} -static inline void kasan_remove_zero_shadow(void *start, - unsigned long size) -{} - static inline void kasan_unpoison_slab(const void *ptr) { } static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } @@ -158,8 +177,6 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } #ifdef CONFIG_KASAN_GENERIC -#define KASAN_SHADOW_INIT 0 - void kasan_cache_shrink(struct kmem_cache *cache); void kasan_cache_shutdown(struct kmem_cache *cache); void kasan_record_aux_stack(void *ptr); @@ -174,8 +191,6 @@ static inline void kasan_record_aux_stack(void *ptr) {} #ifdef CONFIG_KASAN_SW_TAGS -#define KASAN_SHADOW_INIT 0xFF - void kasan_init_tags(void); void *kasan_reset_tag(const void *addr);