From patchwork Fri Nov 13 22:15:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11904945 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 52544C4742C for ; Fri, 13 Nov 2020 22:18:49 +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 C3D992223F for ; Fri, 13 Nov 2020 22:18:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eCCUv4w1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Sdo5xec8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C3D992223F 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=ebW8P8W824Bnq6wiuANOl2mogVdd9QZGLc9hb7S99LI=; b=eCCUv4w1Cgk4olJYPOo1Ht0sL 2MxxrI+sUnDYp+4cbrkrm/7usjYmaLNR4JqP7TFYGfTNfCejK46ZdqEH+QEvu0jAV+cmtIkmhWWK/ R+bmjOYCOZYcThRFfZDX+EqbrKJvgQgWhxyYI4mhtW8Ik4gJ0hg5Sua1iSoJUwqD5L+xLV+nJoAmn gAN5LSP0WakHWG9B9sAcPG33TD5nyFE/Zd+wiqfKYHq4+WteIQAJk6gW6TglbfiICcW6TXG2lzq1P f9sN7xtuIliHtqGBkx9yNtX4qcpBHVq2cFWwtfuri9SvCHTXXJLq0ZKiwy3HZUwWgACg7J36K0t9O 4UKhzsogA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhNH-0008UP-0Y; Fri, 13 Nov 2020 22:16:55 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhMp-0008Jy-5f for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 22:16:28 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id dp12so1218667qvb.2 for ; Fri, 13 Nov 2020 14:16:25 -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=dmp1Ztz+z0/5ouydww+9T91eTtvP6ouU0pc5TkOOGLA=; b=Sdo5xec8tSPhCBD9HVH8oNcti7JVTWAnBqJi7WPO+NIzZ54aQM4HnIl9inItDYW9TC bWQnh825FCOq1JbkMy+NkSB4AVLMhpX+g+PXDkRZZ01lqZNcunr+cbO8MIgc2XMnG6A9 hEZlaG6pJji1w1WY/Ro6jjOdZQQ13+E9oFooGxh/LYDljzPaLqWwSpP+ZsA4LPogN+L9 9ZvpH284+FMQnyYPcBtAWhfxNcqHVS5+NOUJZmA4cZ6JhgrMxptwag1+wTZFpw1+8SzL DI+yQIpxec4CGc1SDFD1mc9aujwDnpZrPQo8usyFzbapOYdcVAyX+SjUK3jUILKi5ywY Fgdg== 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=dmp1Ztz+z0/5ouydww+9T91eTtvP6ouU0pc5TkOOGLA=; b=n+C1nkUzhrVoW8m0va6vKsGMSGsKZ4BftHQN9CAAcz+6w4cey6WrOaToGQ+GLuwvl9 mZEPzHtdlvudU3pZvwElprCFl3I5X1hdCdgYmG8W9DEnRug3ORPSN05JtI4DBBvhzD0S USOqMXitxne8pQC5sBaKfRnyPVbuMxgnIF1oPMtPNkbU6bwlHt/MXsxm4u2VpDSWRYsE M7LzubA9ss27jFi9+yASbiCkGJWJTx4rCKuJWhPxQ+OAYUWw/CXuqwcAhuG6zxbsCVJh nvx+3rqHSYaQ5rcw4dLpa5rio5eC5HU5hL3xLUwvfEzziWJzV6ZtnPhdJ7fdPvNmqYs2 x0jA== X-Gm-Message-State: AOAM532nlPW/HN4J4Uho5YQw3Y8Hgf+JAzWzSM8irL7zfDtudIiMTfpg Cxu5Si5wZBSsEf+rp1NfJ+XN8mJ80D1+d12X X-Google-Smtp-Source: ABdhPJzEbY0rG6ltfJUnnmISccnN45yIP/Gez6V2X6kPmpzEcbfHuqVMAkyZ1+7W2inavCFGTR8CMeGZVtrYJfDm X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:5387:: with SMTP id i7mr4558075qvv.43.1605305783806; Fri, 13 Nov 2020 14:16:23 -0800 (PST) Date: Fri, 13 Nov 2020 23:15:32 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH mm v10 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-20201113_171627_438655_8BE5E4AE X-CRM114-Status: GOOD ( 16.44 ) 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);