From patchwork Thu Sep 24 22:50:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11798303 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 E7C1717E6 for ; Thu, 24 Sep 2020 22:51:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AAABF2396F for ; Thu, 24 Sep 2020 22:51:04 +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="kXKqNW8E" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAABF2396F 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 9088B8E0007; Thu, 24 Sep 2020 18:51:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7FC158E0001; Thu, 24 Sep 2020 18:51:03 -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 649368E0007; Thu, 24 Sep 2020 18:51:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id 4EA398E0001 for ; Thu, 24 Sep 2020 18:51:03 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0D8182DFA for ; Thu, 24 Sep 2020 22:51:03 +0000 (UTC) X-FDA: 77299452006.12.baby55_09141a227162 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id DDAD918004A08 for ; Thu, 24 Sep 2020 22:51:02 +0000 (UTC) X-Spam-Summary: 1,0,0,89335dcd62279b75,d41d8cd98f00b204,31sjtxwokcnaw9zd0k69h72aa270.ya8749gj-886hwy6.ad2@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:3871:4117:4250:4321:4385:5007:6261:6653:6742:8603:9592:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12683:12895:12986:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21772:21990:30054,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8ba3miqm3js6g3zbfmwadus3o3oce6baku5ec4rwrh3orq1dee6b4sk4ro5q.ngwtfyaxfqju6zgs4ry4x3mzyc1ichocjadxwji6w4xp5zbqd7ztca753fce66j.a-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,D X-HE-Tag: baby55_09141a227162 X-Filterd-Recvd-Size: 6757 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 22:51:02 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id y18so275055wma.4 for ; Thu, 24 Sep 2020 15:51:02 -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=o+5muahIyzBsCSQYTa2yEzLZS8Az5j3CfnIGZXwP7nI=; b=kXKqNW8E1mov7NpuLnK47U4pBbnLrdaxpw+5SAN0ltF5XUY0lFHMBL3W7EChB4zCQL QQFIk/6iv+ghmYhrNImHBqmmnRih4Zok72+1NsHqbj9q2ALs9hwUX9mNLJyEHpToqgWh tFUAqd3A0JxQ6N/uzYcU5IxlzfLN/5V0hsgFxp7EYzA5mKyOPdjJfvxvnJaZaQSGKY8g UXfXKhmVviLGaHWh6ftOKsSfXgT9bxcf2XOtxMWstc6u6xRosbEwHezA7MI2fW0rO4TM r8sFxm2VdRxzYH3O+EUoYDnRiL8nn/Xh9J54aDEAtcMuhzclKGM2hRemfaCT9XoaX2Q5 CDuw== 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=o+5muahIyzBsCSQYTa2yEzLZS8Az5j3CfnIGZXwP7nI=; b=SCGCssqqn/8eaawnGu5S16hpolkW6b407qx3NMYY0/H3qBfECAKiHjQDIsHEbQIoF1 Ge7D5C2y9/EbqeRQjjygY75xtoEQ7uFLHdzDiBC+QoXST0kkW5uoCQ3hOwJLeTLeJuYH wKqyvLdtJVwQV1KjLmUxjpzkbAfMudoLFYNwRleY2bVve7aSzvGytUqqF5DFjYh+PXHU BxW+TMd4My1E7nGJNPQhI0kwm4HkiO4DE2n6Zv6p768EGMBLTyFm8xtbTll5zOEDjaJc tHTMq88eFlI33N+AjNbAsbSzRDC8VWQiGQi0QiUzw6/4aLid2f9a9p7ESP5JFpTil7zd qLcA== X-Gm-Message-State: AOAM531FKTqV2fwIPda2HPXCf3Ta4Byy8Y8UQ5qSt3bKQh1/zJaQLXJf qxgInutMriaxzR1F45AwICyUNqIAP89RpZqQ X-Google-Smtp-Source: ABdhPJyehUeiSJg+kXRxdeDQ0lGhmutHtVinnAroN/FF5UMTOjOh25DNFbXLwa+fkNeTRy0ybwFRHtyLRI1oOeSB X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:750d:: with SMTP id o13mr918934wmc.54.1600987861205; Thu, 24 Sep 2020 15:51:01 -0700 (PDT) Date: Fri, 25 Sep 2020 00:50:11 +0200 In-Reply-To: Message-Id: <9de4c3b360444c66fcf454e0880fc655c5d80395.1600987622.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog Subject: [PATCH v3 04/39] kasan: shadow declarations only for software modes From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , 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 | 44 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index bd5b4965a269..44a9aae44138 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -3,16 +3,24 @@ #define _LINUX_KASAN_H #include +#include struct kmem_cache; struct page; struct vm_struct; struct task_struct; -#ifdef CONFIG_KASAN +#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 extern unsigned char kasan_early_shadow_page[PAGE_SIZE]; extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE]; @@ -29,6 +37,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); @@ -69,9 +94,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) { @@ -137,14 +159,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; } @@ -152,8 +166,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); @@ -168,8 +180,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);