From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Peter Collingbourne <pcc@google.com>,
Sasha Levin <sashal@kernel.org>,
pasha.tatashin@soleen.com, wangxiang@cdjrlc.com,
keescook@chromium.org, broonie@kernel.org,
wangkefeng.wang@huawei.com, mark.rutland@arm.com,
tongtiangen@huawei.com, luis.machado@linaro.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH AUTOSEL 5.19 13/58] arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags"
Date: Sun, 7 Aug 2022 21:30:31 -0400 [thread overview]
Message-ID: <20220808013118.313965-13-sashal@kernel.org> (raw)
In-Reply-To: <20220808013118.313965-1-sashal@kernel.org>
From: Catalin Marinas <catalin.marinas@arm.com>
[ Upstream commit 20794545c14692094a882d2221c251c4573e6adf ]
This reverts commit e5b8d9218951e59df986f627ec93569a0d22149b.
Pages mapped in user-space with PROT_MTE have the allocation tags either
zeroed or copied/restored to some user values. In order for the kernel
to access such pages via page_address(), resetting the tag in
page->flags was necessary. This tag resetting was deferred to
set_pte_at() -> mte_sync_page_tags() but it can race with another CPU
reading the flags (via page_to_virt()):
P0 (mte_sync_page_tags): P1 (memcpy from virt_to_page):
Rflags!=0xff
Wflags=0xff
DMB (doesn't help)
Wtags=0
Rtags=0 // fault
Since now the post_alloc_hook() function resets the page->flags tag when
unpoisoning is skipped for user pages (including the __GFP_ZEROTAGS
case), revert the arm64 commit calling page_kasan_tag_reset().
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Peter Collingbourne <pcc@google.com>
Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Acked-by: Andrey Konovalov <andreyknvl@gmail.com>
Link: https://lore.kernel.org/r/20220610152141.2148929-5-catalin.marinas@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/arm64/kernel/hibernate.c | 5 -----
arch/arm64/kernel/mte.c | 9 ---------
arch/arm64/mm/copypage.c | 9 ---------
arch/arm64/mm/mteswap.c | 9 ---------
4 files changed, 32 deletions(-)
diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
index 2e248342476e..af5df48ba915 100644
--- a/arch/arm64/kernel/hibernate.c
+++ b/arch/arm64/kernel/hibernate.c
@@ -300,11 +300,6 @@ static void swsusp_mte_restore_tags(void)
unsigned long pfn = xa_state.xa_index;
struct page *page = pfn_to_online_page(pfn);
- /*
- * It is not required to invoke page_kasan_tag_reset(page)
- * at this point since the tags stored in page->flags are
- * already restored.
- */
mte_restore_page_tags(page_address(page), tags);
mte_free_tag_storage(tags);
diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
index f6b00743c399..b2b730233274 100644
--- a/arch/arm64/kernel/mte.c
+++ b/arch/arm64/kernel/mte.c
@@ -48,15 +48,6 @@ static void mte_sync_page_tags(struct page *page, pte_t old_pte,
if (!pte_is_tagged)
return;
- page_kasan_tag_reset(page);
- /*
- * We need smp_wmb() in between setting the flags and clearing the
- * tags because if another thread reads page->flags and builds a
- * tagged address out of it, there is an actual dependency to the
- * memory access, but on the current thread we do not guarantee that
- * the new page->flags are visible before the tags were updated.
- */
- smp_wmb();
mte_clear_page_tags(page_address(page));
}
diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c
index 0dea80bf6de4..24913271e898 100644
--- a/arch/arm64/mm/copypage.c
+++ b/arch/arm64/mm/copypage.c
@@ -23,15 +23,6 @@ void copy_highpage(struct page *to, struct page *from)
if (system_supports_mte() && test_bit(PG_mte_tagged, &from->flags)) {
set_bit(PG_mte_tagged, &to->flags);
- page_kasan_tag_reset(to);
- /*
- * We need smp_wmb() in between setting the flags and clearing the
- * tags because if another thread reads page->flags and builds a
- * tagged address out of it, there is an actual dependency to the
- * memory access, but on the current thread we do not guarantee that
- * the new page->flags are visible before the tags were updated.
- */
- smp_wmb();
mte_copy_page_tags(kto, kfrom);
}
}
diff --git a/arch/arm64/mm/mteswap.c b/arch/arm64/mm/mteswap.c
index a9e50e930484..4334dec93bd4 100644
--- a/arch/arm64/mm/mteswap.c
+++ b/arch/arm64/mm/mteswap.c
@@ -53,15 +53,6 @@ bool mte_restore_tags(swp_entry_t entry, struct page *page)
if (!tags)
return false;
- page_kasan_tag_reset(page);
- /*
- * We need smp_wmb() in between setting the flags and clearing the
- * tags because if another thread reads page->flags and builds a
- * tagged address out of it, there is an actual dependency to the
- * memory access, but on the current thread we do not guarantee that
- * the new page->flags are visible before the tags were updated.
- */
- smp_wmb();
mte_restore_page_tags(page_address(page), tags);
return true;
--
2.35.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-08-08 1:35 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220808013118.313965-1-sashal@kernel.org>
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 03/58] arm64: kasan: do not instrument stacktrace.c Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 04/58] arm64: stacktrace: use non-atomic __set_bit Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 05/58] arm64: kernel: drop unnecessary PoC cache clean+invalidate Sasha Levin
2022-08-08 9:05 ` Ard Biesheuvel
2022-08-09 14:01 ` Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 06/58] arm64: mm: provide idmap pointer to cpu_replace_ttbr1() Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 07/58] arm64: kaslr: defer initialization to initcall where permitted Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 08/58] arm64: Do not forget syscall when starting a new thread Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 09/58] arm64: fix oops in concurrently setting insn_emulation sysctls Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 11/58] mm: kasan: Skip unpoisoning of user pages Sasha Levin
2022-08-08 1:30 ` Sasha Levin [this message]
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 14/58] arm64: errata: Remove AES hwcap for COMPAT tasks Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 23/58] ARM: dts: imx6ul: add missing properties for sram Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 24/58] ARM: dts: imx6ul: change operating-points to uint32-matrix Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 25/58] ARM: dts: imx6ul: fix keypad compatible Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 26/58] ARM: dts: imx6ul: fix csi node compatible Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 27/58] ARM: dts: imx6ul: fix lcdif " Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 28/58] ARM: dts: imx6ul: fix qspi " Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 29/58] ARM: dts: BCM5301X: Add DT for Meraki MR26 Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 30/58] ARM: dts: ux500: Fix Janice accelerometer mounting matrix Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 31/58] ARM: dts: ux500: Fix Codina " Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 32/58] ARM: dts: ux500: Fix Gavini " Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 35/58] ARM: OMAP2+: display: Fix refcount leak bug Sasha Levin
2022-08-08 1:30 ` [PATCH AUTOSEL 5.19 36/58] ARM: OMAP2+: pdata-quirks: " Sasha Levin
2022-08-08 1:31 ` [PATCH AUTOSEL 5.19 45/58] arm64: dts: allwinner: a64: orangepi-win: Fix LED node name Sasha Levin
2022-08-08 1:31 ` [PATCH AUTOSEL 5.19 46/58] ARM: shmobile: rcar-gen2: Increase refcount for new reference Sasha Levin
2022-08-08 1:31 ` [PATCH AUTOSEL 5.19 49/58] PM: EM: convert power field to micro-Watts precision and align drivers Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220808013118.313965-13-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andreyknvl@gmail.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luis.machado@linaro.org \
--cc=mark.rutland@arm.com \
--cc=pasha.tatashin@soleen.com \
--cc=pcc@google.com \
--cc=stable@vger.kernel.org \
--cc=tongtiangen@huawei.com \
--cc=vincenzo.frascino@arm.com \
--cc=wangkefeng.wang@huawei.com \
--cc=wangxiang@cdjrlc.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).