From patchwork Fri Nov 13 22:16:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11905119 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 F2AD1C55ABD for ; Fri, 13 Nov 2020 23:37:06 +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 A6D3320665 for ; Fri, 13 Nov 2020 23:37:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="xWDWABk/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="CWWbP+Cr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A6D3320665 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=EYklpeobFkzcfRRLAuXC+SHuLkAZtx+Uz4SXw8nH8sU=; b=xWDWABk/MIyhED4RcWbfOep9D wGe7hHFPqQTsiS/d2PP//MWuVV3Cw0VskhNoBOrBmqyWs/3we4C7oM981JJe1Ym0J3qLT3UxXKVfo tkve2CiNZyzQo4dgtp53kAqNy3dqp7f5W/LErKkzWaBO9SRXi31uo7K70hnGmiYvqTp00Ik/8OWSJ WWn7yMx1KWKomIuNe4Lc884UmQKhDb0Mfxm9/MfZvqOeAHNJI2FXdWjkderzLNm8mGoEkN4eGmqv3 SQKQH5I+wzZ76YA4umFLynKD8Dc27oq8xNGHeE5hihxTPE2BKOeX0PzRe3FZ4Zrx3k9wVBq9ZLRj1 Wzs2t9b3w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdic1-0001rB-6i; Fri, 13 Nov 2020 23:36:13 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhOB-0000Ri-5r for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 22:18:03 +0000 Received: by mail-wr1-x44a.google.com with SMTP id 91so4477971wrk.17 for ; Fri, 13 Nov 2020 14:17:47 -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=xaa+VV69xly6NtD9oDw0a4fgTp58XYd2+h3RtuHf6eE=; b=CWWbP+CrzKArtLZOHT697dIqhABlh9KFuDkDt6jVUfI1BP70ptWt0ekQM0OeYO5m0S APNUU1m1/gJ8g/NqB4fVaTWBJfhdHkuzJsJ0FMlinYFq13lLmMVFEpw2oDF8wrpOzib0 19ofn1SgHBRtrBHUpRlY0C4w79GZ3dG1m38JQNg3Cv9D3s+EWna3qcOaI9s0fDJexrs7 kS5gHTAxCc8BvY4GnZyUEHmoFS/r5JKyTGOt3B3cQJ/xIYGs3FD3L8SWeMvE5NqX9V+e 48AGiSiZKTgy8sK2/RnKMaHHfA3Kn+O6Ee9oqk9knT16CM65kb46rHJ4KVr3X5GmxA5R 3K0g== 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=xaa+VV69xly6NtD9oDw0a4fgTp58XYd2+h3RtuHf6eE=; b=NzDKkEmeq4FcPVnYI5fOgkAaFePAI+8ZlhVtYAAZsB0/+8cQuO6+9GF5CxiPpjPaNz 5zZcvurLvT+rPrg/6T3RzXUdCzLYz1GLf511sWZwtK7FrKvESlykMfgCyBh2lVdDLggS v3r2ML2QTF1UE9moHDj0Ght2rPkC7Xa/9MBd6Ih7gJqsszt5k1ln9Rvd026HjATRjQW/ 20wjbIrwjy8uQnWXwNxka3uEQLkml9SShbvWrWIoPGxW9HlOFaqCporHwApv+CeXKFWY omq4esuQK6VN7o0TMKPBUEYGm9TE1dPxYUmIx5I/4qfsVGfd7Pn41YTWvRgWHZHWO33h ZWoA== X-Gm-Message-State: AOAM5335Fr0uQZOFLZjDCPDA8MtwPbnW/JWGPqt5YVGgYa5VWvCk4HJX akCW5SFP5oG+bpOrykfQdn8FSXuJTCa9W9Ac X-Google-Smtp-Source: ABdhPJyBDyYC9/PGel4BR1xfmWz+Zxo/sGgPx5xYgIlAE1YLTmCpnV5Ly2Tz5BFPPp6zu5O3ZmwShvUgo7lwtogd X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:e983:: with SMTP id h3mr5834862wrm.382.1605305866774; Fri, 13 Nov 2020 14:17:46 -0800 (PST) Date: Fri, 13 Nov 2020 23:16:06 +0100 In-Reply-To: Message-Id: <53055673bff17607e42bc518dd31b56cb3e2a3af.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 38/42] kasan, arm64: print report from tag fault handler From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201113_171751_345445_D450E01F X-CRM114-Status: GOOD ( 15.92 ) 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 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);