From patchwork Tue Nov 10 22:10:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895697 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 824DAC4742C for ; Tue, 10 Nov 2020 22:27:52 +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 1EFC4206B2 for ; Tue, 10 Nov 2020 22:27:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WZqjUg6W"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Y/jR1dsz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EFC4206B2 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=9HrK9x38psyVlT8xsGGf0JFdLiXSlw1otP4i70tZfLo=; b=WZqjUg6WLCt0AqezbhMOHI2qi /b5oudafhHBswMdMZuImJCwYE/GotYKxhsXPd9js59J/6QMF1OoQH5z+p5rWRYNx7ym0dvmAnLzy4 tFYdZKbAXPjWnUoAM1sCkRucCjv/GM6q9O7hRmq5Ewm/EA9zrQtGfIQg3q4ABXd6X1oWcWz3hOqTv hiWyLuGgib96TU+gRjXQLAtGW1scX6FdBXbpOwMZTVQFnB9XUPqxCaEtzFpCXuE46pAKXDpJ1JNBJ zCpsBShK4nX+dRmwkA0pV03PKqLFjd1QdEIfbwVWdkc5P5YdZIhEgBTwj5xbCSSgUVWhInm/jA1lE Q/KEs5/bQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcc5f-0002og-G5; Tue, 10 Nov 2020 22:26:15 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbsc-00054w-MM for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:12:56 +0000 Received: by mail-wr1-x449.google.com with SMTP id r16so6152655wrw.22 for ; Tue, 10 Nov 2020 14:12:43 -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=/sxzdyvi8KkfW5gspThP8KvseoTY7ROsnu5nrXDzCag=; b=Y/jR1dsz3MoDl81vp14eGReV4TFu4RPTWCiE9VTJYP+0EekPQ8C5H9S7rFJJO/fXaO kOEoYEtNVzGjZJ4o6dPnzIdEY9RHhVrMNRMZ8WclGzjHjFziL+WhwREtWD5faj2mztzV X2AYk88MyNLjRHStKHJ1brWfHeQVj36mZeXFNHZ3Cq0LnArt1MkCynqe9pXOSy1/VH3y dBPasok/sdJerOrwJ/8YpnPoeknOs1o6yh9zC/hc5bpWNoNbxC+FBZ7y4J8+WWeCId1h CNPgzY93DllUdq5tiTBubK5vlT9b4hHaVAW8RooWas7C7NM4PwE6e3mm3K8sD8Vck1mc vwsw== 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=/sxzdyvi8KkfW5gspThP8KvseoTY7ROsnu5nrXDzCag=; b=Zw7w8jFqLq1S2ZOP9FUKy3Ilh4ArYqatlfptlBkNH7/bR0N8saZr3uuzsL1Lx5Vat0 glRv9uwzWhKBxfqL8gofGrxWGFXMHETt4jeGBu9jEjrJn9CtTWW+a5P5sF3Se8qI0bNc +hn2nv9q8eurUL26TDMwq3n9U680rjMFZGzrsSRMsThYFWTZsJd0MTBOkgfWwwBl9g5j kJNEWCPEapkL+kc/teF/uKWB/76uh36IdD+RLa8lCTo5YAPxI1wh5sKIIxZ3hIBu+6F7 rG5cidJdlhqxqxqvu/N1FJcLuc+f/7Hnk+v2Z8lKFUMhy2QCB69IHgr1dklquwTc5azl 6EBA== X-Gm-Message-State: AOAM532N77uulm6f98RcCgRauE6+MMrW74+YZ5FehsHovvJp7o1gceBH cB6avh9JuBXubiiw+STMs2qG9A2GiKuCepuq X-Google-Smtp-Source: ABdhPJwjLitPJuje4TriI9elVnHCZf9lAYnOrAzCOl08HXbRqejuwd4uq00Z5f6BYQz4oYR+we+b5AqvJh7lXdOX X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6000:109:: with SMTP id o9mr25232534wrx.240.1605046362785; Tue, 10 Nov 2020 14:12:42 -0800 (PST) Date: Tue, 10 Nov 2020 23:10:37 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v9 40/44] kasan, arm64: print report from tag fault handler From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_171246_839815_E83F5301 X-CRM114-Status: GOOD ( 15.63 ) 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 , Andrey Konovalov , Kevin Brodsky , Will Deacon , 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 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 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);