* [PATCH v2] x86/kprobes: Fix 1 byte conditional jump target
@ 2023-02-08 7:17 Nadav Amit
2023-02-08 20:01 ` Peter Zijlstra
2023-02-09 14:24 ` Masami Hiramatsu
0 siblings, 2 replies; 3+ messages in thread
From: Nadav Amit @ 2023-02-08 7:17 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Ingo Molnar, Borislav Petkov, Dave Hansen, x86, linux-kernel,
Nadav Amit, Masami Hiramatsu, Dave Hansen, 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 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@kernel.org>
Suggested-by: Dave Hansen <dave.hansen@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Nadav Amit <namit@vmware.com>
---
v1->v2: Removing the casting completely [Dave]
---
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..695873c0f50b 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 = insn->immediate.value;
break;
case 0x0f:
opcode = insn->opcode.bytes[1];
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] x86/kprobes: Fix 1 byte conditional jump target
2023-02-08 7:17 [PATCH v2] x86/kprobes: Fix 1 byte conditional jump target Nadav Amit
@ 2023-02-08 20:01 ` Peter Zijlstra
2023-02-09 14:24 ` Masami Hiramatsu
1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2023-02-08 20:01 UTC (permalink / raw)
To: Nadav Amit
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
linux-kernel, Nadav Amit, Masami Hiramatsu, Dave Hansen
On Wed, Feb 08, 2023 at 07:17:08AM +0000, Nadav Amit wrote:
> 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 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@kernel.org>
> Suggested-by: Dave Hansen <dave.hansen@intel.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Nadav Amit <namit@vmware.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] x86/kprobes: Fix 1 byte conditional jump target
2023-02-08 7:17 [PATCH v2] x86/kprobes: Fix 1 byte conditional jump target Nadav Amit
2023-02-08 20:01 ` Peter Zijlstra
@ 2023-02-09 14:24 ` Masami Hiramatsu
1 sibling, 0 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2023-02-09 14:24 UTC (permalink / raw)
To: Nadav Amit
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
linux-kernel, Nadav Amit, Masami Hiramatsu, Dave Hansen,
Peter Zijlstra
On Wed, 8 Feb 2023 07:17:08 +0000
Nadav Amit <nadav.amit@gmail.com> wrote:
> 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 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@kernel.org>
> Suggested-by: Dave Hansen <dave.hansen@intel.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Nadav Amit <namit@vmware.com>
Thanks, looks good to me.
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
> ---
>
> v1->v2: Removing the casting completely [Dave]
> ---
> 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..695873c0f50b 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 = insn->immediate.value;
> break;
> case 0x0f:
> opcode = insn->opcode.bytes[1];
> --
> 2.34.1
>
Nadav
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-09 14:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-08 7:17 [PATCH v2] x86/kprobes: Fix 1 byte conditional jump target Nadav Amit
2023-02-08 20:01 ` Peter Zijlstra
2023-02-09 14:24 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).