* [PATCH mm] kasan: print virtual mapping info in reports
@ 2022-02-16 19:01 andrey.konovalov
2022-02-16 19:31 ` Marco Elver
2022-02-17 12:00 ` Mark Rutland
0 siblings, 2 replies; 7+ messages in thread
From: andrey.konovalov @ 2022-02-16 19:01 UTC (permalink / raw)
To: Marco Elver, Alexander Potapenko, Andrew Morton
Cc: Andrey Konovalov, Dmitry Vyukov, Andrey Ryabinin, kasan-dev,
Vincenzo Frascino, Catalin Marinas, linux-mm, linux-kernel,
Andrey Konovalov
From: Andrey Konovalov <andreyknvl@google.com>
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 <andreyknvl@google.com>
---
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);
+
+ 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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH mm] kasan: print virtual mapping info in reports
2022-02-16 19:01 [PATCH mm] kasan: print virtual mapping info in reports andrey.konovalov
@ 2022-02-16 19:31 ` Marco Elver
2022-02-16 20:42 ` Andrey Konovalov
2022-02-17 12:00 ` Mark Rutland
1 sibling, 1 reply; 7+ messages in thread
From: Marco Elver @ 2022-02-16 19:31 UTC (permalink / raw)
To: andrey.konovalov
Cc: Alexander Potapenko, Andrew Morton, Andrey Konovalov,
Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Vincenzo Frascino,
Catalin Marinas, linux-mm, linux-kernel, Andrey Konovalov
On Wed, 16 Feb 2022 at 20:01, <andrey.konovalov@linux.dev> wrote:
>
> From: Andrey Konovalov <andreyknvl@google.com>
>
> 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 <andreyknvl@google.com>
>
> ---
>
> 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);
Can you show an example of what this looks like? It's not showing a
stack trace, so why not continue the line and just say "... created
by: %pS\n"
> + 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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH mm] kasan: print virtual mapping info in reports
2022-02-16 19:31 ` Marco Elver
@ 2022-02-16 20:42 ` Andrey Konovalov
2022-02-16 23:26 ` Marco Elver
0 siblings, 1 reply; 7+ messages in thread
From: Andrey Konovalov @ 2022-02-16 20:42 UTC (permalink / raw)
To: Marco Elver
Cc: andrey.konovalov, Alexander Potapenko, Andrew Morton,
Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Vincenzo Frascino,
Catalin Marinas, Linux Memory Management List, LKML,
Andrey Konovalov
On Wed, Feb 16, 2022 at 8:31 PM Marco Elver <elver@google.com> wrote:
>
> On Wed, 16 Feb 2022 at 20:01, <andrey.konovalov@linux.dev> wrote:
> >
> > From: Andrey Konovalov <andreyknvl@google.com>
> >
> > 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 <andreyknvl@google.com>
> >
> > ---
> >
> > 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);
>
> Can you show an example of what this looks like?
[ 20.883723] The buggy address belongs to the virtual mapping at
[ 20.883723] [ffff8000081c9000, ffff8000081cb000) created by:
[ 20.883723] vmalloc_oob+0xd8/0x4dc
> It's not showing a stack trace,
No, only a single frame.
> so why not continue the line and just say "... created by: %pS\n"
Putting it on a separate line makes the line lengths looks more balanced.
Also, printing a frame on a separate line is consistent with the rest
of KASAN reporting code.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH mm] kasan: print virtual mapping info in reports
2022-02-16 20:42 ` Andrey Konovalov
@ 2022-02-16 23:26 ` Marco Elver
0 siblings, 0 replies; 7+ messages in thread
From: Marco Elver @ 2022-02-16 23:26 UTC (permalink / raw)
To: Andrey Konovalov
Cc: andrey.konovalov, Alexander Potapenko, Andrew Morton,
Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Vincenzo Frascino,
Catalin Marinas, Linux Memory Management List, LKML,
Andrey Konovalov
On Wed, 16 Feb 2022 at 21:42, Andrey Konovalov <andreyknvl@gmail.com> wrote:
>
> On Wed, Feb 16, 2022 at 8:31 PM Marco Elver <elver@google.com> wrote:
> >
> > On Wed, 16 Feb 2022 at 20:01, <andrey.konovalov@linux.dev> wrote:
> > >
> > > From: Andrey Konovalov <andreyknvl@google.com>
> > >
> > > 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 <andreyknvl@google.com>
> > >
> > > ---
> > >
> > > 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);
> >
> > Can you show an example of what this looks like?
>
> [ 20.883723] The buggy address belongs to the virtual mapping at
> [ 20.883723] [ffff8000081c9000, ffff8000081cb000) created by:
> [ 20.883723] vmalloc_oob+0xd8/0x4dc
>
> > It's not showing a stack trace,
>
> No, only a single frame.
>
> > so why not continue the line and just say "... created by: %pS\n"
>
> Putting it on a separate line makes the line lengths looks more balanced.
>
> Also, printing a frame on a separate line is consistent with the rest
> of KASAN reporting code.
That's reasonable, thanks.
Reviewed-by: Marco Elver <elver@google.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH mm] kasan: print virtual mapping info in reports
2022-02-16 19:01 [PATCH mm] kasan: print virtual mapping info in reports andrey.konovalov
2022-02-16 19:31 ` Marco Elver
@ 2022-02-17 12:00 ` Mark Rutland
2022-02-18 15:07 ` Andrey Konovalov
1 sibling, 1 reply; 7+ messages in thread
From: Mark Rutland @ 2022-02-17 12:00 UTC (permalink / raw)
To: andrey.konovalov
Cc: Marco Elver, Alexander Potapenko, Andrew Morton,
Andrey Konovalov, Dmitry Vyukov, Andrey Ryabinin, kasan-dev,
Vincenzo Frascino, Catalin Marinas, linux-mm, linux-kernel,
Andrey Konovalov
On Wed, Feb 16, 2022 at 08:01:37PM +0100, andrey.konovalov@linux.dev wrote:
> From: Andrey Konovalov <andreyknvl@google.com>
>
> 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 <andreyknvl@google.com>
>
> ---
>
> 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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH mm] kasan: print virtual mapping info in reports
2022-02-17 12:00 ` Mark Rutland
@ 2022-02-18 15:07 ` Andrey Konovalov
0 siblings, 0 replies; 7+ messages in thread
From: Andrey Konovalov @ 2022-02-18 15:07 UTC (permalink / raw)
To: Mark Rutland
Cc: andrey.konovalov, Marco Elver, Alexander Potapenko,
Andrew Morton, Dmitry Vyukov, Andrey Ryabinin, kasan-dev,
Vincenzo Frascino, Catalin Marinas, Linux Memory Management List,
LKML, Andrey Konovalov
On Thu, Feb 17, 2022 at 1:00 PM Mark Rutland <mark.rutland@arm.com> wrote:
>
> On Wed, Feb 16, 2022 at 08:01:37PM +0100, andrey.konovalov@linux.dev wrote:
> > From: Andrey Konovalov <andreyknvl@google.com>
> >
> > 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 <andreyknvl@google.com>
> >
> > ---
> >
> > 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.
Indeed. Will fix in v2. Thanks, Mark!
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH mm] kasan: print virtual mapping info in reports
@ 2022-02-22 16:42 andrey.konovalov
0 siblings, 0 replies; 7+ messages in thread
From: andrey.konovalov @ 2022-02-22 16:42 UTC (permalink / raw)
To: Andrew Morton
Cc: Andrey Konovalov, Mark Rutland, Marco Elver, Alexander Potapenko,
Dmitry Vyukov, Andrey Ryabinin, kasan-dev, linux-mm,
linux-kernel, Andrey Konovalov
From: Andrey Konovalov <andreyknvl@google.com>
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 <andreyknvl@google.com>
---
Note: no need to merge this patch into any of the KASAN vmalloc patches
that are already in mm, better to keep it separate.
Changes v1->v2:
- Add find_vm_area() return value NULL check as suggested by Mark Rutland.
---
mm/kasan/report.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 137c2c0b09db..f64352008bb8 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -260,8 +260,21 @@ 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);
+
+ if (va) {
+ 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);
+
+ 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
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-02-22 16:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 19:01 [PATCH mm] kasan: print virtual mapping info in reports andrey.konovalov
2022-02-16 19:31 ` Marco Elver
2022-02-16 20:42 ` Andrey Konovalov
2022-02-16 23:26 ` Marco Elver
2022-02-17 12:00 ` Mark Rutland
2022-02-18 15:07 ` Andrey Konovalov
2022-02-22 16:42 andrey.konovalov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).