diff options
author | Peter Collingbourne <pcc@google.com> | 2022-01-29 13:41:14 -0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-02-01 17:29:08 +0100 |
commit | dd22253c13d2795c566f52c30f1dba48d51c482d (patch) | |
tree | 88327efdb3d06c278f5b25fcced084c664688cc2 /include/linux | |
parent | 1cd8a5d24477c308c9e6f3bb1a8ce61fca1ed411 (diff) | |
download | linux-stable-dd22253c13d2795c566f52c30f1dba48d51c482d.tar.gz linux-stable-dd22253c13d2795c566f52c30f1dba48d51c482d.tar.bz2 linux-stable-dd22253c13d2795c566f52c30f1dba48d51c482d.zip |
mm, kasan: use compare-exchange operation to set KASAN page tag
commit 27fe73394a1c6d0b07fa4d95f1bca116d1cc66e9 upstream.
It has been reported that the tag setting operation on newly-allocated
pages can cause the page flags to be corrupted when performed
concurrently with other flag updates as a result of the use of
non-atomic operations.
Fix the problem by using a compare-exchange loop to update the tag.
Link: https://lkml.kernel.org/r/20220120020148.1632253-1-pcc@google.com
Link: https://linux-review.googlesource.com/id/I456b24a2b9067d93968d43b4bb3351c0cec63101
Fixes: 2813b9c02962 ("kasan, mm, arm64: tag non slab memory allocated via pagealloc")
Signed-off-by: Peter Collingbourne <pcc@google.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/mm.h | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h index a7e4a9e7d807..73210623bda7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1524,11 +1524,18 @@ static inline u8 page_kasan_tag(const struct page *page) static inline void page_kasan_tag_set(struct page *page, u8 tag) { - if (kasan_enabled()) { - tag ^= 0xff; - page->flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT); - page->flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT; - } + unsigned long old_flags, flags; + + if (!kasan_enabled()) + return; + + tag ^= 0xff; + old_flags = READ_ONCE(page->flags); + do { + flags = old_flags; + flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT); + flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT; + } while (unlikely(!try_cmpxchg(&page->flags, &old_flags, flags))); } static inline void page_kasan_tag_reset(struct page *page) |