From patchwork Fri Mar 25 01:12:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12791175 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 A920CC433F5 for ; Fri, 25 Mar 2022 01:12:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D7D58D0021; Thu, 24 Mar 2022 21:12:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 387F68D0005; Thu, 24 Mar 2022 21:12:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 250A08D0021; Thu, 24 Mar 2022 21:12:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 153E88D0005 for ; Thu, 24 Mar 2022 21:12:24 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CE632A3EE5 for ; Fri, 25 Mar 2022 01:12:23 +0000 (UTC) X-FDA: 79281132966.26.6AAD003 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf28.hostedemail.com (Postfix) with ESMTP id 2A86EC0035 for ; Fri, 25 Mar 2022 01:12:23 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 15733B8270A; Fri, 25 Mar 2022 01:12:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A98D3C340EC; Fri, 25 Mar 2022 01:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1648170740; bh=xQSfJIuSU52DubWv2LUm5w2eFU4+5HQyYynBzRelMTQ=; h=Date:To:From:In-Reply-To:Subject:From; b=CKa7zkx4QfK6ssZu8owkNkg2oLecNFrvR8POUZbpY7+SEL365ufFh/L7Z9r05Uiwp jA9TVtp6xrj2zDnxtaSCddsV3/tmpYChhjQ8MATsY9bLnGT51aCcMtLzOUiD6k/Kq8 qgjEL2xpwaA8mToDZ5xelAMSdei0dTNqa53YeLU0= Date: Thu, 24 Mar 2022 18:12:20 -0700 To: ryabinin.a.a@gmail.com,glider@google.com,elver@google.com,dvyukov@google.com,andreyknvl@google.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220324180758.96b1ac7e17675d6bc474485e@linux-foundation.org> Subject: [patch 075/114] kasan: rearrange stack frame info in reports Message-Id: <20220325011220.A98D3C340EC@smtp.kernel.org> X-Stat-Signature: 54ti3sqhx63ikmyfwpdoxkf9meybbjqg Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=CKa7zkx4; spf=pass (imf28.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2A86EC0035 X-HE-Tag: 1648170743-16533 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 Subject: kasan: rearrange stack frame info in reports - 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(). Link: https://lkml.kernel.org/r/1ee113a4c111df97d168c820b527cda77a3cac40.1646237226.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko Cc: Andrey Ryabinin Cc: Dmitry Vyukov Cc: Marco Elver Signed-off-by: Andrew Morton --- mm/kasan/report.c | 12 +++++++++--- mm/kasan/report_generic.c | 15 ++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) --- a/mm/kasan/report.c~kasan-rearrange-stack-frame-info-in-reports +++ a/mm/kasan/report.c @@ -259,6 +259,15 @@ static void print_address_description(vo 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(vo 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) --- a/mm/kasan/report_generic.c~kasan-rearrange-stack-frame-info-in-reports +++ a/mm/kasan/report_generic.c @@ -211,6 +211,7 @@ static void print_decoded_frame_descr(co } } +/* 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_sta 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(con 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);