From patchwork Mon Nov 2 16:04:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11874685 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 8152AC00A89 for ; Mon, 2 Nov 2020 17:30:00 +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 15C9521D91 for ; Mon, 2 Nov 2020 17:29:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dkhNMEJ+"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="ReVmikUf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 15C9521D91 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=1Bq43GbtPNoseNeiqVZVcQ5dwWuJqEqfSIO6N8RztLg=; b=dkhNMEJ+ypQoFOjvDPa7A80Y3 FkF4F8xJkx2F8yXY7HL4SXe+0wa6qI02XMbyL+FB2w8dCwf30mD8QZOGSZmjQ38xf6i9RjYm93zAt t8JrAVkuftOGj2eii8feSsL/T17Hi1a+Xz0Hp3xe9Z6RBTkXt8x8jn+xHryHLfaoVsL87FFWOP2YW agcMfcbKf1E0ZfMPvh2TbvEAXYSP4Sxjn1EBputEVn9etpfKk8OaV46/FnSYxxhjr43imJ9C4cWGD 8FNkdplJ1tWn28DnHCO9EDHvcFL3nohK+jezIYZRoNgXVv0Ofr9UPIbKWzum6P63z7BRZ29KOelqB 86GQAm2bQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZddg-0000ac-7j; Mon, 02 Nov 2020 17:29:04 +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 1kZcLI-00074l-Dv for linux-arm-kernel@lists.infradead.org; Mon, 02 Nov 2020 16:06:02 +0000 Received: by mail-wm1-x349.google.com with SMTP id y21so1749716wmi.7 for ; Mon, 02 Nov 2020 08:05:57 -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=35WbJzPGlJ32SG4OmkQQICRjm1+Un7MaGRWzBQ2gFy8=; b=ReVmikUfyD35ZPa7hA8zZkwvxwA/5N8OqN4auSKNEZ9rVVWtp0EJoTybi+VzCtP2jp CPDFfxl55PnOIfXvOv37raQxHz8p9i2WhNdFvmcS1mpk13Y4mFxSGZPsa4PyNuUEC08p FEeFqir9iq0/DJYfPuAGWbHqFyrioDYpUXvjZ6XT4I/MnNU2KKkimPKlzRfBaNjatEYG zK4op1Kj6AIqZ/MJwI1j0Iar0T2h/5lcdIXXU9U8i//1Yj73pBnI0m2o3ZTtkH0YTce+ 3iS+OtmdE179QKxzlpL6R1UwUdrxgAUsBh+sma29bCsxbiMBVjd+rtoY/F/eL+wmifiQ dpWg== 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=35WbJzPGlJ32SG4OmkQQICRjm1+Un7MaGRWzBQ2gFy8=; b=CAhLi6PUGkA2vEgGi9W9Mi3a8GQ8tmjZZP/gU/utYf7L1pEKn2xxxv0kptSCDngCS9 Gl4xHVVkv9J8JyF9RCLe940t8HrzYtO0gmAp79QN2iPpRG23FF9b4D0le6Pai2fnabBD 6D3Gy466iQKW5bzAHLYElW+nthc4zEFQuhj+j6lkIApG3OACHgMTo2EFKoHm4j6Sb+9L PgU7QIXF/AGZ3ni8YfhieWbaxoH/7YmVKJSEDnWkPcljUzdmkLQ/sJbHwQz/sh/clGsw cSUKWQ//7DPO4+MIalX9qf3ysTpZ6c6X0EOdTOkYZmzNV5nbpNvlb8sStIbY9DD0aNas SLTg== X-Gm-Message-State: AOAM532g3XsJG6ZO6C+pbDOhLvyHu1wt0vUW6goDSggnoHKkzBE3r0T4 lozlNJkeMP0sv8G9Xa260y2liwi4ay95lfBH X-Google-Smtp-Source: ABdhPJxQI7fzcN6hDMp0RmZiP40ZK8WVYR15Oo87hSsXTGEB+onI1lJ/cn8A6qvfXvoM+/C+Z9vvyYf6Ghc12Kxq X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c845:: with SMTP id c5mr7825433wml.135.1604333156027; Mon, 02 Nov 2020 08:05:56 -0800 (PST) Date: Mon, 2 Nov 2020 17:04:17 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v7 37/41] kasan, arm64: print report from tag fault handler From: Andrey Konovalov To: Catalin Marinas , Will Deacon X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201102_110600_583685_4C7A7787 X-CRM114-Status: GOOD ( 15.98 ) 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 , Elena Petrova , Andrey Konovalov , Kevin Brodsky , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , 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 --- 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 fbceb14d93b1..7370e822e588 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -297,10 +298,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 8afc1a6ab202..ce06005d4052 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);