Re: [PATCH v3 1/1] kasan: Add memzero init for unaligned size under SLUB debug

From: Andrey Konovalov
Date: Thu Jul 01 2021 - 09:31:57 EST


On Wed, Jun 30, 2021 at 10:13 PM Marco Elver <elver@xxxxxxxxxx> wrote:
>
> > + if (IS_ENABLED(CONFIG_SLUB_DEBUG) && init && ((unsigned long)size & KASAN_GRANULE_MASK)) {
> > + init = false;
> > + memzero_explicit((void *)addr, size);
> > + }
> > size = round_up(size, KASAN_GRANULE_SIZE);
> >
> > hw_set_mem_tag_range((void *)addr, size, tag, init);
>
> I think this solution might be fine for now, as I don't see an easy way
> to do this without some major refactor to use kmem_cache_debug_flags().
>
> However, I think there's an intermediate solution where we only check
> the static-key 'slub_debug_enabled' though. Because I've checked, and
> various major distros _do_ enabled CONFIG_SLUB_DEBUG. But the static
> branch just makes sure there's no performance overhead.
>
> Checking the static branch requires including mm/slab.h into
> mm/kasan/kasan.h, which we currently don't do and perhaps wanted to
> avoid. Although I don't see a reason there, because there's no circular
> dependency even if we did.

Most likely this won't be a problem. We already include ../slab.h into
many mm/kasan/*.c files.

> Andrey, any opinion?

I like this approach. Easy to implement and is better than checking
only CONFIG_SLUB_DEBUG.

Thanks, Marco!