Re: [PATCH] x86/kprobes: Fix 1 byte conditional jump target

From: Dave Hansen
Date: Mon Feb 06 2023 - 13:42:36 EST


On 2/4/23 13:08, Nadav Amit wrote:
> --- 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;

This new code is at least consistent with what the other code in that
function does with 1-byte immediates. But, I'm curious what the point
is about going through the 's8' type.

What's wrong with:

p->ainsn.rel32 = insn->immediate.value;

? Am I missing something subtle?