mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Leon Hwang <leon.hwang@linux.dev>
Cc: Naveen N Rao <naveen@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] kprobes: Skip disarmed probes when checking optkprobe overlap
Date: Wed, 30 Sep 2026 22:37:24 +0900	[thread overview]
Message-ID: <20260930223724.87336536b2fe72f3732a9534@kernel.org> (raw)
In-Reply-To: <20260930053618.104498-1-leon.hwang@linux.dev>

On Wed, 30 Sep 2026 13:36:18 +0800
Leon Hwang <leon.hwang@linux.dev> wrote:

> On x86, an optkprobe at A replaces five bytes with a jump. If a disabled
> probe B is at A+2, get_optimized_kprobe() stops at B when arming a new
> probe C at A+4. It leaves A optimized:
> 
>               A    A+1  A+2  A+3  A+4
>   A's jump  | e9 | d0 | d1 | d2 | d3 |
>   after C   | e9 | d0 | d1 | d2 | cc |
> 
> The INT3 for C overwrites the last byte of A's jump displacement, so
> execution can jump to the wrong address. B can have prepared optinsns
> while disarmed, but has no jump to unoptimize.

Oops, good catch! get_optimized_kprobe() only checks the first disabled
one and do not unoptimize the A.

> 
> Continue past disarmed and unprepared probes to find the active optimized
> probe before arming a probe in its jump.

Yeah, this looks good to me. Let me send via probes/fixes.

Thank you!!

> 
> Fixes: afd66255b9a4 ("kprobes: Introduce kprobes jump optimization")
> Cc: stable@vger.kernel.org
> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
> ---
>  kernel/kprobes.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 6337da5cab9e..e6f6e18fa1b5 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -495,14 +495,16 @@ static bool kprobe_queued(struct kprobe *p)
>  static struct kprobe *get_optimized_kprobe(kprobe_opcode_t *addr)
>  {
>  	int i;
> -	struct kprobe *p = NULL;
> +	struct kprobe *p;
>  	struct optimized_kprobe *op;
>  
>  	/* Don't check i == 0, since that is a breakpoint case. */
> -	for (i = 1; !p && i < MAX_OPTIMIZED_LENGTH / sizeof(kprobe_opcode_t); i++)
> +	for (i = 1; i < MAX_OPTIMIZED_LENGTH / sizeof(kprobe_opcode_t); i++) {
>  		p = get_kprobe(addr - i);
> +		/* A disabled probe can have prepared, but inactive, optinsns. */
> +		if (!p || !kprobe_optready(p) || kprobe_disarmed(p))
> +			continue;
>  
> -	if (p && kprobe_optready(p)) {
>  		op = container_of(p, struct optimized_kprobe, kp);
>  		if (arch_within_optimized_kprobe(op, addr))
>  			return p;
> -- 
> 2.55.0
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

      reply	other threads:[~2026-09-30 13:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30  5:36 Leon Hwang
2026-09-30 13:37 ` Masami Hiramatsu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260930223724.87336536b2fe72f3732a9534@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=davem@davemloft.net \
    --cc=leon.hwang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=naveen@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®