From patchwork Tue Sep 15 21:16:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777783 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA0346CA for ; Tue, 15 Sep 2020 21:17:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6FF4820770 for ; Tue, 15 Sep 2020 21:17:50 +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="JLHBY9Ag" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FF4820770 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 591DE900095; Tue, 15 Sep 2020 17:17:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F5FA900070; Tue, 15 Sep 2020 17:17:47 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BAB8900095; Tue, 15 Sep 2020 17:17:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0076.hostedemail.com [216.40.44.76]) by kanga.kvack.org (Postfix) with ESMTP id 2130F900070 for ; Tue, 15 Sep 2020 17:17:47 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DE3491F1A for ; Tue, 15 Sep 2020 21:17:46 +0000 (UTC) X-FDA: 77266557732.06.wash51_4506bb027114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id ABFB01005F0A5 for ; Tue, 15 Sep 2020 21:17:46 +0000 (UTC) X-Spam-Summary: 1,0,0,20e9719e34d84b34,d41d8cd98f00b204,3es9hxwokcf46j9naugjrhckkcha.8kihejqt-iigr68g.knc@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:982:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2901:3138:3139:3140:3141:3142:3152:3354:3865:3866:3867:3870:3871:3872:4117:4250:4321:4605:5007:6261:6653:6742:7903:8603:9036:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:14181:14394:14659:14721:21080:21324:21365:21444:21451:21626:30003:30012:30054:30056:30075,0,RBL:209.85.160.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y8zyqp4rkphawbpmhg79rq33b6yyc8j4roxprp45w9nib99ye6h8ndf8tq4tw.copujugi9ue1soamnxpcgrngwore9sfd6o5drz6rptqbjssxnb5fnxnxz7rrqwh.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,C ustom_ru X-HE-Tag: wash51_4506bb027114 X-Filterd-Recvd-Size: 6535 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:46 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id g10so4041122qto.1 for ; Tue, 15 Sep 2020 14:17:46 -0700 (PDT) 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=D8sG/cEP7djDLTapvipoPil4TaVPwtS1uBYZ8/rqMfU=; b=JLHBY9AgkNxAqLTKFWQdxcgJcgqdPUV3TxpRVzNYHFqfab1asZTfQTMH+AqvVnwgCH BnUUjUz0j3cp5q50TzevAEZDIAJ0lOMhBCpOnwtBSEh0VnSduULw/f/WRSJ73y/PSR3g wAtqSI76OkKjfWf3WP25K5JUjRztC3SdAV4hoFEGhsvOomwFaXZfyUboATVZWnH9zU6D TQIjujxm5SaToqhiVOXT9DXzAt8rmJsm0fOCCNW7HoJrb4YrW0Q0m8CDIdPkQBW+HfF8 vXzn130goo1cQM6GpPk5iZ4YGlPC9oVunx0rEnt4NZEdRJcb4DVF1GJSyIHZDe5/ruiQ l/jQ== 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=D8sG/cEP7djDLTapvipoPil4TaVPwtS1uBYZ8/rqMfU=; b=EiFd882Is9KjuGv5+qc8R4oTgr7SomEiCJwd+D1oocCytsyNAnviUknqlcsWkfLeiB BS9vZodvciDjgEFRQGMPUk1UUMp2voG4QrVVUqxrGRPHewcgg/6cS9qkoUj8RyLoADLK VVOqEGX6OkQ0C2PQQ6vZmPmaQ+yEDmTD55BECHdRLCXFRUFHXFDdFODlh/2x6KxPpo8b QKTC7ELgK8yW46GQJXbbD7BC3bxvz10d+cEj1qbovsF5mZOzGARkFH6CD8ZlNWGa0S/p OriK6ksQovc5obqrt823yfB6zemyssKwDQRJfEJ9tPhMPrbv9CmI/pFuCOwwPTj0NJ1p xHaA== X-Gm-Message-State: AOAM530Uplrweq4glSTWfGSEM3rxmQO9BRxbkhknyzlDtjNljIdj/Gjn nrJ3/ahBWffNXb7BEouK1aTox+r1n1oaGBhY X-Google-Smtp-Source: ABdhPJzlRX414ae6dY3KcWoPCkTBwkZK3ld5YB1kdMEENNAIrBphNAvoJTIWKdIYK4+jfcGWQyTwv8zsQNqqfSmk X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:58e3:: with SMTP id di3mr3798476qvb.54.1600204665622; Tue, 15 Sep 2020 14:17:45 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:16 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 34/37] kasan, arm64: print report from tag fault handler From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: ABFB01005F0A5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 --- Change-Id: I3780fe7db6e075dff2937d3d8508f55c9322b095 --- arch/arm64/mm/fault.c | 19 +++++++++++++------ mm/kasan/report.c | 11 ++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index cdc23662691c..ac79819317f2 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -295,17 +296,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; + bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0; - pr_alert("Memory Tagging Extension Fault in %pS\n", (void *)regs->pc); - pr_alert(" %s at address %lx\n", is_write ? "Write" : "Read", addr); - pr_alert(" Pointer tag: [%02x], memory tag: [%02x]\n", - mte_get_ptr_tag(addr), - mte_get_mem_tag((void *)addr)); + /* + * 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_kernel_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index c904edab33b8..34ef81736d73 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -65,9 +65,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);