Re: [PATCH v2] mm: kmsan: Panic on failure to allocate early boot metadata

From: Alexander Potapenko
Date: Mon Oct 16 2023 - 11:53:17 EST


On Mon, Oct 16, 2023 at 5:34 PM Pedro Falcato <pedro.falcato@xxxxxxxxx> wrote:
>
> Given large enough allocations and a machine with low enough memory (i.e
> a default QEMU VM), it's entirely possible that
> kmsan_init_alloc_meta_for_range's shadow+origin allocation fails.
>
> Instead of eating a NULL deref kernel oops, check explicitly for
> memblock_alloc() failure and panic with a nice error message.

For posterity, it is generally quite important for the allocated
shadow and origin to be contiguous, otherwise an unaligned memory
write may result in memory corruption (the corresponding unaligned
shadow write will be assuming that shadow pages are adjacent).
So instead of panicking we could have split the range into smaller
ones until the allocation succeeds, but that would've led to
hard-to-debug problems in the future.

>
> Signed-off-by: Pedro Falcato <pedro.falcato@xxxxxxxxx>
Reviewed-by: Alexander Potapenko <glider@xxxxxxxxxx>