From patchwork Wed Nov 4 23:18:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883377 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 6B3ACC00A89 for ; Thu, 5 Nov 2020 06:36: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 C256F2071A for ; Thu, 5 Nov 2020 06:36:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rXA8EnuW"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="WEoh54Vi"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="c0vkrlRI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C256F2071A 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=rXA8EnuWZb/NkKt/Cq/mfXeA4 CxdbvJCKkPm+UJOiIikTEvUUaeX+y2z8lgsE7lSCxYkir/WS3M5ll2FlMUjjjKn3mApnVKr9/zKxj 9zaKNw2+Gw5YWX5dsiA0M8c53utLD76c0cD4IKlJDcEE59N3GnktdvaStPD6894nykgPWYvCYd4XY 9eMlSaqTMMeuV3wtrRv0Y4otTVPBiahteND82Th84TGpbBJMmIIzj6rGbwxHKtfn5tLZDpZ98ppbm xqqkQvDEcI+qlJHmwGoOksNqPSPw8sSC9fhxJUfOolUVkW8DsfriOQum4KC37VAuPXACx8b6Rvu95 2jus7MCvQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaYs7-0007IZ-GS; Thu, 05 Nov 2020 06:35:47 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW53-000145-JU for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:36:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=35WbJzPGlJ32SG4OmkQQICRjm1+Un7MaGRWzBQ2gFy8=; b=WEoh54Vi5zvGTirImduHP1fwes 25LTTfF4572xbc48AhQhlyC7Oznq+5olMUmmgkVr13CU8WL5HGSaSFDqESYnimKIwl5oEf3pXVM2R WO7P2t4mZU89+gpTDSqEzKW9M/SjqKp8vgfXMNwdBnPe7O8/0pDjY5J9MRHmvtDbEMVMI0hZXZMV/ wfKuAJrSv0AgnDqsq1Qom+62kw77x8R9wINokNxAPl5oH6OT5grc4Cg/PZXgy3NvH4t4iaE37hUXm U3N78i+gCQ04ZJSkpIushugD6tL1HkxMNH3yLYdhlU/fmZa+K9m4i5qeGNEd16qVFaJBG/dJHRzQ5 FEj8yLRw==; Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS62-0004EW-9f for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:46 +0000 Received: by mail-qk1-x74a.google.com with SMTP id u16so14493183qkm.22 for ; Wed, 04 Nov 2020 15:21:41 -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=c0vkrlRIsEA2zaSNjedAHzaANOS3KnMfQBq5IN41oqi4DjS7urZr6IPPvJz9UxlmEd lW6pqmtub3Nyd6OWE074wEOgDmu0UT4Wg9dLQq1YfyblzwoMhnpPcJPwhNwUztvQe/+s 0qkSYVBHDeocB/8qWuxyOvRYz4+sCZPsYugh312jIOu5bHNCzzWJke/Mc6ofThSTxC0F kHC1EPLi214qaGu9G+uHo4OXCWktBoIvmhhT7MoMSxNbqcFf+PP/FfggLNy6XC2iN0a2 zLYJ1VgM1TTpUY5pGPAdOJ8/uoocPxBXoBWvqK0k0KAfoNZvU2Yl3nomO/+QsmiXyG1b sIIg== 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=Ha92LADRx+mIPnmaaBEpH/3xwlsVRfKBVQ7C515+hEBJOoGHmXNWzxhNKDxJR6VJJL CwzXSpCBBJFC0Vg/0PUEfRZcOLKDvLrGr7Pv+AuHK+h6VYS0upv9GI9sWhzD6DlJenuN /f2525tuJyMa8NVX0td6Y0T2jVGZUD5pvT7POhCBkiSG9ZtNirbJ0O2FT8HL+X9XSCyp 2wLVQRggBDH+t3gb7qagc3S1k46LWm3kglcDD7VcRkDH732IFLyr3ZC5At2XUQZJv4dB E4/7VN6hEp4izuYNDGozYG3QexttmScJYV/mgbOSXyBcg2YMFIn790/s8ghmLdEr/X9I 8wpw== X-Gm-Message-State: AOAM5323feFtJsLelxFOqNozmHBybjXXfcG9dq1jLwytTSgeFghozN33 3dLjfRjD4/4TBVZbOYrXFWuoUIzkz+7/8R0L X-Google-Smtp-Source: ABdhPJyQywfWKbdX68bSu2ZPlot1uOmCpCTLZwOGAs9Gz57V7Cqqkk2XTA2l7zW1C/0FANx/P7/BsExHxmasuAN6 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:55ea:: with SMTP id bu10mr283554qvb.28.1604532040493; Wed, 04 Nov 2020 15:20:40 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:54 +0100 In-Reply-To: Message-Id: <4bde28cafd5ef30f4caf2bbeca90a9d7ccb73793.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 39/43] 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-20201104_232142_512204_60C818F3 X-CRM114-Status: GOOD ( 14.19 ) 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 --- 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);