From patchwork Mon Nov 23 20:07:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926451 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.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 EF3B9C63697 for ; Mon, 23 Nov 2020 20:11:22 +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 7D9E520717 for ; Mon, 23 Nov 2020 20:11:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="w3Hd8tSz"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="W0DqXgU7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D9E520717 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=eyiLMRuAWCzqA3NodTPq73YwaGqr4Kt+z9D0WAYeoIU=; b=w3Hd8tSzOZcnPHioQwPu0s6he Pjj1XGRSBZyWuCgyhL/zIfkvyIJWaVsJ6IRttSt9p3GptYSygNiu5/hUZs4f3BNpvoLW42w81xvOp AmWeV6fZnLtbotPagTbVwpVO8Evq6tt68bWTe4ie59SCwHsspocwF8WOW2CBWM6pY4bESCiS/YZrh 0op246uQPYNwGnXBBZ2VylPX1p+o/pYXCk9kjNp/qtCL1TRORjyHRcR6U4f2naLn6oTgvmmLLpqKJ Rb0jkD92Tll81p0c/VmMOsLoJWt3RsSTupZqR4CmLBewAadbLXCawt0cwC0WdIgNjIthVeq4lnsGF TmM+2fbyQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khI99-0008BB-Ga; Mon, 23 Nov 2020 20:09:11 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khI8W-0007vt-9m for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:08:46 +0000 Received: by mail-wr1-x449.google.com with SMTP id e18so6206184wrs.23 for ; Mon, 23 Nov 2020 12:08:29 -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=rY7yMii3gaWV4vY+mOJjHDhvV20XyRJBFdhOjQqTKLM=; b=W0DqXgU79wWwM7h7ukCXUWawItRO0j6I59qY5A4xLAYoAQNrq8ef2wCqmbnERi5+3g vobLgLy0I8KqldRVzGLEs+MAvhlDlflGt8zlxt9fGXWZPXVbQizuWX/cjn7LaJaVSdHh ulRjfu0YAO/9Dw4TBCKaZTPXdHN4VHtSECuPLHqqcJ7/90APJBSYSXopKNFHqkI2OkXF KtTRND9pIQiwV24eDRH3ARBOi+Nk1wdpgKHHJ7YGKptiHW7iTUE85G6hOIU3Pml8xLyL Sdoau+nm/6iNqnnJYYcXzNL2yVC6sgt1m23TaQsVO34+vPL7eJfzNxPRzDWbZncmkd1Z C6tA== 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=rY7yMii3gaWV4vY+mOJjHDhvV20XyRJBFdhOjQqTKLM=; b=OETdOC5IK/PN0oeSYRAZqsNeqk7DEFa4G5t1lQtbxazRkvd6JM9jYtg1rsaJohhkYw B8dzgf4NV1x8CN8MJLwMj0dFGHKmKwKLVh7Uywai0198/4qtq+1+ni1RZyykXLXdiZbu 9j1AdvzlzWlCKFFYqVmR0mWPMYy8cHxfEtQyRo0wsHYnZYKXYC38Wf48Sk0GT+0afQpw BH9getuRnm6Eo4teBzz8G0k1zHA8SHGvwMrv8WMe5ZbdJWyuKMIT6llrpyyEYrUqXZYZ IkzqacgYKQxmTr6vfTmTCDpZRV90vLfCIPcbLv+cL4p7z4bJX1JDk/OwZEOUclwY3ZP5 GDOg== X-Gm-Message-State: AOAM5319r4zdKPIT5juiriPcU8p+Ep5oYCFBrAHQCQUjN+46qyxNRz8h fyqjRCgdhbvKrH+uIvYUsYOa5R1dLBj6FwXm X-Google-Smtp-Source: ABdhPJx023ZlE/f0mFCG7RLP/bX8clTGcJW0u+/k7KRJl3ehxU0KrnpD66InXkeDCZ6G2YOnrqvFVGbbMfRK0XYP X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:dd8b:: with SMTP id u133mr558600wmg.107.1606162108611; Mon, 23 Nov 2020 12:08:28 -0800 (PST) Date: Mon, 23 Nov 2020 21:07:28 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v11 04/42] kasan: shadow declarations only for software modes From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_150832_720813_CDD2EC36 X-CRM114-Status: GOOD ( 16.81 ) 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 , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , 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);