FAILED: patch "[PATCH] mm, kasan: use compare-exchange operation to set KASAN page" failed to apply to 5.4-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 27fe73394a1c6d0b07fa4d95f1bca116d1cc66e9 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <[email protected]>
Date: Sat, 29 Jan 2022 13:41:14 -0800
Subject: [PATCH] mm, kasan: use compare-exchange operation to set KASAN page
tag
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.
include/linux/mm.h +12 -5
@@ -1506,11 +1506,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)