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: 11926647 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.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 6F9CBC63777 for ; Mon, 23 Nov 2020 20:27:56 +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 07FC420715 for ; Mon, 23 Nov 2020 20:27:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AucZzhm+"; 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 07FC420715 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=RFA2t9qw8UP7uumwTSM2RVg+8H70S5gAsahESumi0VI=; b=AucZzhm+6MPR9dTHFXFZ7z3mY J6xm96sLY8OZM6Nx0nPO9ivfihaeY2lofGpVMaLsl3PL7DzQ6v535LWtNgEyILuglwju+PVw0YCJm YdQDIo9XjPzOYy40wsKHA2hIjHTC5odvXV0E1nDkl9L3gD7ICHjspnp1QRgfVJDj/pafeAAVvF9Tl 4IwEiHQcpYYdKjR3pmWhqZUdkTbykaEL2qhuzGCmaj+4v02gzEWkJ/+vfBekdhO2th0fyZFwnct9o miHuxHCRTYLxcK5M/T4+bdtQCa+GtvqBIsuazFdV4r/nRvVACC8vE4h7K+1EyOyvfXtBhpuiLILVt 27m7vnlEg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIPU-0006vp-8o; Mon, 23 Nov 2020 20:26: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 1khI9y-0008V6-MM for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:10:20 +0000 Received: by mail-wm1-x349.google.com with SMTP id o17so142715wmd.9 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=GYanhKQSerk5mD7FIsEPSBeFvzD+mvxqtty1FMEZ1YZxdaOFLQutHbJ2znzqy4Resn aUAMgYjEU4z2gDa9uECgFuP8+xadn69DppENP8eSHnY6tSth/F8kQtFLcOHJzq6rCV5X U8BNfQfzwKAE5K7wJxojZGGd6rmyOfUvkoG6C/gyv0RvHgQJBbg6t4qXbXpnyMeiC3m7 h8rflR7dDPY7SZOBdS3t9lvwt3GquQBLZLiuj7UhpCRoBx/69wwVjyAVTvKBbOwIx2MQ qoqPrRiKB9WFH6X92gEJW3+cKxZ6OZvOU9jAvyiGymEUhW6R0qTtv42XFAQqiZsE/BLt ZUhA== X-Gm-Message-State: AOAM533ytPOaBNPOZCMCGW/Fqlqg02VpIXsc+2eCJPT5CMlCKIO/VabZ lcrOzIesetj6C0tqeZoKw3zJWIVOKunbrzpq 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151003_283188_5A677FBE X-CRM114-Status: GOOD ( 16.29 ) 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);