From patchwork Fri Jan 15 13:03:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12022697 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.5 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 858FFC433E0 for ; Fri, 15 Jan 2021 13:03:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 19CE022473 for ; Fri, 15 Jan 2021 13:03:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 19CE022473 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 52EB88D016D; Fri, 15 Jan 2021 08:03:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 506A98D016B; Fri, 15 Jan 2021 08:03:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F5688D016D; Fri, 15 Jan 2021 08:03:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id 2A94E8D016B for ; Fri, 15 Jan 2021 08:03:53 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DBA962C1F for ; Fri, 15 Jan 2021 13:03:52 +0000 (UTC) X-FDA: 77708026704.28.order25_3c16afe2752f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id AEB376C36 for ; Fri, 15 Jan 2021 13:03:52 +0000 (UTC) X-HE-Tag: order25_3c16afe2752f X-Filterd-Recvd-Size: 6234 Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 Jan 2021 13:03:52 +0000 (UTC) Received: by mail-qv1-f74.google.com with SMTP id cc1so7588928qvb.3 for ; Fri, 15 Jan 2021 05:03:52 -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=hLav+6cEwiPVPNQ10H8mUnfXDXSTPqRFsNjQotE+jzA=; b=Sh2HR2ssv22qj/Ox0Y413CCPV307dbT5KXC2u/9JMQT47kKYkHhqe+TBznrMD4j545 zwfZJu/moFJjgslO5+Z7LAOidJv6WifGvAYC/7O4n9t6th4ICiC0SvHHnnCfnPF8gY+0 0/vyBQtKyVn2YEGQ2MU95deZJIvVOgVPz5W0KVc8OCqTyv3V5UOECCjA2LYhdyxphVg8 7PsWmj//xJCAdfcM/cpfBMzQD/jP4Ondyz4a5K1SXb9h1Trm/kOFV2OmmXzkmbq7ACwV 27N3pJtJHvUV/aSDWZqoQMgMRQJdenMHlImacDTD1pXymW4TyqHp9jgfrUibN88WBRKv 2F6g== 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=hLav+6cEwiPVPNQ10H8mUnfXDXSTPqRFsNjQotE+jzA=; b=NOEOcEp+1EDDAWbQ+Y5VDjsGLCp8QbqmChFdANJ7HvvZ9wAoIlQD+byAGsfNeiPiq4 FmRI5oFu8ZuWMqUeZ34Rjqb45Q0x3n04ZP8ZAwFbNZVFPsQjYzXBEpdhE+8TqQ1FWxTo LJN1Qlc5w2PipuBRtnZMvKgiAV4zyyuKVOAPl18AYeK4+Z4f60dQW+yCGUh8lCpQ/NpO rsii86zWfcakrwpC7Cx5LY4f2TDJTdUuAYhJGQxMjeRmBONyeBCGLhNPeOgB3Y6v4Za8 bxGPKwTibcJXLk7jXz630zd9HKq07zvHr+k13SneB/ofJnqs1g5bInwYwsrim15Ee/GF AWjQ== X-Gm-Message-State: AOAM532hpIXHiLe+2VSppyGsk1QzBvKbNnXls5KOo07N5LvmnlSW4MfN YgIMpzjECyknsYn5YL4MER6as5dyIc4= X-Google-Smtp-Source: ABdhPJwcxbW4F0oXAeIpK+OvuTtdxUQ7SsZtruNCXPi/u8cr2SIDC13l6xM4zNss2rTVBUqx4VJstHIKwJ8= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:9ff]) (user=glider job=sendgmr) by 2002:a05:6214:140d:: with SMTP id n13mr11772979qvx.45.1610715831400; Fri, 15 Jan 2021 05:03:51 -0800 (PST) Date: Fri, 15 Jan 2021 14:03:36 +0100 In-Reply-To: <20210115130336.2520663-1-glider@google.com> Message-Id: <20210115130336.2520663-6-glider@google.com> Mime-Version: 1.0 References: <20210115130336.2520663-1-glider@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v2 5/5] kasan: use error_report_start and error_report_end tracepoints From: Alexander Potapenko To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Cc: andreyknvl@google.com, dvyukov@google.com, mingo@redhat.com, elver@google.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, glider@google.com, 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 --- v2: - change error_report_start and error_report_end prototypes to accept enum error_detector instead of char* (as suggested by Steven Rostedt) --- 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..78b8bbc84dc2 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(ERROR_DETECTOR_KASAN, addr); } -static void end_report(unsigned long *flags) +static void end_report(unsigned long *flags, unsigned long addr) { + trace_error_report_end(ERROR_DETECTOR_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,