From patchwork Wed Mar 2 16:36:23 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: 12766288 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 ECB32C433EF for ; Wed, 2 Mar 2022 16:36:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 725F68D0003; Wed, 2 Mar 2022 11:36:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AF418D0001; Wed, 2 Mar 2022 11:36:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C9C58D0003; Wed, 2 Mar 2022 11:36:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 2AC248D0001 for ; Wed, 2 Mar 2022 11:36:50 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F040820341 for ; Wed, 2 Mar 2022 16:36:49 +0000 (UTC) X-FDA: 79200000138.09.46EF2A2 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf09.hostedemail.com (Postfix) with ESMTP id 45535140005 for ; Wed, 2 Mar 2022 16:36:49 +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=1646239008; 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=/PNbeFwa0AFDpaFm8soBx+srw+6LkE/5medj0Pnuzw0=; b=dv6ARQELb9KrBwGlPNLJRXzwHGIL9vGau4uJBJnlfxJAURfUnesxoerB2uQ1mLFWWJpXCY eMBLw+rI7xjWi+Uqs6C7OYC65eMQkQblcKlU2uEt4dLkyYDGPGIakZh4NzoflRtxJBQp1E A9UTsjjFXAN48UAJzg4uhu0IIVPV10k= 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 03/22] kasan: rearrange stack frame info in reports Date: Wed, 2 Mar 2022 17:36:23 +0100 Message-Id: <1ee113a4c111df97d168c820b527cda77a3cac40.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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 45535140005 X-Stat-Signature: w7x8ju7abqfh5enm4fsywxo3k1ufjsqi Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=dv6ARQEL; spf=pass (imf09.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-HE-Tag: 1646239009-428011 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 printing stack frame info before printing page info. - Add object_is_on_stack() check to print_address_description() and add a corresponding WARNING to kasan_print_address_stack_frame(). This looks more in line with the rest of the checks in this function and also allows to avoid complicating code logic wrt line breaks. - Clean up comments related to get_address_stack_frame_info(). Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- mm/kasan/report.c | 12 +++++++++--- mm/kasan/report_generic.c | 15 ++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index ded648c0a0e4..d60ee8b81e2b 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -259,6 +259,15 @@ static void print_address_description(void *addr, u8 tag) pr_err("\n"); } + if (object_is_on_stack(addr)) { + /* + * Currently, KASAN supports printing frame information only + * for accesses to the task's own stack. + */ + kasan_print_address_stack_frame(addr); + pr_err("\n"); + } + if (is_vmalloc_addr(addr)) { struct vm_struct *va = find_vm_area(addr); @@ -278,9 +287,6 @@ static void print_address_description(void *addr, u8 tag) dump_page(page, "kasan: bad access detected"); pr_err("\n"); } - - kasan_print_address_stack_frame(addr); - pr_err("\n"); } static bool meta_row_is_guilty(const void *row, const void *addr) diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 139615ef326b..3751391ff11a 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -211,6 +211,7 @@ static void print_decoded_frame_descr(const char *frame_descr) } } +/* Returns true only if the address is on the current task's stack. */ static bool __must_check get_address_stack_frame_info(const void *addr, unsigned long *offset, const char **frame_descr, @@ -224,13 +225,6 @@ static bool __must_check get_address_stack_frame_info(const void *addr, BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP)); - /* - * NOTE: We currently only support printing frame information for - * accesses to the task's own stack. - */ - if (!object_is_on_stack(addr)) - return false; - aligned_addr = round_down((unsigned long)addr, sizeof(long)); mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE); shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr); @@ -269,14 +263,13 @@ void kasan_print_address_stack_frame(const void *addr) const char *frame_descr; const void *frame_pc; + if (WARN_ON(!object_is_on_stack(addr))) + return; + if (!get_address_stack_frame_info(addr, &offset, &frame_descr, &frame_pc)) return; - /* - * get_address_stack_frame_info only returns true if the given addr is - * on the current task's stack. - */ pr_err("\n"); pr_err("addr %px is located in stack of task %s/%d at offset %lu in frame:\n", addr, current->comm, task_pid_nr(current), offset);