From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Naveen N Rao <naveen@kernel.org>,
"David S . Miller" <davem@davemloft.net>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Mani Tofigh <mt4022@columbia.edu>
Subject: [PATCH v3 3/5] kprobes: Do not overwrite jump instruction when re-arming unoptimizing probe
Date: Wed, 11 Nov 2026 23:13:49 +0900 [thread overview]
Message-ID: <179440642973.328088.10282643330198602134.stgit@devnote2> (raw)
In-Reply-To: <179440640176.328088.17106877243326801914.stgit@devnote2>
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
When an optimized probe is temporarily disarmed or disabled,
unoptimize_kprobe() places it on the unoptimizing list, but leaves
the relative jump in text until the optimizer thread runs.
__disarm_kprobe() explicitly skips arch_disarm_kprobe() when
kprobe_queued_unopt(p) is true.
However, if __arm_kprobe() is called before the unoptimization pass
executes, it unconditionally calls arch_arm_kprobe(p), writing a
breakpoint instruction over the first byte of the jump while leaving the
trailing bytes intact. optimize_kprobe(p) then dequeues the probe from
the unoptimizing queue, leaving the jump opcode overwritten with a
breakpoint in text while KPROBE_FLAG_OPTIMIZED remains set.
Skip calling arch_arm_kprobe() in __arm_kprobe() when
kprobe_queued_unopt(p) is true, keeping the existing relative jump intact
while unoptimization is cancelled. If optimize_kprobe() cannot optimize
the probe (e.g. due to a post_handler or disabled optimization), force
unoptimization immediately.
Fixes: 06e0d3b89da1 ("kprobes: Make optprobe optimizer multi-generational and asynchronous")
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
Changes in v3:
- Restore the __arm_kprobe() fix that was accidentally dropped in v2
while omitting the reuse_unused_kprobe() hunk superseded by commit
1ffd6efb1b58 ("kprobes: Arm reused optprobe on cooling list").
---
kernel/kprobes.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index c0637302eeae..f7cf77ca70de 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1263,6 +1263,19 @@ static void __init kprobe_sysctls_init(void)
}
#endif /* CONFIG_SYSCTL */
+/* Return true if the probe is queued on unoptimizing lists */
+static bool kprobe_queued_unopt(struct kprobe *p)
+{
+ struct optimized_kprobe *op;
+
+ if (kprobe_aggrprobe(p)) {
+ op = container_of(p, struct optimized_kprobe, kp);
+ if (optprobe_queued_unopt(op))
+ return true;
+ }
+ return false;
+}
+
/* Put a breakpoint for a probe. */
static void __arm_kprobe(struct kprobe *p)
{
@@ -1276,21 +1289,11 @@ static void __arm_kprobe(struct kprobe *p)
/* Fallback to unoptimized kprobe */
unoptimize_kprobe(_p, true);
- arch_arm_kprobe(p);
+ if (!kprobe_queued_unopt(p))
+ arch_arm_kprobe(p);
optimize_kprobe(p); /* Try to optimize (add kprobe to a list) */
-}
-
-/* Return true if the probe is queued on unoptimizing lists */
-static bool kprobe_queued_unopt(struct kprobe *p)
-{
- struct optimized_kprobe *op;
-
- if (kprobe_aggrprobe(p)) {
- op = container_of(p, struct optimized_kprobe, kp);
- if (optprobe_queued_unopt(op))
- return true;
- }
- return false;
+ if (unlikely(kprobe_queued_unopt(p)))
+ unoptimize_kprobe(p, true);
}
/* Remove the breakpoint of a probe. */
next prev parent reply other threads:[~2026-11-11 14:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 14:13 [PATCH v3 0/5] kprobes: Fixes for ftrace ops and optprobe state machine Masami Hiramatsu (Google)
2026-11-11 14:13 ` [PATCH v3 1/5] kprobes: Switch ftrace ops when adding probe with post_handler Masami Hiramatsu (Google)
2026-11-11 14:13 ` [PATCH v3 2/5] kprobes: Fix UAF and queue cooling probes on forced unoptimization Masami Hiramatsu (Google)
2026-11-11 14:13 ` Masami Hiramatsu (Google) [this message]
2026-11-11 14:13 ` [PATCH v3 4/5] kprobes: Re-optimize blocked sibling probe when cooling finishes Masami Hiramatsu (Google)
2026-11-11 14:14 ` [PATCH v3 5/5] kprobes: Add KUnit test cases for kprobes regressions Masami Hiramatsu (Google)
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=179440642973.328088.10282643330198602134.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mt4022@columbia.edu \
--cc=naveen@kernel.org \
--cc=rostedt@goodmis.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®