]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
34da96ff6805ccd46bf91fc4ad62fa0989f36aac
[thirdparty/kernel/stable-queue.git] /
1 From 31fa985b4196f8a66f027672e9bf2b81fea0417c Mon Sep 17 00:00:00 2001
2 From: Zqiang <qiang1.zhang@intel.com>
3 Date: Wed, 27 Apr 2022 12:41:56 -0700
4 Subject: kasan: prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time
5
6 From: Zqiang <qiang1.zhang@intel.com>
7
8 commit 31fa985b4196f8a66f027672e9bf2b81fea0417c upstream.
9
10 kasan_quarantine_remove_cache() is called in kmem_cache_shrink()/
11 destroy(). The kasan_quarantine_remove_cache() call is protected by
12 cpuslock in kmem_cache_destroy() to ensure serialization with
13 kasan_cpu_offline().
14
15 However the kasan_quarantine_remove_cache() call is not protected by
16 cpuslock in kmem_cache_shrink(). When a CPU is going offline and cache
17 shrink occurs at same time, the cpu_quarantine may be corrupted by
18 interrupt (per_cpu_remove_cache operation).
19
20 So add a cpu_quarantine offline flags check in per_cpu_remove_cache().
21
22 [akpm@linux-foundation.org: add comment, per Zqiang]
23
24 Link: https://lkml.kernel.org/r/20220414025925.2423818-1-qiang1.zhang@intel.com
25 Signed-off-by: Zqiang <qiang1.zhang@intel.com>
26 Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
27 Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
28 Cc: Alexander Potapenko <glider@google.com>
29 Cc: Andrey Konovalov <andreyknvl@gmail.com>
30 Cc: <stable@vger.kernel.org>
31 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
32 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
33 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
34 ---
35 mm/kasan/quarantine.c | 7 +++++++
36 1 file changed, 7 insertions(+)
37
38 --- a/mm/kasan/quarantine.c
39 +++ b/mm/kasan/quarantine.c
40 @@ -299,6 +299,13 @@ static void per_cpu_remove_cache(void *a
41 struct qlist_head *q;
42
43 q = this_cpu_ptr(&cpu_quarantine);
44 + /*
45 + * Ensure the ordering between the writing to q->offline and
46 + * per_cpu_remove_cache. Prevent cpu_quarantine from being corrupted
47 + * by interrupt.
48 + */
49 + if (READ_ONCE(q->offline))
50 + return;
51 qlist_move_cache(q, &to_free, cache);
52 qlist_free_all(&to_free, cache);
53 }