From patchwork Mon Nov 23 20:07:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926465 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 98592C63697 for ; Mon, 23 Nov 2020 20:14:38 +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 0A00420715 for ; Mon, 23 Nov 2020 20:14:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gfh2DSwf"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="O7WwYPWk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A00420715 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=hfRjr1IfXkMzHLf5/B8cZ6P2Arfq5UUz2SQVQLwHK4Y=; b=gfh2DSwfI54NlpspB8jH+zBpA GHlnc0gZBNSCMn9KvkjbzwqhS4/TqGBLMjnYwc0NhdHKojMQWDYe3oUdW+t9VEjNFOVHhqH3YZfyJ fYROjrVQt+7Gs3LAxJ80vFql8GF23/upU3sJV2KBxX0lBiWK0VtlaAJGWYtfkU1crm1vOG+F0shUO EVZHCqtw3dHgSjxfU45o+iIVH6AvvaS3RWAOnbNHTzW9+3mIcSlQ9H9PcGg0plMRzJQg4CYRk4yG5 j8BDqjK8gh9vRgyAdG9ejxszMmAF4WoFmCIrPfd0caDPWbODxWaq1xfXEr4zC1EAK2G3a6s+O+GUg 8cMUAcEiQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIDp-0001cP-7s; Mon, 23 Nov 2020 20:14:01 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khI8v-00086U-51 for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:09:28 +0000 Received: by mail-wm1-x349.google.com with SMTP id g72so148124wme.6 for ; Mon, 23 Nov 2020 12:08:55 -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=j0H1kye0JXAlJChaoMRiBPaX4tsiHsBeGw6rmAAJgEQ=; b=O7WwYPWkQiF4+62IOKMAx/X6Ff4hjiF7JYrJFo/ly8VYHByg8L4B0btLKLwABYm1E8 huMTztyv6O5Vrgz8sBZZwst4glDNATB4SZiVghUn4WxngW8pNQjBDoEMwcfJ9shQSMsa +rp8UhMu5RjBnl1zpNZRlGA/wkHWpDzGUBMp2K1RA6jVh255LtMbr/aY75SZ9USI9Y5C 62SUTsyhlGsBidwuh0TTdO+9ouXcaJIxs6CQVOxbSEczlZX1+gxW+27fvDhongyYW9oI ZEBvcEiKR+icBV3JM3nyaBkmTkyAI0yhKfLUwRkh9x9mGZiTSJz+vHTpLb6M7XAYPUd6 ReUg== 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=j0H1kye0JXAlJChaoMRiBPaX4tsiHsBeGw6rmAAJgEQ=; b=DKieXaHuyle1VYr0vjjsECF/7CnavIhXe102gI8FbnW/XoPc1E36MFPJ0HdQ3RxGyk rdWFwrFr7odfQZMe0wLBqe4lkWlSLKw/69NPgYUa6FP2fkEKLYxBAyVLHO9dB+0q4+88 zxSJSOgKMiHmg/rADGZsIUgKaQqtbSn++C4Q0EezZwdPMJpBUrZ5wgWffW/Cs+UTEvgB cDhe0AVbtOH7JGjYvZaZ3GuNgZ8m3ZLrFY3T8QHH4ERRap0l9OMPzsiMQjx6P9mjQa7d 39sl+CjcQWuvRVWFC7tHAtvBb88geauKHqnIOTdgoLPEr6Yx//dNwPrF8X6LGGys0LV/ aXuA== X-Gm-Message-State: AOAM530YELbzGLRDUHy5Nlma4/FL7su9/XFZpbrmPIuMCeJ4Ox5yDJ8O YaxVNFPntaPAkvX2pzGY6wdfUvptNcYRBmXE X-Google-Smtp-Source: ABdhPJy1ZujxVINbJkA1qNZ/uTPkGYGCdGMYLsjhYtl31l+sZgjPNZrDJ+QGJJelBlD6IqphjApEnnniIPvBlkMx X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:a752:: with SMTP id q79mr630695wme.24.1606162134262; Mon, 23 Nov 2020 12:08:54 -0800 (PST) Date: Mon, 23 Nov 2020 21:07:39 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v11 15/42] kasan, arm64: only use kasan_depth 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-20201123_150857_284879_2A2B3E99 X-CRM114-Status: GOOD ( 19.37 ) 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. 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 d237051dca58..58567a672c5c 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_range(const void *address, size_t size); void kasan_unpoison_task_stack(struct task_struct *task); @@ -121,9 +124,6 @@ static inline void kasan_unpoison_range(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 e53e2b110128..d440060c9008 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1225,7 +1225,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 ae55570b4d32..52fa763d2169 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -47,6 +47,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++; @@ -56,6 +57,7 @@ void kasan_disable_current(void) { current->kasan_depth--; } +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ void kasan_unpoison_range(const void *address, size_t size) { 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);