linux-stable/mm/kasan
Andrey Konovalov 63b85ac56a kasan: stop leaking stack trace handles
Commit 773688a6cb ("kasan: use stack_depot_put for Generic mode") added
support for stack trace eviction for Generic KASAN.

However, that commit didn't evict stack traces when the object is not put
into quarantine.  As a result, some stack traces are never evicted from
the stack depot.

In addition, with the "kasan: save mempool stack traces" series, the free
stack traces for mempool objects are also not properly evicted from the
stack depot.

Fix both issues by:

1. Evicting all stack traces when an object if freed if it was not put
   into quarantine;

2. Always evicting an existing free stack trace when a new one is saved.

Also do a few related clean-ups:

- Do not zero out free track when initializing/invalidating free meta:
  set a value in shadow memory instead;

- Rename KASAN_SLAB_FREETRACK to KASAN_SLAB_FREE_META;

- Drop the kasan_init_cache_meta function as it's not used by KASAN;

- Add comments for the kasan_alloc_meta and kasan_free_meta structs.

[akpm@linux-foundation.org: make release_free_meta() and release_alloc_meta() static]
Link: https://lkml.kernel.org/r/20231226225121.235865-1-andrey.konovalov@linux.dev
Fixes: 773688a6cb ("kasan: use stack_depot_put for Generic mode")
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-01-05 10:17:45 -08:00
..
common.c kasan: stop leaking stack trace handles 2024-01-05 10:17:45 -08:00
generic.c kasan: stop leaking stack trace handles 2024-01-05 10:17:45 -08:00
hw_tags.c kasan: check kasan_vmalloc_enabled in vmalloc tests 2023-12-29 11:58:45 -08:00
init.c kasan: Add (pmd|pud)_init for LoongArch zero_(pud|p4d)_populate process 2023-09-06 22:54:16 +08:00
kasan.h kasan: stop leaking stack trace handles 2024-01-05 10:17:45 -08:00
kasan_test.c kasan: speed up match_all_mem_tag test for SW_TAGS 2023-12-29 11:58:46 -08:00
kasan_test_module.c kasan: unify printk prefixes 2023-10-18 14:34:15 -07:00
Makefile kasan: test: fix test for new meminstrinsic instrumentation 2023-03-02 21:54:22 -08:00
quarantine.c kasan: stop leaking stack trace handles 2024-01-05 10:17:45 -08:00
report.c kasan: improve kasan_non_canonical_hook 2023-12-29 11:58:44 -08:00
report_generic.c kasan: stop leaking stack trace handles 2024-01-05 10:17:45 -08:00
report_hw_tags.c kasan: use internal prototypes matching gcc-13 builtins 2023-06-09 16:25:19 -07:00
report_sw_tags.c kasan: use internal prototypes matching gcc-13 builtins 2023-06-09 16:25:19 -07:00
report_tags.c kasan: simplify kasan_complete_mode_report_info for tag-based modes 2023-12-29 11:58:47 -08:00
shadow.c kasan: export kasan_poison as GPL 2023-12-29 11:58:45 -08:00
sw_tags.c kasan: use internal prototypes matching gcc-13 builtins 2023-06-09 16:25:19 -07:00
tags.c kasan: simplify saving extra info into tracks 2023-12-29 11:58:46 -08:00