All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Collingbourne <pcc@google.com>
To: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Alexander Potapenko <glider@google.com>,
	George Popescu <georgepope@android.com>,
	Elena Petrova <lenaptr@google.com>,
	Evgenii Stepanov <eugenis@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linux Memory Management List <linux-mm@kvack.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH] kasan: fix unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled
Date: Thu, 6 May 2021 19:59:28 -0700	[thread overview]
Message-ID: <CAMn1gO6zUSN+-BSmKN=WuTJ=oabu1iUBJ1HhrJELPO_HzR8v4Q@mail.gmail.com> (raw)
In-Reply-To: <CA+fCnZcEQBLRQhSkJc_FRdkvYabihY8aho3QHE4jjw10WuuoyQ@mail.gmail.com>

On Thu, May 6, 2021 at 4:58 PM Andrey Konovalov <andreyknvl@gmail.com> wrote:
>
> On Fri, May 7, 2021 at 1:47 AM Peter Collingbourne <pcc@google.com> wrote:
> >
> > On Thu, May 6, 2021 at 3:12 PM Andrey Konovalov <andreyknvl@gmail.com> wrote:
> > >
> > > On Thu, May 6, 2021 at 11:20 PM Peter Collingbourne <pcc@google.com> wrote:
> > > >
> > > > These tests deliberately access these arrays out of bounds,
> > > > which will cause the dynamic local bounds checks inserted by
> > > > CONFIG_UBSAN_LOCAL_BOUNDS to fail and panic the kernel. To avoid this
> > > > problem, access the arrays via volatile pointers, which will prevent
> > > > the compiler from being able to determine the array bounds.
> > > >
> > > > Signed-off-by: Peter Collingbourne <pcc@google.com>
> > > > Cc: stable@vger.kernel.org
> > > > Link: https://linux-review.googlesource.com/id/I90b1713fbfa1bf68ff895aef099ea77b98a7c3b9
> > > > ---
> > > >  lib/test_kasan.c | 14 ++++++++------
> > > >  1 file changed, 8 insertions(+), 6 deletions(-)
> > > >
> > > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> > > > index dc05cfc2d12f..2a078e8e7b8e 100644
> > > > --- a/lib/test_kasan.c
> > > > +++ b/lib/test_kasan.c
> > > > @@ -654,8 +654,8 @@ static char global_array[10];
> > > >
> > > >  static void kasan_global_oob(struct kunit *test)
> > > >  {
> > > > -       volatile int i = 3;
> > > > -       char *p = &global_array[ARRAY_SIZE(global_array) + i];
> > > > +       char *volatile array = global_array;
> > > > +       char *p = &array[ARRAY_SIZE(global_array) + 3];
> > >
> > > Nit: in the kernel, "volatile" usually comes before the pointer type.
> >
> > That would refer to a different type. "volatile char *" is a pointer
> > to volatile char, while "char *volatile" is a volatile pointer to
> > char. The latter is what we want here, because we want to prevent the
> > compiler from inferring things about the pointer itself (i.e. its
> > array bounds), not the data that it refers to.
>
> I see. This is unusual. I'd say this needs to be explicitly explained
> in the commit message, as well as in a comment in the code.

Done in v2.

Peter

  reply	other threads:[~2021-05-07  2:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 21:20 [PATCH] kasan: fix unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled Peter Collingbourne
2021-05-06 21:20 ` Peter Collingbourne
2021-05-06 22:12 ` Andrey Konovalov
2021-05-06 22:12   ` Andrey Konovalov
2021-05-06 23:47   ` Peter Collingbourne
2021-05-06 23:47     ` Peter Collingbourne
2021-05-06 23:57     ` Andrey Konovalov
2021-05-06 23:57       ` Andrey Konovalov
2021-05-07  2:59       ` Peter Collingbourne [this message]
2021-05-07  2:59         ` Peter Collingbourne
2021-05-09  0:30 ` Andrew Morton
2021-05-10 17:16   ` Peter Collingbourne
2021-05-10 17:16     ` Peter Collingbourne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMn1gO6zUSN+-BSmKN=WuTJ=oabu1iUBJ1HhrJELPO_HzR8v4Q@mail.gmail.com' \
    --to=pcc@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=eugenis@google.com \
    --cc=georgepope@android.com \
    --cc=glider@google.com \
    --cc=lenaptr@google.com \
    --cc=linux-mm@kvack.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.