2020-11-10 22:17:06

by Andrey Konovalov

[permalink] [raw]
Subject: [PATCH v9 21/44] kasan: kasan_non_canonical_hook only for software modes

This is a preparatory commit for the upcoming addition of a new hardware
tag-based (MTE-based) KASAN mode.

kasan_non_canonical_hook() is only applicable to KASAN modes that use
shadow memory, and won't be needed for hardware tag-based KASAN.

No functional changes for software modes.

Signed-off-by: Andrey Konovalov <[email protected]>
Signed-off-by: Vincenzo Frascino <[email protected]>
Reviewed-by: Marco Elver <[email protected]>
---
Change-Id: Icc9f5ef100a2e86f3a4214a0c3131a68266181b2
---
mm/kasan/report.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 5d5733831ad7..594bad2a3a5e 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -403,7 +403,8 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write,
return ret;
}

-#ifdef CONFIG_KASAN_INLINE
+#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
+ defined(CONFIG_KASAN_INLINE)
/*
* With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
* canonical half of the address space) cause out-of-bounds shadow memory reads
--
2.29.2.222.g5d2a92d10f8-goog


2020-11-11 15:14:10

by Alexander Potapenko

[permalink] [raw]
Subject: Re: [PATCH v9 21/44] kasan: kasan_non_canonical_hook only for software modes

On Tue, Nov 10, 2020 at 11:11 PM Andrey Konovalov <[email protected]> wrote:
>
> This is a preparatory commit for the upcoming addition of a new hardware
> tag-based (MTE-based) KASAN mode.
>
> kasan_non_canonical_hook() is only applicable to KASAN modes that use
> shadow memory, and won't be needed for hardware tag-based KASAN.
>
> No functional changes for software modes.
>
> Signed-off-by: Andrey Konovalov <[email protected]>
> Signed-off-by: Vincenzo Frascino <[email protected]>
> Reviewed-by: Marco Elver <[email protected]>
> ---
> Change-Id: Icc9f5ef100a2e86f3a4214a0c3131a68266181b2
> ---
> mm/kasan/report.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> index 5d5733831ad7..594bad2a3a5e 100644
> --- a/mm/kasan/report.c
> +++ b/mm/kasan/report.c
> @@ -403,7 +403,8 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write,
> return ret;
> }
>
> -#ifdef CONFIG_KASAN_INLINE
> +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
> + defined(CONFIG_KASAN_INLINE)
> /*
> * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
> * canonical half of the address space) cause out-of-bounds shadow memory reads

Perhaps this comment also needs to be updated.

> --
> 2.29.2.222.g5d2a92d10f8-goog
>


--
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

2020-11-11 18:54:16

by Andrey Konovalov

[permalink] [raw]
Subject: Re: [PATCH v9 21/44] kasan: kasan_non_canonical_hook only for software modes

On Wed, Nov 11, 2020 at 4:09 PM Alexander Potapenko <[email protected]> wrote:
>
> On Tue, Nov 10, 2020 at 11:11 PM Andrey Konovalov <[email protected]> wrote:
> >
> > This is a preparatory commit for the upcoming addition of a new hardware
> > tag-based (MTE-based) KASAN mode.
> >
> > kasan_non_canonical_hook() is only applicable to KASAN modes that use
> > shadow memory, and won't be needed for hardware tag-based KASAN.
> >
> > No functional changes for software modes.
> >
> > Signed-off-by: Andrey Konovalov <[email protected]>
> > Signed-off-by: Vincenzo Frascino <[email protected]>
> > Reviewed-by: Marco Elver <[email protected]>
> > ---
> > Change-Id: Icc9f5ef100a2e86f3a4214a0c3131a68266181b2
> > ---
> > mm/kasan/report.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> > index 5d5733831ad7..594bad2a3a5e 100644
> > --- a/mm/kasan/report.c
> > +++ b/mm/kasan/report.c
> > @@ -403,7 +403,8 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write,
> > return ret;
> > }
> >
> > -#ifdef CONFIG_KASAN_INLINE
> > +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
> > + defined(CONFIG_KASAN_INLINE)
> > /*
> > * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
> > * canonical half of the address space) cause out-of-bounds shadow memory reads
>
> Perhaps this comment also needs to be updated.

In what way?

2020-11-12 15:19:02

by Alexander Potapenko

[permalink] [raw]
Subject: Re: [PATCH v9 21/44] kasan: kasan_non_canonical_hook only for software modes

On Wed, Nov 11, 2020 at 7:52 PM 'Andrey Konovalov' via kasan-dev
<[email protected]> wrote:
>
> On Wed, Nov 11, 2020 at 4:09 PM Alexander Potapenko <[email protected]> wrote:
> >
> > On Tue, Nov 10, 2020 at 11:11 PM Andrey Konovalov <[email protected]> wrote:
> > >
> > > This is a preparatory commit for the upcoming addition of a new hardware
> > > tag-based (MTE-based) KASAN mode.
> > >
> > > kasan_non_canonical_hook() is only applicable to KASAN modes that use
> > > shadow memory, and won't be needed for hardware tag-based KASAN.
> > >
> > > No functional changes for software modes.
> > >
> > > Signed-off-by: Andrey Konovalov <[email protected]>
> > > Signed-off-by: Vincenzo Frascino <[email protected]>
> > > Reviewed-by: Marco Elver <[email protected]>
> > > ---
> > > Change-Id: Icc9f5ef100a2e86f3a4214a0c3131a68266181b2
> > > ---
> > > mm/kasan/report.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> > > index 5d5733831ad7..594bad2a3a5e 100644
> > > --- a/mm/kasan/report.c
> > > +++ b/mm/kasan/report.c
> > > @@ -403,7 +403,8 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write,
> > > return ret;
> > > }
> > >
> > > -#ifdef CONFIG_KASAN_INLINE
> > > +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
> > > + defined(CONFIG_KASAN_INLINE)
> > > /*
> > > * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
> > > * canonical half of the address space) cause out-of-bounds shadow memory reads
> >
> > Perhaps this comment also needs to be updated.
>
> In what way?

Ok, maybe not. I thought you were restricting the set of configs under
which this hook is used, so this should've been explained.
But as far as I understand, CONFIG_KASAN_INLINE already implies
"defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)",
doesn't it?
Maybe this change is not needed at all then?

>
> --
> 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 [email protected].
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/CAAeHK%2BwX%2BJPyZm2A5mDdGFCqnH6kdSBLyOZ2TnWfZnZuq_V0Bw%40mail.gmail.com.



--
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

2020-11-12 19:29:05

by Andrey Konovalov

[permalink] [raw]
Subject: Re: [PATCH v9 21/44] kasan: kasan_non_canonical_hook only for software modes

On Thu, Nov 12, 2020 at 4:16 PM Alexander Potapenko <[email protected]> wrote:
>
> On Wed, Nov 11, 2020 at 7:52 PM 'Andrey Konovalov' via kasan-dev
> <[email protected]> wrote:
> >
> > On Wed, Nov 11, 2020 at 4:09 PM Alexander Potapenko <[email protected]> wrote:
> > >
> > > On Tue, Nov 10, 2020 at 11:11 PM Andrey Konovalov <[email protected]> wrote:
> > > >
> > > > This is a preparatory commit for the upcoming addition of a new hardware
> > > > tag-based (MTE-based) KASAN mode.
> > > >
> > > > kasan_non_canonical_hook() is only applicable to KASAN modes that use
> > > > shadow memory, and won't be needed for hardware tag-based KASAN.
> > > >
> > > > No functional changes for software modes.
> > > >
> > > > Signed-off-by: Andrey Konovalov <[email protected]>
> > > > Signed-off-by: Vincenzo Frascino <[email protected]>
> > > > Reviewed-by: Marco Elver <[email protected]>
> > > > ---
> > > > Change-Id: Icc9f5ef100a2e86f3a4214a0c3131a68266181b2
> > > > ---
> > > > mm/kasan/report.c | 3 ++-
> > > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> > > > index 5d5733831ad7..594bad2a3a5e 100644
> > > > --- a/mm/kasan/report.c
> > > > +++ b/mm/kasan/report.c
> > > > @@ -403,7 +403,8 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write,
> > > > return ret;
> > > > }
> > > >
> > > > -#ifdef CONFIG_KASAN_INLINE
> > > > +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
> > > > + defined(CONFIG_KASAN_INLINE)
> > > > /*
> > > > * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
> > > > * canonical half of the address space) cause out-of-bounds shadow memory reads
> > >
> > > Perhaps this comment also needs to be updated.
> >
> > In what way?
>
> Ok, maybe not. I thought you were restricting the set of configs under
> which this hook is used, so this should've been explained.
> But as far as I understand, CONFIG_KASAN_INLINE already implies
> "defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)",
> doesn't it?
> Maybe this change is not needed at all then?

Ah, yes, you're right. Will drop this patch, thanks!