Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3289093pxf; Mon, 15 Mar 2021 06:22:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN0QL4KcccZFDu7qwmzzR4sz4KQ5/O0n1HbBLcOjoHmhWIdP0C/pM25qsZM7klHMmjOzew X-Received: by 2002:a05:6402:22f6:: with SMTP id dn22mr29407100edb.214.1615814544318; Mon, 15 Mar 2021 06:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615814544; cv=none; d=google.com; s=arc-20160816; b=z+3ape1pYJd7w5CBtlWxLP61LZG5ZLfkpsDh62qiPQ4c7/hKczW60FZmwawmNB1HOR 4twyMd/WTy7y2+NoV5xHlE/UFYvVNJbdBTVhwQc7rrToBafMwdBHf7EfOGyOOFOswYnx 8yTfIA0iCbSsSiu2VSBa7yDGhYlDP28Gg5ksEiE57w/ULn63JiRxfYfljHSJTzYHLQ61 Pi53RzsmPlrbPUJfiXA4Bn/RYyCl/fQTZaPGdHRkkZqGVYu226P+NyP/ovl8cqD4+3b9 H6fuG8ZHcl2JmXz2yU3+wFYzODDyzM7Wmi0L+WsXgT0l+A4cGh3piNhaMBh/rxP/iQCI rS0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=WjA/D/j2uujoyj1qbB7tk/Evdiq/flAsV6eMkmYGi3A=; b=mvPdKHN4JrUB45qyzEYdQ5NnUXFTseJ9+oAQSfgS2cDvfTmnfnJ7cDaiRMoNn2iJ6V TD9pMAdHV69P0/xxHfgUPzCDNOJWyhjmLxIVm28XBkJPAFfrCb4Hud3Lavg3mYtxNq+v AzUHs1641a6seGlPw3ROtN9ohhrql5AUOc4sthFjQDz9nwugAq3qQP3PyG7qLTCjPpOJ BDZ0Xr5l5Obj2tm87XnaWv0Z7SyGBZAmv72Q4PFV6Q7iYSmj/8d7a0K4qm790ZwKt4rB HgaU2CuATQKApe0wlanLijsyRm+4LHejCnGg/sXfi0DJBfk1bI43uzd43Uu4+lhMhVnE KYcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ss27si11099217ejb.322.2021.03.15.06.22.02; Mon, 15 Mar 2021 06:22:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230307AbhCONUx (ORCPT + 99 others); Mon, 15 Mar 2021 09:20:53 -0400 Received: from foss.arm.com ([217.140.110.172]:39934 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbhCONUi (ORCPT ); Mon, 15 Mar 2021 09:20:38 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A6D5F12FC; Mon, 15 Mar 2021 06:20:37 -0700 (PDT) Received: from e119884-lin.cambridge.arm.com (e119884-lin.cambridge.arm.com [10.1.196.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C2A4A3F792; Mon, 15 Mar 2021 06:20:35 -0700 (PDT) From: Vincenzo Frascino To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Cc: Vincenzo Frascino , Andrew Morton , Catalin Marinas , Will Deacon , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Andrey Konovalov , Lorenzo Pieralisi Subject: [PATCH v16 4/9] kasan: Add report for async mode Date: Mon, 15 Mar 2021 13:20:14 +0000 Message-Id: <20210315132019.33202-5-vincenzo.frascino@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315132019.33202-1-vincenzo.frascino@arm.com> References: <20210315132019.33202-1-vincenzo.frascino@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org KASAN provides an asynchronous mode of execution. Add reporting functionality for this mode. Cc: Dmitry Vyukov Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Reviewed-by: Andrey Konovalov Acked-by: Catalin Marinas Acked-by: Andrey Konovalov Tested-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 6 ++++++ mm/kasan/kasan.h | 16 ++++++++++++++++ mm/kasan/report.c | 17 ++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 8b3b99d659b7..b1678a61e6a7 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -393,6 +393,12 @@ static inline void *kasan_reset_tag(const void *addr) #endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS*/ +#ifdef CONFIG_KASAN_HW_TAGS + +void kasan_report_async(void); + +#endif /* CONFIG_KASAN_HW_TAGS */ + #ifdef CONFIG_KASAN_SW_TAGS void __init kasan_init_sw_tags(void); #else diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 9d97b104c3b0..56b155ddaf30 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -7,17 +7,33 @@ #include #ifdef CONFIG_KASAN_HW_TAGS + #include + DECLARE_STATIC_KEY_FALSE(kasan_flag_stacktrace); +extern bool kasan_flag_async __ro_after_init; + static inline bool kasan_stack_collection_enabled(void) { return static_branch_unlikely(&kasan_flag_stacktrace); } + +static inline bool kasan_async_mode_enabled(void) +{ + return kasan_flag_async; +} #else + static inline bool kasan_stack_collection_enabled(void) { return true; } + +static inline bool kasan_async_mode_enabled(void) +{ + return false; +} + #endif extern bool kasan_flag_panic __ro_after_init; diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 87b271206163..8b0843a2cdd7 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -87,7 +87,8 @@ static void start_report(unsigned long *flags) static void end_report(unsigned long *flags, unsigned long addr) { - trace_error_report_end(ERROR_DETECTOR_KASAN, addr); + if (!kasan_async_mode_enabled()) + trace_error_report_end(ERROR_DETECTOR_KASAN, addr); pr_err("==================================================================\n"); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); spin_unlock_irqrestore(&report_lock, *flags); @@ -360,6 +361,20 @@ void kasan_report_invalid_free(void *object, unsigned long ip) end_report(&flags, (unsigned long)object); } +#ifdef CONFIG_KASAN_HW_TAGS +void kasan_report_async(void) +{ + unsigned long flags; + + start_report(&flags); + pr_err("BUG: KASAN: invalid-access\n"); + pr_err("Asynchronous mode enabled: no access details available\n"); + pr_err("\n"); + dump_stack(); + end_report(&flags, 0); +} +#endif /* CONFIG_KASAN_HW_TAGS */ + static void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip) { -- 2.30.2