From patchwork Thu Oct 29 19:25:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11867199 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 857DE697 for ; Thu, 29 Oct 2020 19:26:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3533F20825 for ; Thu, 29 Oct 2020 19:26:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vLHwj7A5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3533F20825 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CAD456B0093; Thu, 29 Oct 2020 15:26:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C38E96B0095; Thu, 29 Oct 2020 15:26:41 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB7456B0096; Thu, 29 Oct 2020 15:26:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id 700736B0093 for ; Thu, 29 Oct 2020 15:26:41 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 17233180AD815 for ; Thu, 29 Oct 2020 19:26:41 +0000 (UTC) X-FDA: 77425945002.01.stamp16_05000092728f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id E9AFA1004BA8E for ; Thu, 29 Oct 2020 19:26:40 +0000 (UTC) X-Spam-Summary: 1,0,0,3dcb276726a0d0f6,d41d8cd98f00b204,3bxebxwokca4o1r5scy19zu22uzs.q20zw18b-00y9oqy.25u@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:966:968:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3152:3354:3865:3866:3868:3870:3871:4117:4250:4321:4385:5007:6261:6653:6742:8603:9592:9969:10004:10400:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12555:12683:12895:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21772:21990:30054,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04ygp14ag3s5aoowfm6ztdrdzfd4hoce4jh5thw64rwrh3orq1ne49x7k3axhd1.g6by4w8ekjeghjdt4o81rxibbbxeuz13wkmtjddg1fpf1ox8n73h4re5ihjn19e.k-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0, DNSBL:ne X-HE-Tag: stamp16_05000092728f X-Filterd-Recvd-Size: 6724 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Thu, 29 Oct 2020 19:26:40 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id h8so1687214wrt.9 for ; Thu, 29 Oct 2020 12:26:40 -0700 (PDT) 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=nboRM2CFBpQGYkXl6uRGVt4iydoGbxyL4XKrxiXLpKY=; b=vLHwj7A5gFQKqlkRDBMVzX6K9iJ/mMR6bA0PxbMCKvpNLDl67MVinUphj1bWMfnhll 7EKjNu0BDMsx4OjuMmBu1buc9CeCM9Rp7XrvpfoHzRu/rd1Gvv2YQs0StYOBxVndw5nX kz6J3IfTyvPwkKtP9q/qkdOXv1A6QRL8tgQz35+DVVcRoODEGW+K6tAOS8xbfPZlaE+N b0bKgwUI7oPQ03zDlPkFIx36OevYLbvz8z/rFFt4hvH5S6nTaWIvL8KZWULFxVl9NdWg Dvr9udCV+PLe1ftwi9LUy9A3UBWELicytQ5NN1HH5IHd2smHLd/XV0501sRX5FPHQVxo 0xKA== 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=nboRM2CFBpQGYkXl6uRGVt4iydoGbxyL4XKrxiXLpKY=; b=Tj5ySgJ7RpcByG/TL35se5uFsTwybSW6+eDrFznNeCscsuMAOvmviwESPv29cJZIWv wp21b7dwjj/kv5qpGqDDzzqbXvCGlz/4JC7G1hy+PKPQeS/b6JTYFvvTpAL061zRKrz2 faDikKK+ZeDcBOC56p2Rc6ENrFvyiFNV1oL8wlRmL1sIvmn7yjxtfrYOcqlvC/TeVRN0 cD5mGxJ9cJXlSPchrN5PHHNDqucXSuWEdUdjarpt0K1+zJJDo7op85/U9NBOHyG7E5dp NI5lfGVw6rPRPb/z1Oq/wuXbHIOWvLn1r7MNJ6TyWw8BcoWhsCVX4DqXNCK7EWhdskAz uVSw== X-Gm-Message-State: AOAM5318JcCHyFMkM37X4TS8kte3FsXC1Ld6UoiisiKEssJ1FnRJAker IYhi8RQptVNzuhp5C9MgibuuYemU9cGoJOJw X-Google-Smtp-Source: ABdhPJwIIyzSfuuguARDCDhOaa8VXjLTXjjb9PFLkIubsbZADx+X2+oyTkemHPuhBQlyecjUTgfvNXvANDRlo6Ac X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:c58f:: with SMTP id m15mr7428154wrg.144.1603999599104; Thu, 29 Oct 2020 12:26:39 -0700 (PDT) Date: Thu, 29 Oct 2020 20:25:34 +0100 In-Reply-To: Message-Id: <0130b488568090eb2ad2ffc47955122be754cfbe.1603999489.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v6 13/40] kasan: shadow declarations only for software modes From: Andrey Konovalov To: Catalin Marinas , Will Deacon Cc: Vincenzo Frascino , kasan-dev@googlegroups.com, Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: 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 --- Change-Id: I864be75a88b91b443c55e9c2042865e15703e164 --- include/linux/kasan.h | 45 ++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 59538e795df4..45345dd5cfd6 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -10,9 +10,20 @@ struct vm_struct; struct task_struct; #ifdef CONFIG_KASAN +#include +#endif + +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #include -#include + +/* Software KASAN implementations use shadow memory. */ + +#ifdef CONFIG_KASAN_SW_TAGS +#define KASAN_SHADOW_INIT 0xFF +#else +#define KASAN_SHADOW_INIT 0 +#endif /* kasan_data struct is used in KUnit tests for KASAN expected failures */ struct kunit_kasan_expectation { @@ -35,6 +46,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 +103,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 +168,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 +175,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 +189,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);