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: 11926387 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.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 55B4AC63697 for ; Mon, 23 Nov 2020 20:08:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA3BC20717 for ; Mon, 23 Nov 2020 20:08:58 +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="O7WwYPWk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA3BC20717 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 C7DE46B009C; Mon, 23 Nov 2020 15:08:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C07C56B009D; Mon, 23 Nov 2020 15:08:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7FD16B009E; Mon, 23 Nov 2020 15:08:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id 6E7676B009C for ; Mon, 23 Nov 2020 15:08:56 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 175EF181AEF1A for ; Mon, 23 Nov 2020 20:08:56 +0000 (UTC) X-FDA: 77516771472.15.boat62_4001d4827368 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id EA1D41814B0C1 for ; Mon, 23 Nov 2020 20:08:55 +0000 (UTC) X-HE-Tag: boat62_4001d4827368 X-Filterd-Recvd-Size: 8850 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Nov 2020 20:08:55 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id o17so141700wmd.9 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=L5YRcbshqbEItAji7vC0KslPW1q/WMCJM4CGJtvjxIPDoaUF24EQsGBM3BKuHOh47l y+JV6gygbU1VU/eoVkabcYm3jTm+MdpaAHcXGBTe1YADJuJ6yCdEesHdf3bNx4wYHprT GOgx6p6RSxD6OEdsbiMCvRgCBbQ64+bvwpXrfRNvkBjqzus6H8kwm4A/tU8OHvVDJz5+ zxiQJjed3etyp7s0nxEiolKTn4cZCTTF1obvnPaEpZSs4iQFOXu8NTzEfluv9VVWEweu lPQ7qX2oWdZqbp8NPhCExZCgMRL8j7N4LFxpd9e5ondiXGfvN2mfHbwiS0pUJLjYMGOn TwFQ== X-Gm-Message-State: AOAM533kul9V/ZDrGRgvDC/9PSagQ+H2HqFRXgKtoh8XSp0QwyAXUAtm iYW+YJBF2KVT+IeDEC1/r6758wW0H0fHDHDh 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 Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, 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. 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);