From: Xie Yuanbin <xieyuanbin1@huawei.com>
To: <linux@armlinux.org.uk>, <rmk+kernel@armlinux.org.uk>,
<kees@kernel.org>, <yangyj.ee@gmail.com>, <ardb@kernel.org>,
<tony@atomide.com>, <xieyuanbin1@huawei.com>
Cc: <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <will@kernel.org>,
<nixiaoming@huawei.com>, <liaohua4@huawei.com>,
<wangbing6@huawei.com>, <lilinjie8@huawei.com>,
<wangfangpeng1@huawei.com>
Subject: [RFC RESEND PATCH] ARM: spectre-v2: fix the spectre operation that may be bypassed
Date: Fri, 6 Jun 2025 09:43:35 +0800 [thread overview]
Message-ID: <20250606014335.1772-1-xieyuanbin1@huawei.com> (raw)
In-Reply-To: <20250424100437.27477-1-xieyuanbin1@huawei.com>
As discussed before, to completely fix this problem, we must do
the spectre operation after the user mode is trapped in the kernel
and before the interrupt is enabled.
I have tried to add a hook function and it in fsr_info to avoid
performance deterioration (The preceding example will trigger
"level 2 permission fault", which is cold code in normal cases).
However, this does not work. I find that the user program can
also trigger "translation fault" or "access flag fault"
when accessing a kernel address.
Therefore, extra performance overhead is inevitable.
(An if branch needs to be added before the interrupt is enabled.)
I have tried to reduce the impact on performance.
If the page fault comes from the user mode,
the interrupt must be enabled. In this case,
a judgment can be reduced.
Fixes: f5fe12b1eaee ("ARM: spectre-v2: harden user aborts in kernel space")
Signed-off-by: Xie Yuanbin <xieyuanbin1@huawei.com>
---
arch/arm/mm/fault.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
index ab01b51de559..3425a12a8f52 100644
--- a/arch/arm/mm/fault.c
+++ b/arch/arm/mm/fault.c
@@ -272,25 +272,35 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
if (kprobe_page_fault(regs, fsr))
return 0;
/* Enable interrupts if they were enabled in the parent context. */
- if (interrupts_enabled(regs))
- local_irq_enable();
+ if (likely(user_mode(regs))) {
+ if (IS_ENABLED(CONFIG_PREEMPT) &&
+ IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR) &&
+ unlikely(addr >= TASK_SIZE)) {
+
+ __do_user_fault(addr, fsr, SIGSEGV, SEGV_MAPERR, regs);
+ return 0;
+ }
+
+ flags |= FAULT_FLAG_USER;
+ } else if (!interrupts_enabled(regs))
+ goto irq_disabled;
+
+ local_irq_enable();
+irq_disabled:
/*
* If we're in an interrupt or have no user
* context, we must not take the fault..
*/
if (faulthandler_disabled() || !mm)
goto no_context;
- if (user_mode(regs))
- flags |= FAULT_FLAG_USER;
-
if (is_write_fault(fsr)) {
flags |= FAULT_FLAG_WRITE;
vm_flags = VM_WRITE;
}
if (fsr & FSR_LNX_PF) {
--
2.48.1
prev parent reply other threads:[~2025-06-06 1:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 10:04 [PATCH] ARM: spectre-v2: fix unstable cpu get xieyuanbin1
2025-04-24 10:21 ` Russell King (Oracle)
2025-04-24 13:31 ` xieyuanbin1
2025-04-24 13:50 ` Russell King (Oracle)
2025-04-24 14:03 ` xieyuanbin1
2025-05-07 12:28 ` [RFC PATCH] ARM: spectre-v2: fix the spectre operation that may be bypassed Xie Yuanbin
2025-06-06 1:43 ` Xie Yuanbin [this message]
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=20250606014335.1772-1-xieyuanbin1@huawei.com \
--to=xieyuanbin1@huawei.com \
--cc=ardb@kernel.org \
--cc=kees@kernel.org \
--cc=liaohua4@huawei.com \
--cc=lilinjie8@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=nixiaoming@huawei.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=tony@atomide.com \
--cc=wangbing6@huawei.com \
--cc=wangfangpeng1@huawei.com \
--cc=will@kernel.org \
--cc=yangyj.ee@gmail.com \
/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
all inboxes | Powered by JetHome®