All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/kprobes: Fix 1 byte conditional jump target
@ 2023-02-04 21:08 Nadav Amit
  2023-02-05  7:49 ` Nadav Amit
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Nadav Amit @ 2023-02-04 21:08 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Ingo Molnar, Borislav Petkov, Dave Hansen, x86, linux-kernel,
	Nadav Amit, Masami Hiramatsu, Peter Zijlstra

From: Nadav Amit <namit@vmware.com>

Commit 3bc753c06dd0 ("kbuild: treat char as always unsigned") broke
kprobes.  Setting a probe-point on 1 byte conditional jump can cause the
kernel to crash, as the branch target is not sign extended.

Fix by using s8 instead of char and use immediate.value instead of
immediate.bytes for consistency.

Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Nadav Amit <namit@vmware.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 b36f3c367cb2..6a56d56b3817 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -625,7 +625,7 @@ static int prepare_emulation(struct kprobe *p, struct insn *insn)
 		/* 1 byte conditional jump */
 		p->ainsn.emulate_op = kprobe_emulate_jcc;
 		p->ainsn.jcc.type = opcode & 0xf;
-		p->ainsn.rel32 = *(char *)insn->immediate.bytes;
+		p->ainsn.rel32 = *(s8 *)&insn->immediate.value;
 		break;
 	case 0x0f:
 		opcode = insn->opcode.bytes[1];
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-02-08  7:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-04 21:08 [PATCH] x86/kprobes: Fix 1 byte conditional jump target Nadav Amit
2023-02-05  7:49 ` Nadav Amit
2023-02-06 14:19   ` Masami Hiramatsu
2023-02-06 14:18 ` Masami Hiramatsu
2023-02-06 18:42 ` Dave Hansen
2023-02-06 19:05   ` Nadav Amit
2023-02-06 22:38     ` Dave Hansen
2023-02-07  0:54       ` Masami Hiramatsu
2023-02-07 15:21         ` Masami Hiramatsu
2023-02-07 15:33           ` Dave Hansen
2023-02-08  6:34             ` Nadav Amit
2023-02-08  6:56               ` Dave Hansen
2023-02-08  6:58                 ` Nadav Amit

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.