The patch titled Subject: kfence-limit-currently-covered-allocations-when-pool-nearly-full-fix has been removed from the -mm tree. Its filename was kfence-limit-currently-covered-allocations-when-pool-nearly-full-fix.patch This patch was dropped because it was folded into kfence-limit-currently-covered-allocations-when-pool-nearly-full.patch ------------------------------------------------------ From: Marco Elver <elver@xxxxxxxxxx> Subject: kfence-limit-currently-covered-allocations-when-pool-nearly-full-fix * Simplify and just use hash_32(). * Use more random stack_hash_seed. Link: https://lkml.kernel.org/r/YU3MRGaCaJiYht5g@xxxxxxxxxxxxxxxx Signed-off-by: Marco Elver <elver@xxxxxxxxxx> Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Cc: Alexander Potapenko <glider@xxxxxxxxxx> Cc: Aleksandr Nogikh <nogikh@xxxxxxxxxx> Cc: Jann Horn <jannh@xxxxxxxxxx> Cc: Taras Madan <tarasmadan@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/kfence/core.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) --- a/mm/kfence/core.c~kfence-limit-currently-covered-allocations-when-pool-nearly-full-fix +++ a/mm/kfence/core.c @@ -10,6 +10,7 @@ #include <linux/atomic.h> #include <linux/bug.h> #include <linux/debugfs.h> +#include <linux/hash.h> #include <linux/irq_work.h> #include <linux/jhash.h> #include <linux/kcsan-checks.h> @@ -122,14 +123,21 @@ atomic_t kfence_allocation_gate = ATOMIC * P(alloc_traces) = (1 - e^(-HNUM * (alloc_traces / SIZE)) ^ HNUM */ #define ALLOC_COVERED_HNUM 2 -#define ALLOC_COVERED_SIZE (1 << (const_ilog2(CONFIG_KFENCE_NUM_OBJECTS) + 2)) -#define ALLOC_COVERED_HNEXT(h) (1664525 * (h) + 1013904223) +#define ALLOC_COVERED_ORDER (const_ilog2(CONFIG_KFENCE_NUM_OBJECTS) + 2) +#define ALLOC_COVERED_SIZE (1 << ALLOC_COVERED_ORDER) +#define ALLOC_COVERED_HNEXT(h) hash_32(h, ALLOC_COVERED_ORDER) #define ALLOC_COVERED_MASK (ALLOC_COVERED_SIZE - 1) static atomic_t alloc_covered[ALLOC_COVERED_SIZE]; /* Stack depth used to determine uniqueness of an allocation. */ #define UNIQUE_ALLOC_STACK_DEPTH 8UL +/* + * Randomness for stack hashes, making the same collisions across reboots and + * different machines less likely. + */ +static u32 stack_hash_seed __ro_after_init; + /* Statistics counters for debugfs. */ enum kfence_counter_id { KFENCE_COUNTER_ALLOCATED, @@ -166,12 +174,9 @@ static inline bool should_skip_covered(v static u32 get_alloc_stack_hash(unsigned long *stack_entries, size_t num_entries) { - /* Some randomness across reboots / different machines. */ - u32 seed = (u32)((unsigned long)__kfence_pool >> (BITS_PER_LONG - 32)); - num_entries = min(num_entries, UNIQUE_ALLOC_STACK_DEPTH); num_entries = filter_irq_stacks(stack_entries, num_entries); - return jhash(stack_entries, num_entries * sizeof(stack_entries[0]), seed); + return jhash(stack_entries, num_entries * sizeof(stack_entries[0]), stack_hash_seed); } /* @@ -759,6 +764,7 @@ void __init kfence_init(void) if (!kfence_sample_interval) return; + stack_hash_seed = (u32)random_get_entropy(); if (!kfence_init_pool()) { pr_err("%s failed\n", __func__); return; _ Patches currently in -mm which might be from elver@xxxxxxxxxx are lib-stackdepot-include-gfph.patch lib-stackdepot-remove-unused-function-argument.patch lib-stackdepot-introduce-__stack_depot_save.patch kasan-common-provide-can_alloc-in-kasan_save_stack.patch kasan-generic-introduce-kasan_record_aux_stack_noalloc.patch workqueue-kasan-avoid-alloc_pages-when-recording-stack.patch mm-fix-data-race-in-pagepoisoned.patch stacktrace-move-filter_irq_stacks-to-kernel-stacktracec.patch kfence-count-unexpectedly-skipped-allocations.patch kfence-move-saving-stack-trace-of-allocations-into-__kfence_alloc.patch kfence-limit-currently-covered-allocations-when-pool-nearly-full.patch kfence-limit-currently-covered-allocations-when-pool-nearly-full-fix-fix.patch kfence-add-note-to-documentation-about-skipping-covered-allocations.patch kfence-test-use-kunit_skip-to-skip-tests.patch kfence-shorten-critical-sections-of-alloc-free.patch kfence-always-use-static-branches-to-guard-kfence_alloc.patch kfence-default-to-dynamic-branch-instead-of-static-keys-mode.patch