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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4028CC433FE for ; Wed, 2 Mar 2022 17:30:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0F278D0002; Wed, 2 Mar 2022 12:30:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BBE7C8D0001; Wed, 2 Mar 2022 12:30:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A86CF8D0002; Wed, 2 Mar 2022 12:30:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 9AAD88D0001 for ; Wed, 2 Mar 2022 12:30:03 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4534F251B0 for ; Wed, 2 Mar 2022 17:30:03 +0000 (UTC) X-FDA: 79200134286.13.0EDE94B Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by imf29.hostedemail.com (Postfix) with ESMTP id 913AD120014 for ; Wed, 2 Mar 2022 17:30:02 +0000 (UTC) Received: by mail-qt1-f172.google.com with SMTP id s15so2272677qtk.10 for ; Wed, 02 Mar 2022 09:30:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OLg2W0bKVEV676ftdFrveZxXudZ89DnOZdQYznwvXt0=; b=eusAHOKuaAy8skenQKUgbUEHTRjaazo3Q5Vric3LJ64Un9yn2Qxv6E3+qftc5HQ3fP Y24ULMuYdKZXUdA6V97e7xXrDABj6gbBpa0t3L2z80X2Tx76wU+IdXLQIAIDpTq2hb3t qbIFozoZ6IYLDwqJ/bdERlWnAKkU6KA+HhISc5BOsN66fkMIjpqPnuCMoE88ckC117e1 xPasnBAbn+4AH9CBIgCZfcN6JF1MJLfNIZbHzyvhrygCG1y7KdFueUEGrjkvKqH4Rsys /jHnUflcZt0z07cTTALTKCvqZ5EhpSW8V89ZGTJBlbXY2W9jAR7B9l9//yo/WMrOlQQT nr6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OLg2W0bKVEV676ftdFrveZxXudZ89DnOZdQYznwvXt0=; b=EFLhV0s/mZEXjL8ItNhx+6Y0OTOMzylK5fsLSx1kHbZXjsV+e36RQdFVxvR3YPuIjE vdQZzUrJoHQHfNEPzWXvyXaM7hDAdhRnK38PwF8OH0uHWnqjG6Xp2FJr7yaBuB9dFKwo RObFRqDNTzgmGaYkH38rimCKrHfRCM57LPJC9YJdcKmlRnP61UuDP+T08+tSI4yT1oTK 1eCp+6I9vWt/feeMbgRPEb6BioYtAom5Xs++2wex+6xiheOvll6qvEaSXVAsYIFQjXOE NUeqVraYBleCBpoGWnpYz9CxywxbnJuQM9DIp85xx1oieEFG/zY2ErALcUYcdZjx9e1f kHYw== X-Gm-Message-State: AOAM532JiYJrMHDjf8thts2ptg5C/AUlEfT390+DzQyF74zjuIfksGJM R9XxrUj0jMwSZ2pgAQNjPx8+XXpAjzHUh1ci3eDX6Q== X-Google-Smtp-Source: ABdhPJwMl/DAJENFpHJAIZvToP+w7g3zaSuQK5gAQLCxwlz1MG9uJPicYMrn1fDIPoluT57biFRGwrjc6Kpgyw5BVxQ= X-Received: by 2002:a05:622a:1709:b0:2de:821:b3e2 with SMTP id h9-20020a05622a170900b002de0821b3e2mr24574927qtk.578.1646242201642; Wed, 02 Mar 2022 09:30:01 -0800 (PST) MIME-Version: 1.0 References: <1ee113a4c111df97d168c820b527cda77a3cac40.1646237226.git.andreyknvl@google.com> In-Reply-To: <1ee113a4c111df97d168c820b527cda77a3cac40.1646237226.git.andreyknvl@google.com> From: Alexander Potapenko Date: Wed, 2 Mar 2022 18:29:25 +0100 Message-ID: Subject: Re: [PATCH mm 03/22] kasan: rearrange stack frame info in reports To: andrey.konovalov@linux.dev Cc: Marco Elver , Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev , Andrew Morton , Linux Memory Management List , LKML , Andrey Konovalov Content-Type: multipart/alternative; boundary="000000000000a533c905d93fa1c4" X-Rspamd-Queue-Id: 913AD120014 X-Stat-Signature: iyww3whrg7mqztb7ypkfirofxurk6nmm X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=eusAHOKu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of glider@google.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=glider@google.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646242202-958659 X-Bogosity: Ham, tests=bogofilter, spamicity=0.052578, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --000000000000a533c905d93fa1c4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 2, 2022 at 5:36 PM wrote: > 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 =3D 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 =3D round_down((unsigned long)addr, sizeof(long)); > mem_ptr =3D round_down(aligned_addr, KASAN_GRANULE_SIZE); > shadow_ptr =3D 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); > -- > 2.25.1 > > -- > You received this message because you are subscribed to the Google Groups > "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/kasan-dev/1ee113a4c111df97d168c820b527c= da77a3cac40.1646237226.git.andreyknvl%40google.com > . > --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Liana Sebastian Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Diese E-Mail ist vertraulich. Falls Sie diese f=C3=A4lschlicherweise erhalt= en haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, l=C3=B6schen Sie alle Kopien und Anh=C3=A4nge davon und lassen Sie mich bit= te wissen, dass die E-Mail an die falsche Person gesendet wurde. This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person. --000000000000a533c905d93fa1c4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Mar 2, 2022 at 5:36 PM <andrey.konovalov@linux.dev&= gt; wrote:
From:= Andrey Konovalov <andreyknvl@google.com>

