[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230705064653.226811-10-lihuafei1@huawei.com>
Date: Wed, 5 Jul 2023 14:46:53 +0800
From: Li Huafei <lihuafei1@...wei.com>
To: <stable@...r.kernel.org>
CC: <gregkh@...uxfoundation.org>, <mhiramat@...nel.org>,
<tglx@...utronix.de>, <mingo@...hat.com>, <bp@...en8.de>,
<x86@...nel.org>, <hpa@...or.com>, <sashal@...nel.org>,
<peterz@...radead.org>, <linux-kernel@...r.kernel.org>,
<xukuohai@...wei.com>, <natechancellor@...il.com>,
<ndesaulniers@...gle.com>, <rostedt@...dmis.org>,
<weiyongjun1@...wei.com>, <gustavoars@...nel.org>,
<namit@...are.com>, <laijs@...ux.alibaba.com>,
<clang-built-linux@...glegroups.com>, <lihuafei1@...wei.com>
Subject: [PATCH 5.10 9/9] x86/kprobes: Fix JNG/JNLE emulation
From: Nadav Amit <namit@...are.com>
[ Upstream commit 8924779df820c53875abaeb10c648e9cb75b46d4 ]
When kprobes emulates JNG/JNLE instructions on x86 it uses the wrong
condition. For JNG (opcode: 0F 8E), according to Intel SDM, the jump is
performed if (ZF == 1 or SF != OF). However the kernel emulation
currently uses 'and' instead of 'or'.
As a result, setting a kprobe on JNG/JNLE might cause the kernel to
behave incorrectly whenever the kprobe is hit.
Fix by changing the 'and' to 'or'.
Fixes: 6256e668b7af ("x86/kprobes: Use int3 instead of debug trap for single-step")
Signed-off-by: Nadav Amit <namit@...are.com>
Signed-off-by: Ingo Molnar <mingo@...nel.org>
Cc: stable@...r.kernel.org
Link: https://lore.kernel.org/r/20220813225943.143767-1-namit@vmware.com
Signed-off-by: Li Huafei <lihuafei1@...wei.com>
---
arch/x86/kernel/kprobes/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index bde43592f54a..c78b4946385e 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -505,7 +505,7 @@ static void kprobe_emulate_jcc(struct kprobe *p, struct pt_regs *regs)
match = ((regs->flags & X86_EFLAGS_SF) >> X86_EFLAGS_SF_BIT) ^
((regs->flags & X86_EFLAGS_OF) >> X86_EFLAGS_OF_BIT);
if (p->ainsn.jcc.type >= 0xe)
- match = match && (regs->flags & X86_EFLAGS_ZF);
+ match = match || (regs->flags & X86_EFLAGS_ZF);
}
__kprobe_emulate_jmp(p, regs, (match && !invert) || (!match && invert));
}
--
2.17.1
Powered by blists - more mailing lists