Re: [PATCH 2/8] kasan: test: avoid writing invalid memory

From: Andrey Konovalov
Date: Thu Aug 12 2021 - 09:02:36 EST


On Thu, Aug 12, 2021 at 10:57 AM Marco Elver <elver@xxxxxxxxxx> wrote:
>
> On Wed, 11 Aug 2021 at 21:21, <andrey.konovalov@xxxxxxxxx> wrote:
> > From: Andrey Konovalov <andreyknvl@xxxxxxxxx>
> >
> > Multiple KASAN tests do writes past the allocated objects or writes to
> > freed memory. Turn these writes into reads to avoid corrupting memory.
> > Otherwise, these tests might lead to crashes with the HW_TAGS mode, as it
> > neither uses quarantine nor redzones.
> >
> > Signed-off-by: Andrey Konovalov <andreyknvl@xxxxxxxxx>
>
> Reviewed-by: Marco Elver <elver@xxxxxxxxxx>
>
> although if you need a write primitive somewhere that doesn't corrupt
> memory, you could use atomic_add() or atomic_or() of 0. Although
> technically that's a read-modify-write.

Interesting idea. I'd say let's keep the volatile reads for now, and
change them if we encounter any problem with those.

> For generic mode one issue is
> that these are explicitly instrumented and not through the compiler,
> which is only a problem if you're testing the compiler emits the right
> instrumentation.

On a related point, it seems we have no KASAN tests to check atomic operations.

Filed https://bugzilla.kernel.org/show_bug.cgi?id=214055 for this.

Thanks!