Skip to content

Commit

Permalink
arm64: Fix KASAN random tag seed initialization
Browse files Browse the repository at this point in the history
[ Upstream commit f75c235 ]

Currently, kasan_init_sw_tags() is called before setup_per_cpu_areas(),
so per_cpu(prng_state, cpu) accesses the same address regardless of the
value of "cpu", and the same seed value gets copied to the percpu area
for every CPU. Fix this by moving the call to smp_prepare_boot_cpu(),
which is the first architecture hook after setup_per_cpu_areas().

Fixes: 3c9e3aa ("kasan: add tag related helper functions")
Fixes: 3f41b60 ("kasan: fix random seed generation for tag-based mode")
Signed-off-by: Samuel Holland <[email protected]>
Reviewed-by: Andrey Konovalov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Catalin Marinas <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
SiFiveHolland authored and gregkh committed Aug 29, 2024
1 parent 8555383 commit c58f777
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 0 additions & 3 deletions arch/arm64/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,6 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
smp_init_cpus();
smp_build_mpidr_hash();

/* Init percpu seeds for random tags after cpus are set up. */
kasan_init_sw_tags();

#ifdef CONFIG_ARM64_SW_TTBR0_PAN
/*
* Make sure init_thread_info.ttbr0 always generates translation
Expand Down
2 changes: 2 additions & 0 deletions arch/arm64/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ void __init smp_prepare_boot_cpu(void)
init_gic_priority_masking();

kasan_init_hw_tags();
/* Init percpu seeds for random tags after cpus are set up. */
kasan_init_sw_tags();
}

/*
Expand Down

0 comments on commit c58f777

Please sign in to comment.