From patchwork Mon Nov 23 20:08:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926433 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 1268FC64E7A for ; Mon, 23 Nov 2020 20:10:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9407120757 for ; Mon, 23 Nov 2020 20:10:01 +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="neCUGBfU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9407120757 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 DD9E36B00C3; Mon, 23 Nov 2020 15:09:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D67946B00C4; Mon, 23 Nov 2020 15:09:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB5CD6B00C5; Mon, 23 Nov 2020 15:09:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id 887936B00C3 for ; Mon, 23 Nov 2020 15:09:59 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 394921EE6 for ; Mon, 23 Nov 2020 20:09:59 +0000 (UTC) X-FDA: 77516774118.20.scale29_5f0ae8d27368 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 0E34A180C07AF for ; Mon, 23 Nov 2020 20:09:59 +0000 (UTC) X-HE-Tag: scale29_5f0ae8d27368 X-Filterd-Recvd-Size: 6261 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Nov 2020 20:09:58 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id e18so6206833wrs.23 for ; Mon, 23 Nov 2020 12:09:58 -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=a641qLXzuR11g6BMkmBPCphI45HnOtEuvC8VFs/i0oY=; b=neCUGBfUlBvzHcri54FWSxW9eFHJEi3CWU5DBAF4zPMCbuvfGwsZupN3DKSl4x2YO2 7vqXobhxBlVc4efQ67niDqzzonPG6CmZ8lKtswsRFtHRB5S6KJ9BL9qLX1SY6jVRlK2J c8bK+1m7/xA2Uu4LJZyF6EdW29LWsdhb0mdcbLbKb1ISATTP9DZ4EW5trIjboNyfd7aC HYttI9r53xvHWS0nxs6X+83N2tlN7sqRPVBmyAHG05TyuIsDwicUrV8NPu7KlN4y34LU +ZxMuRL8VspB5gYyX/oM2BumjWXcbDi+SbTROi1rcPb8rDabu7K1Hw9NMV7Isx7hQ28t wgvg== 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=a641qLXzuR11g6BMkmBPCphI45HnOtEuvC8VFs/i0oY=; b=TBwGkg8AgwieVeIiY/W5JwSVp1t2QjriSJFWN3T0y3G676TRmHDhm87dZd2/AFapbo JSqE+945C47RntuhxDrDuuqtzNUHInbNNZtJ3iLftwAeiEz+CcrJ57DD6gSlZwDUrBkd yGRsFbnMGJIYQMYDhG9/EZBNZ0MWSwDIN9J5SBmO/liu7GLjlIkjJbwiKUCwzrV8hvEy 0sJOtuqPP5mUlwUSzcQhVCkIdEq258lDLO0zFnpEh6/7TUSJ2e9ONCocT4N4QZIZCB1o 6zkR3e0cjoGCKoZ+zdf558BReZkRUckZzOlzNTUMw13JruNDsy/4tx/mx9KGe+BAvjKt mrpA== X-Gm-Message-State: AOAM530/zUkRi2duyuF/hT+PU8Q7egf8DhSQ6w9+7WieYQWUQt0yLjLI sEK6jDzf5TwglcKMc+NhDmuzz3jdWrPp1y4v X-Google-Smtp-Source: ABdhPJzbUN3oGIDfvcDJArPlcXQTm+qdElAwFv2IDBGPxqRS3v2vpJpKfw3cPWg5H2l2qDnAYZ5sX0jh1Pa8TG1/ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:bd0b:: with SMTP id n11mr580484wmf.111.1606162197472; Mon, 23 Nov 2020 12:09:57 -0800 (PST) Date: Mon, 23 Nov 2020 21:08:02 +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 38/42] kasan, arm64: print report from tag fault handler 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: Add error reporting for hardware tag-based KASAN. When CONFIG_KASAN_HW_TAGS is enabled, print KASAN report from the arm64 tag fault handler. SAS bits aren't set in ESR for all faults reported in EL1, so it's impossible to find out the size of the access the caused the fault. Adapt KASAN reporting code to handle this case. Signed-off-by: Andrey Konovalov Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas Reviewed-by: Alexander Potapenko --- Change-Id: I3780fe7db6e075dff2937d3d8508f55c9322b095 --- arch/arm64/mm/fault.c | 14 ++++++++++++++ mm/kasan/report.c | 11 ++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 1e4b9353c68a..3aac2e72f81e 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -298,10 +299,23 @@ static void die_kernel_fault(const char *msg, unsigned long addr, do_exit(SIGKILL); } +#ifdef CONFIG_KASAN_HW_TAGS static void report_tag_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) { + bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0; + + /* + * SAS bits aren't set for all faults reported in EL1, so we can't + * find out access size. + */ + kasan_report(addr, 0, is_write, regs->pc); } +#else +/* Tag faults aren't enabled without CONFIG_KASAN_HW_TAGS. */ +static inline void report_tag_fault(unsigned long addr, unsigned int esr, + struct pt_regs *regs) { } +#endif static void do_tag_recovery(unsigned long addr, unsigned int esr, struct pt_regs *regs) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 2c503b667413..a69c2827a125 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -62,9 +62,14 @@ static void print_error_description(struct kasan_access_info *info) { pr_err("BUG: KASAN: %s in %pS\n", get_bug_type(info), (void *)info->ip); - pr_err("%s of size %zu at addr %px by task %s/%d\n", - info->is_write ? "Write" : "Read", info->access_size, - info->access_addr, current->comm, task_pid_nr(current)); + if (info->access_size) + pr_err("%s of size %zu at addr %px by task %s/%d\n", + info->is_write ? "Write" : "Read", info->access_size, + info->access_addr, current->comm, task_pid_nr(current)); + else + pr_err("%s at addr %px by task %s/%d\n", + info->is_write ? "Write" : "Read", + info->access_addr, current->comm, task_pid_nr(current)); } static DEFINE_SPINLOCK(report_lock);