From patchwork Wed Jan 13 09:16:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12016215 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.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 A7B07C433E0 for ; Wed, 13 Jan 2021 09:17:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1B92C233E2 for ; Wed, 13 Jan 2021 09:17:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B92C233E2 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 8A5A48D002D; Wed, 13 Jan 2021 04:17:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 82CEF8D002C; Wed, 13 Jan 2021 04:17:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F5108D002D; Wed, 13 Jan 2021 04:17:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0119.hostedemail.com [216.40.44.119]) by kanga.kvack.org (Postfix) with ESMTP id 4D1A88D002C for ; Wed, 13 Jan 2021 04:17:12 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1CC6D18061B9B for ; Wed, 13 Jan 2021 09:17:12 +0000 (UTC) X-FDA: 77700197904.02.fang11_3c063f02751c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 041CF10097AA0 for ; Wed, 13 Jan 2021 09:17:11 +0000 (UTC) X-HE-Tag: fang11_3c063f02751c X-Filterd-Recvd-Size: 6174 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 09:17:11 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id f18so549447wmq.1 for ; Wed, 13 Jan 2021 01:17:11 -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=pMSZunVusBFa2srMdPuW53fXoOwDSFeZUvebF05YN08=; b=d4C0PW5sZc0HlVWTO9j0oxt1OwJCzegOR6uDyERunOBnLuzZup+teT4aMNmJkI0FDn YRedWuQrB8arw/Jt5f8VUq/+QPbJDWhLsUjf1ZxaiubNyBX1+XCSQbCj1uQDXMeQkhp5 GOvnj696GHLj2reYj7W8v95JYL5Vxhix7bSbLO6+LFHeyzUutxwmps9ehUheOdsomQdq fLmcjcKFWYgCaPfrwh4ypvmCy3SGwBt5fgt6xepe9j3qHUOtjqEkW3xbA/EILaM2WqSg W3Ni7DYvcAe0Z6iOax0ObnSz4PSTOvl4dBpwTNHucMLpFH1ZAnrA1c4dDYuhwm/E3rA2 YgIg== 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=pMSZunVusBFa2srMdPuW53fXoOwDSFeZUvebF05YN08=; b=H+6jRk2Akx6idzYzY6iMBeNgmulPRE1LuZPXA6HQ5xN6MZjWHUcfXQsbcR5ZCYbUsM b/uS8UFc9wx/o4FkjTRc0TnibzqQL58bP2UzqyPatNrsCVqLxbzFMcl0OE7rRh8P4p4r Lwvv1DhFMnq9z22m3N6KIHUn0wA+yxZQQskkIOeetM8G1dTLgVD+iEOXKgIBfVZe69ZB lOfybBtjL0ekJsD4qGnKczhVnz6gEQICa6OMEl/728jTLa9s6hJ7/RF8iNVLS3yZXAjF hYxRS18SsVrc9ddBO3TGNCF0JArSiN+q9Q5r8stTyalqNL5WtrPueXpe/MnovGc4nxvd hj6Q== X-Gm-Message-State: AOAM532fL7ferBiXcpPMXRKkdHo+Zn3aJR+fOXgbmlgBQMniE+GNXxg3 PNNHQkEQf+dYVPJvZQahVbaNMc0zu5w= X-Google-Smtp-Source: ABdhPJz3jt64c/gcj+wvuQCEziz78fmMWTAdkDanZ1a8Y5QATUBLbztfMzxaMeklY7WCE2FLqh5B8RbPUvY= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:9ff]) (user=glider job=sendgmr) by 2002:a1c:5644:: with SMTP id k65mr1225748wmb.62.1610529430509; Wed, 13 Jan 2021 01:17:10 -0800 (PST) Date: Wed, 13 Jan 2021 10:16:57 +0100 In-Reply-To: <20210113091657.1456216-1-glider@google.com> Message-Id: <20210113091657.1456216-5-glider@google.com> Mime-Version: 1.0 References: <20210113091657.1456216-1-glider@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 4/4] kasan: use error_report_start and error_report_end tracepoints From: Alexander Potapenko To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org Cc: Alexander Potapenko , Marco Elver , Andrey Konovalov , Dmitry Vyukov , Ingo Molnar , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , linux-mm@kvack.org 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: Make it possible to trace KASAN error reporting (in particular, for compatibility with CONFIG_ERROR_REPORT_NOTIFY). Suggested-by: Marco Elver Cc: Andrew Morton Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Ingo Molnar Cc: Marco Elver Cc: Petr Mladek Cc: Steven Rostedt Cc: Sergey Senozhatsky Cc: linux-mm@kvack.org Signed-off-by: Alexander Potapenko --- mm/kasan/report.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index c0fb21797550..fd015dd5dd39 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -74,7 +75,7 @@ static void print_error_description(struct kasan_access_info *info) static DEFINE_SPINLOCK(report_lock); -static void start_report(unsigned long *flags) +static void start_report(unsigned long *flags, unsigned long addr) { /* * Make sure we don't end up in loop. @@ -82,10 +83,12 @@ static void start_report(unsigned long *flags) kasan_disable_current(); spin_lock_irqsave(&report_lock, *flags); pr_err("==================================================================\n"); + trace_error_report_start("kasan", addr); } -static void end_report(unsigned long *flags) +static void end_report(unsigned long *flags, unsigned long addr) { + trace_error_report_end("kasan", addr); pr_err("==================================================================\n"); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); spin_unlock_irqrestore(&report_lock, *flags); @@ -348,14 +351,14 @@ void kasan_report_invalid_free(void *object, unsigned long ip) kasan_update_kunit_status(current->kunit_test); #endif /* IS_ENABLED(CONFIG_KUNIT) */ - start_report(&flags); + start_report(&flags, (unsigned long)object); pr_err("BUG: KASAN: double-free or invalid-free in %pS\n", (void *)ip); print_tags(tag, object); pr_err("\n"); print_address_description(object, tag); pr_err("\n"); print_memory_metadata(object); - end_report(&flags); + end_report(&flags, (unsigned long)object); } static void __kasan_report(unsigned long addr, size_t size, bool is_write, @@ -385,7 +388,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, info.is_write = is_write; info.ip = ip; - start_report(&flags); + start_report(&flags, addr); print_error_description(&info); if (addr_has_metadata(untagged_addr)) @@ -400,7 +403,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, dump_stack(); } - end_report(&flags); + end_report(&flags, addr); } bool kasan_report(unsigned long addr, size_t size, bool is_write,