Skip to content

Commit 8924779

Browse files
anadavIngo Molnar
authored andcommitted
x86/kprobes: Fix JNG/JNLE emulation
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: 6256e66 ("x86/kprobes: Use int3 instead of debug trap for single-step") Signed-off-by: Nadav Amit <namit@vmware.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220813225943.143767-1-namit@vmware.com
1 parent ffcf9c5 commit 8924779

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/x86/kernel/kprobes/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static void kprobe_emulate_jcc(struct kprobe *p, struct pt_regs *regs)
505505
match = ((regs->flags & X86_EFLAGS_SF) >> X86_EFLAGS_SF_BIT) ^
506506
((regs->flags & X86_EFLAGS_OF) >> X86_EFLAGS_OF_BIT);
507507
if (p->ainsn.jcc.type >= 0xe)
508-
match = match && (regs->flags & X86_EFLAGS_ZF);
508+
match = match || (regs->flags & X86_EFLAGS_ZF);
509509
}
510510
__kprobe_emulate_jmp(p, regs, (match && !invert) || (!match && invert));
511511
}

0 commit comments

Comments
 (0)