From patchwork Thu Jan 21 13:19:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12036141 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 5342AC433DB for ; Thu, 21 Jan 2021 13:19:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DF02E23A01 for ; Thu, 21 Jan 2021 13:19:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF02E23A01 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 670AC6B0023; Thu, 21 Jan 2021 08:19:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 625A46B0024; Thu, 21 Jan 2021 08:19:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EB746B0025; Thu, 21 Jan 2021 08:19:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id 368DE6B0023 for ; Thu, 21 Jan 2021 08:19:29 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E88378249980 for ; Thu, 21 Jan 2021 13:19:28 +0000 (UTC) X-FDA: 77729838816.26.shake05_4e06e7b27563 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id C7A721804B667 for ; Thu, 21 Jan 2021 13:19:28 +0000 (UTC) X-HE-Tag: shake05_4e06e7b27563 X-Filterd-Recvd-Size: 5331 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 13:19:28 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id e12so986991wrx.14 for ; Thu, 21 Jan 2021 05:19:28 -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=3UapMw1B/lQ8O8rK1t5yloPW20aKmQdYgqwziIYXJaY=; b=UKSOk4WzR2mtDoCBipGA36JhtfgylD1LozvLVpUwCjthtsOSGbdlWMc2q8E2pmyHdh 3ImBadYTaBj0ZhQ+OwufJlquLcifn27sJvDhP0iaz3UGUhMdgJ+ZkmZkw/tS7/zcjsdU Tgi7ErDfePAS28w8dFBLeqBfhd7QxzXchYbQqGyVwlSPXpoZfZEbQGSWasZmh6lV8Tto J68r/4NDvEugjF8vneCaHszTUtwU1yUHjFp64o+lFACtZ1m94s7NluiylwXXRR9NZYGX VlEqcWHT2m77F7gPpMAfNi1xcWxFQilRXACXBtGrekrUVW3fkZmmd86URU/K8Zy5mWUu y+WQ== 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=3UapMw1B/lQ8O8rK1t5yloPW20aKmQdYgqwziIYXJaY=; b=k4Iu39gi79mtx9ZNsL8853GIpH6GLC/GdCVvtQBIe0L5V865CWHrZ2X7rOpvcH3fwm JcwlKYywICAi+641DlwH8MNRtyjJr52JaHkkkFrMBDd8nTlqMGgx/dv8w78j/zgCDGy6 9rwDJ9QEft8N9RZd/T879omMWyD3lf9emKKfbpswwYMXgiReW5/Am9guCWzgEWIkTC0f 4A9py4krvRamvMrB+VkvPOl9tqUTY7jcwTAupIHX0kERCyAowOjocPhOiIuYVAFwqr0H ZAHuIE+znBEr73Nmk8Nyxoqlair+JdzCMQBDkRlxn2q3Q/XDYi4DEf6LXiQ6NYjRHBfK 7wdw== X-Gm-Message-State: AOAM533Gk8xMRPnTSsSYGn6vwthv2+1CEQLHf5AATLJq/PicMqq+1r8H AWlpJ+ldexNGtXHacOjmzokUG0F8GmI= X-Google-Smtp-Source: ABdhPJw5JH6viWlCpNTEeENNaqAUbl0z56mqHOR+JS2XF/jIGeIsHBiubDSgHt35cRONxjNqkHPgiHd/phA= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:9ff]) (user=glider job=sendgmr) by 2002:a5d:6c6b:: with SMTP id r11mr3209323wrz.38.1611235166783; Thu, 21 Jan 2021 05:19:26 -0800 (PST) Date: Thu, 21 Jan 2021 14:19:15 +0100 In-Reply-To: <20210121131915.1331302-1-glider@google.com> Message-Id: <20210121131915.1331302-4-glider@google.com> Mime-Version: 1.0 References: <20210121131915.1331302-1-glider@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH 3/3] kasan: use error_report_end tracepoint From: Alexander Potapenko To: akpm@linux-foundation.org, glider@google.com Cc: elver@google.com, andreyknvl@google.com, dvyukov@google.com, mingo@redhat.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux-mm@kvack.org, linux-api@vger.kernel.org, vbabka@suse.cz, gregkh@linuxfoundation.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. A good usecase is watching for trace events from the userspace to detect and process memory corruption reports from the kernel. 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 --- v3: - dropped error_report_start 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 234f35a84f19..87b271206163 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -84,8 +85,9 @@ static void start_report(unsigned long *flags) pr_err("==================================================================\n"); } -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); @@ -355,7 +357,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip) 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, @@ -401,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,