From patchwork Fri Nov 13 22:15:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11905013 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 12ADAC4742C for ; Fri, 13 Nov 2020 22:24:50 +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 B8182207DE for ; Fri, 13 Nov 2020 22:24:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BmuzSfIQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="nVndJlcF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8182207DE 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=8Xv1hTgxoBoRtKXrq3xKkHwbdbJhJCy+xjtLgvJElS4=; b=BmuzSfIQm79pxzJGCWjXTrOmp UBG//uNRgBU25p4bMh6Ec0jI+CFDrJpNtUuthf7iH+jIrWr6sUPS0cbjjUlVF6dIgn45I1118NMQZ AgTirgMfV1LnC/wbbyN0IHct6tNU8tyWly6Kndxiz71B0KNjk68edmCwEqJixIVeDqMJC7NW74aeS 0wU3O7aEgLHr6uoO31uH6DSqMIhS6heWPTV98bfjBG+Ajpu+6lGAulruxJgI8IUEtzfKkDAoCE93i jKZGFtCoW3ejOx5Zs4TpljK1nUtpRkBdPzIFn6U3KX+pfMfz8SiXFxny7dCeJTbzQGkc9ukNZcyHZ GKY6r2Zcg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhT0-0002T9-8q; Fri, 13 Nov 2020 22:22:50 +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 1kdhNG-0008Vb-Ix for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 22:17:13 +0000 Received: by mail-wm1-x349.google.com with SMTP id 14so4717380wmg.1 for ; Fri, 13 Nov 2020 14:16:51 -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=ntObSH5Wts69G9iVeYOB8VW5d6k5gPFIMEcmSrRrEtM=; b=nVndJlcFGG+2Wgj+xg9aMHiKFEZYhIglZVAS4t49zG4AAkogMnXeXStL6s9dGMQqd0 RBTPELv3GlCVKd6MdJfs7w6pfD28+LS9Af6oAW2ZnBO6HSAd5cyT9vrLd09nVtRJMqfR hvSWvqiId2xsk7+h9Qyw++vHpNRMu92ZWTTKWUvbHXpoCIIiqo9SoYdQJt6w8Sbv9Vkr LA+l14xw9x8udFs3GU8LVAKb4za1i//bbOptaQxA2CHiinozbukE/T0VByhyxYhtokC7 Bt3s+lImUoBECC/uKxY5zVqCyw2qdT86Mvee5zeTHM4GPjSf+E9hjh0GiSj8YX+wOlMV SZ9g== 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=ntObSH5Wts69G9iVeYOB8VW5d6k5gPFIMEcmSrRrEtM=; b=blgmGgZWo3xu1Ut3awIaQnT59eIwokFU3byHT9oGHJchHQCJ1vELYJDbE83yYb52SF B7O1+58Av7GC3Yfv5VTS1Q4rSkV7wKIzzFAzmMrC15gUM5nuNrXh/e1WCEdvxMNtQ24E o0ORs3nBaLVbgRNYXihOJMiXCUu/rteDA1MtzWaOO/Li9l9Ig63j2XQ89+x5yV704Y8n S7EH9FtTSR/kxr3qX3EGVClm8J2mCLWZIg0gXThbTvu7ya8eM1pc0Y6KTAmFVoMZfFC5 nTiPmw9onOn/KVpizVelQCslY6vnd9+Qt/IJO3CnMg7VAMFZP87LajDg5+q3q9oPGtTS wFyA== X-Gm-Message-State: AOAM530gfv0HuBw63TgNqs8eODgkhPn4JP/duBdFCwndKbs51ovzRQKs JxxZdci3nXoqk17wdRCmJwTL0HvZ8IvbNLFz X-Google-Smtp-Source: ABdhPJw2rgtJo0FTYNpsIx8pk0Z3JmrZZwJI78cD6gWpL2nskNkJO6exfzKl0e7yw8fgF2xSKy05qnSNQSdR8kWY X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:f246:: with SMTP id b6mr5787412wrp.238.1605305810568; Fri, 13 Nov 2020 14:16:50 -0800 (PST) Date: Fri, 13 Nov 2020 23:15:43 +0100 In-Reply-To: Message-Id: <98764bf6acb71bd93f344bcd7441e4ae6091d023.1605305705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH mm v10 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-20201113_171654_739122_63345610 X-CRM114-Status: GOOD ( 19.01 ) 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 8682df0050bf..96f6e581e7eb 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1203,7 +1203,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);