From patchwork Wed Mar 2 16:36:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12766309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2ED5BC433EF for ; Wed, 2 Mar 2022 16:40:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB6248D0002; Wed, 2 Mar 2022 11:40:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B64A58D0001; Wed, 2 Mar 2022 11:40:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A54878D0002; Wed, 2 Mar 2022 11:40:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 967A68D0001 for ; Wed, 2 Mar 2022 11:40:04 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5506295AE6 for ; Wed, 2 Mar 2022 16:40:04 +0000 (UTC) X-FDA: 79200008328.28.8CCC603 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf16.hostedemail.com (Postfix) with ESMTP id A76DF180002 for ; Wed, 2 Mar 2022 16:40:03 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1646239202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=djMH4j9HV8SXlCfl9Af/XXd5VDpDAiry7CNPlQpwESU=; b=PnZ2t/ANIdtINzZYFaDix7C8GIFWc+Tcr3lo2iGiNpriUbTepgZwinlIDD+IUj0vIZXPAT PUWWJBTw6hHckQ1Q+E98GyyjPVqju9Ydl66WDlbG/CQjQkd9tMJr4XtT5MULXn29AcSCz2 GJxDfbMqH3fNp2GkTIiuEGRW74+fR8I= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 20/22] kasan: reorder reporting functions Date: Wed, 2 Mar 2022 17:36:40 +0100 Message-Id: <82aa926c411e00e76e97e645a551ede9ed0c5e79.1646237226.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A76DF180002 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="PnZ2t/AN"; spf=pass (imf16.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Stat-Signature: 7zimyuf4nuuhrwqjueqpyk4j4f34kz5d X-HE-Tag: 1646239203-172177 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: From: Andrey Konovalov Move print_error_description()'s, report_suppressed()'s, and report_enabled()'s definitions to improve the logical order of function definitions in report.c. No functional changes. Signed-off-by: Andrey Konovalov --- mm/kasan/report.c | 82 +++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index ef649f5cee29..7ef3b0455603 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -84,24 +84,29 @@ static int __init kasan_set_multi_shot(char *str) } __setup("kasan_multi_shot", kasan_set_multi_shot); -static void print_error_description(struct kasan_report_info *info) +/* + * Used to suppress reports within kasan_disable/enable_current() critical + * sections, which are used for marking accesses to slab metadata. + */ +static bool report_suppressed(void) { - if (info->type == KASAN_REPORT_INVALID_FREE) { - pr_err("BUG: KASAN: double-free or invalid-free in %pS\n", - (void *)info->ip); - return; - } +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) + if (current->kasan_depth) + return true; +#endif + return false; +} - pr_err("BUG: KASAN: %s in %pS\n", - kasan_get_bug_type(info), (void *)info->ip); - 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)); +/* + * Used to avoid reporting more than one KASAN bug unless kasan_multi_shot + * is enabled. Note that KASAN tests effectively enable kasan_multi_shot + * for their duration. + */ +static bool report_enabled(void) +{ + if (test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) + return true; + return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags); } #if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) @@ -160,6 +165,26 @@ static void end_report(unsigned long *flags, void *addr) kasan_enable_current(); } +static void print_error_description(struct kasan_report_info *info) +{ + if (info->type == KASAN_REPORT_INVALID_FREE) { + pr_err("BUG: KASAN: double-free or invalid-free in %pS\n", + (void *)info->ip); + return; + } + + pr_err("BUG: KASAN: %s in %pS\n", + kasan_get_bug_type(info), (void *)info->ip); + 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 void print_track(struct kasan_track *track, const char *prefix) { pr_err("%s by task %u:\n", prefix, track->pid); @@ -381,31 +406,6 @@ static void print_memory_metadata(const void *addr) } } -/* - * Used to suppress reports within kasan_disable/enable_current() critical - * sections, which are used for marking accesses to slab metadata. - */ -static bool report_suppressed(void) -{ -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) - if (current->kasan_depth) - return true; -#endif - return false; -} - -/* - * Used to avoid reporting more than one KASAN bug unless kasan_multi_shot - * is enabled. Note that KASAN tests effectively enable kasan_multi_shot - * for their duration. - */ -static bool report_enabled(void) -{ - if (test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) - return true; - return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags); -} - static void print_report(struct kasan_report_info *info) { void *tagged_addr = info->access_addr;