From patchwork Tue Nov 10 22:10:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895625 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 4FC67C388F7 for ; Tue, 10 Nov 2020 22:18:00 +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 DB65B20674 for ; Tue, 10 Nov 2020 22:17:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1Z1QMTg2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Iu8mOEF+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB65B20674 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=7mspDZAFNT7MXdB9Sg4nakqSVUHqGg4nf2zy9K23dyA=; b=1Z1QMTg2v7rNBsGJi4KUs34Az DLbOxujngp6X6kFlUcH96QoEWVtQVOyDBroEZQbcvqlfFkh4RGsIgj7k4RiQvZwDuEd7QavWgnWHC BetQqxRpAEESuV1wSHZfhjDn4BJzZVjyJFXgnwHVsD5ZDC+OEAASXkxLNx1gxc3mGabA4xk6VAXIP jgXB8oa89cnuD/64Fm2dwlGZqpl6mgdHStheBoYiAvjGhyX+L+GVvHpzWTB+V89SPe17cHauMMoYG Zeuv+lpgQR8o+AA0us/kcgxtGO224uulXBu34AOZfYaotu2I//WEzU1LTipE/0VrkIz/1+rq1IKgl wXgNe+lhQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbwo-0006vj-R3; Tue, 10 Nov 2020 22:17:06 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbrj-0004fW-01 for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:12:08 +0000 Received: by mail-wr1-x44a.google.com with SMTP id f4so3141700wru.21 for ; Tue, 10 Nov 2020 14:11:45 -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=LK+ho829pHfUNxMsQpfFeZONsS3mumkNxCYvKzzjGVY=; b=Iu8mOEF+Li9wr5hKAd+tC0Mwca6uicD2b8KPgwTOydhUrA3B4aOlCl4MuBGmr5BvKP /UUvYx9LID/p6iPDXMv7qnWWabdkwfj+e+lMaUOpWxpNe1JoisxTBJgoHQALnnnR20Xv mRM9/hm+v9v5Qe40llhqaEAyJeaVz+IndNysIoUEPXZv5LTeEIPXtfmSEmReS3MYC/vc +oSRgyD+g4km4bb+mvn+cyMWJGqEBJfWkmkCFcX+73SOZ3GIG+SOVvVreCQfSloA7VbD LK1ozVQ+YcOVFThdLtwWbxcyX0QAVZWBzpsnURXP2Tw/vb7dn5clPxfj6N2ldpF+lxLR b8uQ== 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=LK+ho829pHfUNxMsQpfFeZONsS3mumkNxCYvKzzjGVY=; b=n9q7ckwmSz2DZOX5KIogT9jkwEW3z2CCMRGREIrnDZHCJy5gFMqZB1Z+8VPOHZyrcZ 2kNlnyQferWdiqoEyc+uhTSXnvvcMxSuvRLYt1APCUi+KXT3FAwsbQFuoYl8KeK8Jtkz wJxCIv/ETvor5kfDSU/gL9KEWY/9ewAn5Luop5rITcnDRtrrDoBR2DxETh3rmGrHwUY3 AWXYF7agb07Tmd7Itl/QOs/MZIx7hfctRMPf6AEWxWkIIS4Fgl1TLd36wXYdYzPDwm5O FKOx6D2HxCcZJolpbShgvymkpw1pkggoYsZi9nBoWcyqBIdYH+GxvfrLc50lyn04lYY9 GREg== X-Gm-Message-State: AOAM533bcHnArpdFbYMNkozj2d+K4VhX8hILRgLi1WfugP1GJxNzkU+0 RiilbHjXt46bSWkaWgR70yCahCM3z3qNjZKB X-Google-Smtp-Source: ABdhPJzef0gbAHZj8RghJAAJMQiMzdnzsNe+ZmY4MQP/bt6+y3z+ulRgrVIQmKUJY1NZpXA/nMBKFSwf+beC9FzD X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:3c84:: with SMTP id j126mr226389wma.151.1605046304637; Tue, 10 Nov 2020 14:11:44 -0800 (PST) Date: Tue, 10 Nov 2020 23:10:13 +0100 In-Reply-To: Message-Id: <91b3defa17748a61d1432929a80890043ca8dcda.1605046192.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v9 16/44] kasan, arm64: only use kasan_depth 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-20201110_171151_093258_41A5E195 X-CRM114-Status: GOOD ( 18.61 ) 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. Hardware tag-based KASAN won't use kasan_depth. Only define and use it when one of the software KASAN modes are enabled. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas Reviewed-by: Alexander Potapenko --- Change-Id: I6109ea96c8df41ef6d75ad71bf22c1c8fa234a9a --- arch/arm64/mm/kasan_init.c | 11 ++++++++--- include/linux/kasan.h | 18 +++++++++--------- include/linux/sched.h | 2 +- init/init_task.c | 2 +- mm/kasan/common.c | 2 ++ mm/kasan/report.c | 2 ++ 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index ffeb80d5aa8d..5172799f831f 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -273,17 +273,22 @@ static void __init kasan_init_shadow(void) cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); } +static void __init kasan_init_depth(void) +{ + init_task.kasan_depth = 0; +} + #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) */ static inline void __init kasan_init_shadow(void) { } +static inline void __init kasan_init_depth(void) { } + #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ void __init kasan_init(void) { kasan_init_shadow(); - - /* At this point kasan is fully initialized. Enable error messages */ - init_task.kasan_depth = 0; + kasan_init_depth(); pr_info("KernelAddressSanitizer initialized\n"); } diff --git a/include/linux/kasan.h b/include/linux/kasan.h index f6435b9f889c..979d598e1c30 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -51,6 +51,12 @@ static inline void *kasan_mem_to_shadow(const void *addr) int kasan_add_zero_shadow(void *start, unsigned long size); void kasan_remove_zero_shadow(void *start, unsigned long size); +/* Enable reporting bugs after kasan_disable_current() */ +extern void kasan_enable_current(void); + +/* Disable reporting bugs for current task */ +extern void kasan_disable_current(void); + #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ static inline int kasan_add_zero_shadow(void *start, unsigned long size) @@ -61,16 +67,13 @@ static inline void kasan_remove_zero_shadow(void *start, unsigned long size) {} +static inline void kasan_enable_current(void) {} +static inline void kasan_disable_current(void) {} + #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ #ifdef CONFIG_KASAN -/* Enable reporting bugs after kasan_disable_current() */ -extern void kasan_enable_current(void); - -/* Disable reporting bugs for current task */ -extern void kasan_disable_current(void); - void kasan_unpoison_memory(const void *address, size_t size); void kasan_unpoison_task_stack(struct task_struct *task); @@ -121,9 +124,6 @@ static inline void kasan_unpoison_memory(const void *address, size_t size) {} static inline void kasan_unpoison_task_stack(struct task_struct *task) {} -static inline void kasan_enable_current(void) {} -static inline void kasan_disable_current(void) {} - static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} diff --git a/include/linux/sched.h b/include/linux/sched.h index 063cd120b459..81b09bd31186 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1197,7 +1197,7 @@ struct task_struct { u64 timer_slack_ns; u64 default_timer_slack_ns; -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) unsigned int kasan_depth; #endif diff --git a/init/init_task.c b/init/init_task.c index a56f0abb63e9..39703b4ef1f1 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -176,7 +176,7 @@ struct task_struct init_task .numa_group = NULL, .numa_faults = NULL, #endif -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) .kasan_depth = 1, #endif #ifdef CONFIG_KCSAN diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 543e6bf2168f..d0b3ff410b0c 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -46,6 +46,7 @@ void kasan_set_track(struct kasan_track *track, gfp_t flags) track->stack = kasan_save_stack(flags); } +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) void kasan_enable_current(void) { current->kasan_depth++; @@ -55,6 +56,7 @@ void kasan_disable_current(void) { current->kasan_depth--; } +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) { diff --git a/mm/kasan/report.c b/mm/kasan/report.c index b18d193f7f58..af9138ea54ad 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -292,8 +292,10 @@ static void print_shadow_for_address(const void *addr) static bool report_enabled(void) { +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) if (current->kasan_depth) return false; +#endif if (test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) return true; return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags);