linux/mm/kfence
Pimyn Girgis 870ff19251 mm/kfence: randomize the freelist on initialization
Randomize the KFENCE freelist during pool initialization to make
allocation patterns less predictable.  This is achieved by shuffling the
order in which metadata objects are added to the freelist using
get_random_u32_below().

Additionally, ensure the error path correctly calculates the address range
to be reset if initialization fails, as the address increment logic has
been moved to a separate loop.

Link: https://lkml.kernel.org/r/20260120161510.3289089-1-pimyn@google.com
Fixes: 0ce20dd840 ("mm: add Kernel Electric-Fence infrastructure")
Signed-off-by: Pimyn Girgis <pimyn@google.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Ernesto Martnez Garca <ernesto.martinezgarcia@tugraz.at>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Kees Cook <kees@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
History 2026-01-26 19:03:48 -08:00
..
.kunitconfig kfence: test: use new suite_{init/exit} support, add .kunitconfig 2022-05-02 12:35:57 -06:00
core.c mm/kfence: randomize the freelist on initialization 2026-01-26 19:03:48 -08:00
kfence.h kfence: save freeing stack trace at calling time instead of freeing time 2024-09-01 20:26:12 -07:00
kfence_test.c mm/kfence: use str_write_read() helper in get_access_type() 2025-01-25 20:22:45 -08:00
Makefile kfence: avoid passing -g for test 2023-03-23 17:18:35 -07:00
report.c mm/kfence: use str_write_read() helper in get_access_type() 2025-01-25 20:22:45 -08:00