Re: [PATCH v2] x86/kprobes: Fix 1 byte conditional jump target
From: Peter Zijlstra
Date: Wed Feb 08 2023 - 15:01:42 EST
On Wed, Feb 08, 2023 at 07:17:08AM +0000, Nadav Amit wrote:
> From: Nadav Amit <namit@xxxxxxxxxx>
>
> 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 and instead
> zero-extended.
>
> In fact, there is no need for any casting of immediate.value since sign
> extension is already done during its decoding in insn_get_immediate().
>
> Fix by removing the casting of the 1 byte conditional jump target.
> Future patches can also remove the casting (and sign extension) in other
> cases in which immediate.value is being used.
>
> Fixes: 3bc753c06dd0 ("kbuild: treat char as always unsigned")
> Suggested-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
> Suggested-by: Dave Hansen <dave.hansen@xxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Signed-off-by: Nadav Amit <namit@xxxxxxxxxx>
Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>