- Move printing stack frame info before printing page info.

- Add object_is_on_stack() check to print_address_description()
=C2=A0 and add a corresponding WARNING to kasan_print_address_stack_frame()= .
=C2=A0 This looks more in line with the rest of the checks in this function=
=C2=A0 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 <andreyknvl@google.com>
Revi= ewed-by: Alexander Potapenko <glide= r@google.com>=C2=A0
---
=C2=A0mm/kasan/report.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 12 +++++++++---<= br> =C2=A0mm/kasan/report_generic.c | 15 ++++-----------
=C2=A02 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 t= ag)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pr_err("\n&quo= t;);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (object_is_on_stack(addr)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/*
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * Currently, KASAN= supports printing frame information only
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * for accesses to = the task's own stack.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0kasan_print_address= _stack_frame(addr);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pr_err("\n&quo= t;);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (is_vmalloc_addr(addr)) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct vm_struct *v= a =3D find_vm_area(addr);

@@ -278,9 +287,6 @@ static void print_address_description(void *addr, u8 ta= g)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dump_page(page, &qu= ot;kasan: bad access detected");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pr_err("\n&quo= t;);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
-
-=C2=A0 =C2=A0 =C2=A0 =C2=A0kasan_print_address_stack_frame(addr);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0pr_err("\n");
=C2=A0}

=C2=A0static 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)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0}

+/* Returns true only if the address is on the current task's stack. */=
=C2=A0static bool __must_check get_address_stack_frame_info(const void *add= r,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned long *offset,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 const char **frame_descr,
@@ -224,13 +225,6 @@ static bool __must_check get_address_stack_frame_info(= const void *addr,

=C2=A0 =C2=A0 =C2=A0 =C2=A0 BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP));=

-=C2=A0 =C2=A0 =C2=A0 =C2=A0/*
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 * NOTE: We currently only support printing fra= me information for
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 * accesses to the task's own stack.
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 */
-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!object_is_on_stack(addr))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return false;
-
=C2=A0 =C2=A0 =C2=A0 =C2=A0 aligned_addr =3D round_down((unsigned long)addr= , sizeof(long));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 mem_ptr =3D round_down(aligned_addr, KASAN_GRAN= ULE_SIZE);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 shadow_ptr =3D kasan_mem_to_shadow((void *)alig= ned_addr);
@@ -269,14 +263,13 @@ void kasan_print_address_stack_frame(const void *addr= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 const char *frame_descr;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 const void *frame_pc;

+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (WARN_ON(!object_is_on_stack(addr)))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!get_address_stack_frame_info(addr, &of= fset, &frame_descr,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &= amp;frame_pc))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;

-=C2=A0 =C2=A0 =C2=A0 =C2=A0/*
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 * get_address_stack_frame_info only returns tr= ue if the given addr is
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 * on the current task's stack.
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 */
=C2=A0 =C2=A0 =C2=A0 =C2=A0 pr_err("\n");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 pr_err("addr %px is located in stack of ta= sk %s/%d at offset %lu in frame:\n",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0addr, current->co= mm, task_pid_nr(current), offset);
--
2.25.1

--
You received this message because you are subscribed to the Google Groups &= quot;kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to kasan-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://gro= ups.google.com/d/msgid/kasan-dev/1ee113a4c111df97d168c820b527cda77a3cac40.1= 646237226.git.andreyknvl%40google.com.


--
Alexander Potapenko
Software= Engineer

Google Germany GmbH
Erika-Mann-Stra=C3=9Fe, 33
80636= M=C3=BCnchen

Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Liana Sebasti= an
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellsch= aft: Hamburg

Diese E-Mail ist vertraulich. Falls Sie diese f=C3=A4ls= chlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jeman= d anderes weiter, l=C3=B6schen Sie alle Kopien und Anh=C3=A4nge davon und l= assen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet= wurde.

=C2=A0 =C2=A0 =C2=A0

This e-mail is confidential. If= you received this communication by mistake, please don't forward it to= anyone else, please erase all copies and attachments, and please let me kn= ow that it has gone to the wrong person.
--000000000000a533c905d93fa1c4--