From: Peter Zijlstra <peterz@infradead.org>
To: Nadav Amit <nadav.amit@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Nadav Amit <namit@vmware.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Andy Lutomirski <luto@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH] x86/kprobes: fix JNG/JNLE emulation
Date: Mon, 15 Aug 2022 09:29:20 +0200 [thread overview]
Message-ID: <Yvn10AjTCHM+ua9E@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <20220813225943.143767-1-namit@vmware.com>
On Sat, Aug 13, 2022 at 03:59:43PM -0700, Nadav Amit wrote:
> From: Nadav Amit <namit@vmware.com>
>
> 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'.
>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: stable@vger.kernel.org
> Fixes: 6256e668b7af ("x86/kprobes: Use int3 instead of debug trap for single-step")
> Signed-off-by: Nadav Amit <namit@vmware.com>
Urgghh..
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> 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 74167dc5f55e..4c3c27b6aea3 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.25.1
>
next prev parent reply other threads:[~2022-08-15 7:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-13 22:59 Nadav Amit
2022-08-15 7:29 ` Peter Zijlstra [this message]
2022-08-15 8:48 ` [tip: perf/urgent] x86/kprobes: Fix " tip-bot2 for Nadav Amit
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=Yvn10AjTCHM+ua9E@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=namit@vmware.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@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
all inboxes | Powered by JetHome®