Re: [RESEND PATCH v2] x86/kprobes: Fix boundary check in insn_jump_into_range()
From: Masami Hiramatsu (Google)
Date: Sat Dec 05 2026 - 04:50:17 EST
Hi,
On Fri, 4 Dec 2026 13:17:04 +0800, Jinke Han <jinkehan@xxxxxxxxxxxxxx> wrote:
> The range checked by insn_jump_into_range() is half-open:
> [start, start + len). However, the current check treats the upper
> bound as inclusive, so a jump target at `probe address +
> JMP32_INSN_SIZE` is incorrectly considered to jump into the
> optimized region.
>
> A valid jump target must be an instruction boundary. A target at
> `probe address + JMP32_INSN_SIZE` lies just outside the overwritten
> region, so allow the jmp optimization in this case.
>
> For example, with a kprobe at queued_spin_lock_slowpath+17, the
> optimized region covers queued_spin_lock_slowpath+17..+21, and the
> next instruction boundary is queued_spin_lock_slowpath+22. A branch
> target at queued_spin_lock_slowpath+22 is therefore outside the
> half-open range [probe, probe + JMP32_INSN_SIZE).
>
> Before this patch, the kprobe falls back to an int3 kprobe because
> the boundary target is wrongly considered to be inside the range:
>
> 0xffffffff823ebdff <queued_spin_lock_slowpath+15>: xchg %ax,%ax
> 0xffffffff823ebe01 <queued_spin_lock_slowpath+17>: int3
> 0xffffffff823ebe02 <queued_spin_lock_slowpath+18>: add %eax,(%rax)
> 0xffffffff823ebe04 <queued_spin_lock_slowpath+20>: add %al,(%rax)
> 0xffffffff823ebe06 <queued_spin_lock_slowpath+22>: mov 0x0(%rbp),%eax
>
> With this patch, jump optimization can be used:
>
> 0xffffffff823ebdff <queued_spin_lock_slowpath+15>: xchg %ax,%ax
> 0xffffffff823ebe01 <queued_spin_lock_slowpath+17>: jmp 0xffffffffc0401000
> 0xffffffff823ebe06 <queued_spin_lock_slowpath+22>: mov 0x0(%rbp),%eax
>
> Fixes: c0f7ac3a9edde ("kprobes/x86: Support kprobes jump optimization on x86")
> Signed-off-by: Jinke Han <jinkehan@xxxxxxxxxxxxxx>
> ---
> Changes in v2
> - Only the changelog is updated; the code keep unchanged.
(What changelog was updated??)
Also, can you Cc:linux-trace-kernel@xxxxxxxxxxxxxxx next time?
Anyway, let me pick this to probes/fixes.
Thanks,
> ---
> arch/x86/kernel/kprobes/opt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
> index 3f8fea52619f..a920ecb99381 100644
> --- a/arch/x86/kernel/kprobes/opt.c
> +++ b/arch/x86/kernel/kprobes/opt.c
> @@ -252,7 +252,7 @@ static int insn_jump_into_range(struct insn *insn, unsigned long start, int len)
> }
> target = (unsigned long)insn->next_byte + insn->immediate.value;
>
> - return (start <= target && target <= start + len);
> + return (start <= target && target < start + len);
> }
>
> /* Decode whole function to ensure any instructions don't jump into target */
> --
> 2.34.1
>
>
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>