From patchwork Wed Nov 4 23:18:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883233 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 880D4C00A89 for ; Thu, 5 Nov 2020 04:55:51 +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 04D6C2083B for ; Thu, 5 Nov 2020 04:55:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="S7Mu8/UZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CLw0LP3H"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dgN/w1am" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 04D6C2083B 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=MMVGao1u3fYlm+mzvjZQ+o67sqCJQv0+CnGTaOb4+ww=; b=S7Mu8/UZDDnHvbXykUHxjWJzy O6KqCLwfny/0Xz+G1h4GZ/t/qVY+UUFecQ0X04LbQr569YtRWcM10N+c6P/rr8hWTnbknsJUXRt2b Hvfs0xxi3Xf3pnN0P0YG27HDoNFkFTXE8C4f02mN0Bu5Qq6Ie2PlHX2aV3h4i9zo+L1th/vkQgd6W TQAnkSHgvQ6Ffp8BUUDrO58IvMN9hXI7ZmJSAREuVeva9UeYWxDV7F3DfUnhY4IyEQS3WrbI/jFBJ rvLn+6ek0tUdLKSqEBOFy1vmx9/JSUtLPCGcARiNnSh30oTp1OYg2OK4IuHhsjuamTESbio96bV8K YcAfUrcSw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXI1-0001Om-MK; Thu, 05 Nov 2020 04:54:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5M-00016k-KK for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=nboRM2CFBpQGYkXl6uRGVt4iydoGbxyL4XKrxiXLpKY=; b=CLw0LP3HXk5RGjISqnXidXtJ3A fMY4qHW0eMNgDyOEQh22iYLqZU/k/xc6yCsX5RYH2tWvxpwToA8o5nDRFUewDnaQeePjk7si3cSPv dW5cLWwTI2YEv/l8tXfbxSuhzUjlijUZ7kxV4WQarTmbuqnXheFgRXvUD0OvMIAYWVEG9Ie8Q0Crp JR/x56hQjqCD8MOa0IdAzFTdI1VEJdLIuuflN8KynVSPCd98lQ2RCXYMlWYW0Ot5d9zBOgzR+XWv3 hF87ArLkTslenASb7Vew3uMWkiSmJjZtsLrXGr6sbYbQOCdvcyX1xxqB+AtnsWJcI2ADp7C0zXr7p JBJrPG9w==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4i-0003uM-M8 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:23 +0000 Received: by mail-wr1-x44a.google.com with SMTP id h8so44306wrt.9 for ; Wed, 04 Nov 2020 15:20:20 -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=nboRM2CFBpQGYkXl6uRGVt4iydoGbxyL4XKrxiXLpKY=; b=dgN/w1amHzWAucOFICHabUoYKns9E0EW4S17djL5Mq75cVwBGdDZqGYn8Qeq7nvUMW M97Jt+7e9lvcxl2kI9TAb+GXKY0QiGMIdyQ80daOWo5mtsE7SwttKp2xBsEJ2yjJSSCQ ayJDF8IL3/w0AgWFJMHoxvvtX/6pIISNeXHtetBbvP07VtsxAq5Dv50zks2RcMAKViLG CkyCLE5yfn5OdhtwmcfKGxnNruhoxrd+swkNI0152pnDJP/YtMLok9KSOn6eqZ38+VjO +BSkyPd2W9vydTe8BECVlFQ+za6j6eQ8FXktVLuLm2s382u0spMvJohHeUQmMlt4pBxG MK8w== 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=kNdoVuPQ7uKQsR4ot9neZ2NvZQxZTMr/0s1Obgsvx98R66rbwyZGDu4SoRiKmCgWMi SBP1kLzlPcYwZDNvMSKdx1sYIqpArsOmUTE2Jo3xQ4ueiU++kjM9/FdvxlEBhFa+oBV5 GFzmqKeP3AovxIuFN0WEc6JYcbHgIB2OKIJIdDCBRGfjxJFk5n3gY5/SPL2Qi2/0uEut sLIapkPp/4JtETuVcMofwEykUOojpLLdza3aLDdrSepZCpKAHy6iD7YSQsxFQ87gNBPg mL1Zm1hBaJDMa/E63sEjRjtOCUIBKdjhohkpEBxSTtj/d0e/SvJX7nFJ0WwLJERoqL+U bW3A== X-Gm-Message-State: AOAM531XwZmh5kg9CofKrIzDK4IHcUFRHrAWt4kOxuEOGSuOGBWMS+/Q O7HcLFGms/fe3HwYPZpikZhj3qb3YC5OqB9t X-Google-Smtp-Source: ABdhPJyqM0dDi4GfWkh1I27aN5R/lBK00hzYxseangjAFcdYFNu3XKGF2HJ+8fAAEsbL6D3qdB2J3NKnTJRwJA6F X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:4957:: with SMTP id w84mr86567wma.84.1604531958343; Wed, 04 Nov 2020 15:19:18 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:20 +0100 In-Reply-To: Message-Id: <36545c406b0aea73f636fa25e85de6a86a349775.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 05/43] 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-20201104_232020_869987_76143C06 X-CRM114-Status: GOOD ( 12.83 ) 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 --- 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);