Skip to content

Commit 31fa985

Browse files
qiangzh3torvalds
authored andcommitted
kasan: prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time
kasan_quarantine_remove_cache() is called in kmem_cache_shrink()/ destroy(). The kasan_quarantine_remove_cache() call is protected by cpuslock in kmem_cache_destroy() to ensure serialization with kasan_cpu_offline(). However the kasan_quarantine_remove_cache() call is not protected by cpuslock in kmem_cache_shrink(). When a CPU is going offline and cache shrink occurs at same time, the cpu_quarantine may be corrupted by interrupt (per_cpu_remove_cache operation). So add a cpu_quarantine offline flags check in per_cpu_remove_cache(). [[email protected]: add comment, per Zqiang] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Zqiang <[email protected]> Reviewed-by: Dmitry Vyukov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d615b54 commit 31fa985

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mm/kasan/quarantine.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ static void per_cpu_remove_cache(void *arg)
315315
struct qlist_head *q;
316316

317317
q = this_cpu_ptr(&cpu_quarantine);
318+
/*
319+
* Ensure the ordering between the writing to q->offline and
320+
* per_cpu_remove_cache. Prevent cpu_quarantine from being corrupted
321+
* by interrupt.
322+
*/
323+
if (READ_ONCE(q->offline))
324+
return;
318325
qlist_move_cache(q, &to_free, cache);
319326
qlist_free_all(&to_free, cache);
320327
}

0 commit comments

Comments
 (0)