Skip to content

Commit e940066

Browse files
melvertorvalds
authored andcommitted
lib/stackdepot: always do filter_irq_stacks() in stack_depot_save()
The non-interrupt portion of interrupt stack traces before interrupt entry is usually arbitrary. Therefore, saving stack traces of interrupts (that include entries before interrupt entry) to stack depot leads to unbounded stackdepot growth. As such, use of filter_irq_stacks() is a requirement to ensure stackdepot can efficiently deduplicate interrupt stacks. Looking through all current users of stack_depot_save(), none (except KASAN) pass the stack trace through filter_irq_stacks() before passing it on to stack_depot_save(). Rather than adding filter_irq_stacks() to all current users of stack_depot_save(), it became clear that stack_depot_save() should simply do filter_irq_stacks(). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Marco Elver <[email protected]> Reviewed-by: Alexander Potapenko <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Reviewed-by: Andrey Konovalov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Vijayanand Jitta <[email protected]> Cc: "Gustavo A. R. Silva" <[email protected]> Cc: Imran Khan <[email protected]> Cc: Chris Wilson <[email protected]> Cc: Jani Nikula <[email protected]> Cc: Mika Kuoppala <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 2dba5eb commit e940066

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/stackdepot.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ EXPORT_SYMBOL_GPL(stack_depot_fetch);
328328
* (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids
329329
* any allocations and will fail if no space is left to store the stack trace.
330330
*
331+
* If the stack trace in @entries is from an interrupt, only the portion up to
332+
* interrupt entry is saved.
333+
*
331334
* Context: Any context, but setting @can_alloc to %false is required if
332335
* alloc_pages() cannot be used from the current context. Currently
333336
* this is the case from contexts where neither %GFP_ATOMIC nor
@@ -346,6 +349,16 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries,
346349
unsigned long flags;
347350
u32 hash;
348351

352+
/*
353+
* If this stack trace is from an interrupt, including anything before
354+
* interrupt entry usually leads to unbounded stackdepot growth.
355+
*
356+
* Because use of filter_irq_stacks() is a requirement to ensure
357+
* stackdepot can efficiently deduplicate interrupt stacks, always
358+
* filter_irq_stacks() to simplify all callers' use of stackdepot.
359+
*/
360+
nr_entries = filter_irq_stacks(entries, nr_entries);
361+
349362
if (unlikely(nr_entries == 0) || stack_depot_disable)
350363
goto fast_exit;
351364

mm/kasan/common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc)
3636
unsigned int nr_entries;
3737

3838
nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
39-
nr_entries = filter_irq_stacks(entries, nr_entries);
4039
return __stack_depot_save(entries, nr_entries, flags, can_alloc);
4140
}
4241

0 commit comments

Comments
 (0)