From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05601C433F5 for ; Thu, 17 Feb 2022 12:00:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240133AbiBQMAb (ORCPT ); Thu, 17 Feb 2022 07:00:31 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234641AbiBQMA3 (ORCPT ); Thu, 17 Feb 2022 07:00:29 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0E829294126 for ; Thu, 17 Feb 2022 04:00:15 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CC7DD113E; Thu, 17 Feb 2022 04:00:14 -0800 (PST) Received: from lakrids (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 65E833F66F; Thu, 17 Feb 2022 04:00:12 -0800 (PST) Date: Thu, 17 Feb 2022 12:00:09 +0000 From: Mark Rutland To: andrey.konovalov@linux.dev Cc: Marco Elver , Alexander Potapenko , Andrew Morton , Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Vincenzo Frascino , Catalin Marinas , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: Re: [PATCH mm] kasan: print virtual mapping info in reports Message-ID: References: <5b120f7cadcc0e0d8d5f41fd0cff35981b3f7f3a.1645038022.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5b120f7cadcc0e0d8d5f41fd0cff35981b3f7f3a.1645038022.git.andreyknvl@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 16, 2022 at 08:01:37PM +0100, andrey.konovalov@linux.dev wrote: > From: Andrey Konovalov > > Print virtual mapping range and its creator in reports affecting virtual > mappings. > > Also get physical page pointer for such mappings, so page information > gets printed as well. > > Signed-off-by: Andrey Konovalov > > --- > > Note: no need to merge this patch into any of the KASAN vmalloc patches > that are already in mm, better to keep it separate. > --- > mm/kasan/report.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/mm/kasan/report.c b/mm/kasan/report.c > index 137c2c0b09db..8002fb3c417d 100644 > --- a/mm/kasan/report.c > +++ b/mm/kasan/report.c > @@ -260,8 +260,18 @@ static void print_address_description(void *addr, u8 tag) > pr_err(" %pS\n", addr); > } > > + if (is_vmalloc_addr(addr)) { > + struct vm_struct *va = find_vm_area(addr); > + > + pr_err("The buggy address belongs to the virtual mapping at\n" > + " [%px, %px) created by:\n" > + " %pS\n", va->addr, va->addr + va->size, va->caller); The return value of find_vm_area() needs a NULL check here; is_vmalloc_addr(addr) just checks that `addr` is within the vmalloc VA range, and doesn't guarantee that there is a vmap_area associated with that `addr`. Without the NULL-check, we'll blow up on the `va->addr` dereference and will fail to make the report, which would be unfortunate. Thanks, Mark. > + > + page = vmalloc_to_page(page); > + } > + > if (page) { > - pr_err("The buggy address belongs to the page:\n"); > + pr_err("The buggy address belongs to the physical page:\n"); > dump_page(page, "kasan: bad access detected"); > } > > -- > 2.25.1 >