From: sashiko-bot@kernel.org
To: "Mani Tofigh" <mt4022@columbia.edu>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] kprobes: Arm reused optprobe on cooling list
Date: Tue, 03 Nov 2026 19:12:46 +0000 [thread overview]
Message-ID: <sashiko-outbox-195906@kernel.org> (raw)
In-Reply-To: <20261103-kprobes-optprobe-state-v1-3-6aaac612abe6@columbia.edu>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kprobes: reuse_unused_kprobe() arms cooling probe when new probe is disabled
--
commit c03ba118d217fb856e6a911233d52037e4e98250
Author: Mani Tofigh <mt4022@columbia.edu>
kprobes: Arm reused optprobe on cooling list
This commit arms an unused aggregator kprobe in reuse_unused_kprobe() when
it is still on an optprobe cooling list so that a newly registered probe
at the same address will fire before optimization finishes.
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 84a5f68476eb1..59c5689299ce3 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
[ ... ]
> @@ -1067,6 +1068,13 @@ static int reuse_unused_kprobe(struct kprobe *ap)
> if (!kprobe_optready(ap))
> return -EINVAL;
>
> + if (optprobe_queued_cooling(op)) {
> + /* Already disarmed. It will be optimized again upon finalize */
> + if (!kprobes_all_disarmed)
> + __arm_kprobe(ap);
> + return 0;
> + }
[Severity: High]
What happens here if the newly registered kprobe has KPROBE_FLAG_DISABLED
set, such as when __register_trace_kprobe() registers a new tracefs
kprobe_events entry before enabling it?
In __register_kprobe() -> register_aggr_kprobe(), reuse_unused_kprobe(ap)
is called before checking whether the new probe p is disabled:
kernel/kprobes.c:register_aggr_kprobe() {
...
} else if (kprobe_unused(ap)) {
/* This probe is going to die. Rescue it */
ret = reuse_unused_kprobe(ap);
if (ret)
return ret;
}
...
if (ret == 0 && kprobe_disabled(ap) && !kprobe_disabled(p)) {
ap->flags &= ~KPROBE_FLAG_DISABLED;
if (!kprobes_all_disarmed) {
/* Arm the breakpoint again. */
ret = arm_kprobe(ap);
...
}
Because reuse_unused_kprobe(ap) unconditionally clears KPROBE_FLAG_DISABLED
on ap and calls __arm_kprobe(ap) when op is on a cooling_list, it bypasses
the !kprobe_disabled(p) check in register_aggr_kprobe(). This arms a
breakpoint in kernel text (and later jump-optimizes ap in
optprobe_finalize_generation()) even though all child probes on ap->list
are disabled.
Furthermore, if the disabled child probe p is later unregistered without
ever being enabled, __unregister_kprobe_top() calls __disable_kprobe(p),
which sees kprobe_disabled(p) and returns early without setting
KPROBE_FLAG_DISABLED on ap or disarming it:
kernel/kprobes.c:__disable_kprobe() {
...
if (kprobe_disabled(p))
return orig_p;
...
}
Then in __unregister_kprobe_top(), kprobe_disarmed(ap) is false because
KPROBE_FLAG_DISABLED is not set on ap:
kernel/kprobes.c:__unregister_kprobe_top() {
...
if (ap == p ||
(list_is_singular(&ap->list) && kprobe_disarmed(ap))) {
/*
* !disarmed could be happen if the probe is under delayed
* unoptimizing.
*/
hlist_del_rcu(&ap->hlist);
return 0;
}
...
}
Does this leave the aggregator struct optimized_kprobe permanently hashed
and leaked in kprobe_table with an empty ap->list and an active breakpoint
or jump instruction patched into kernel text?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103-kprobes-optprobe-state-v1-0-6aaac612abe6@columbia.edu?part=3
next prev parent reply other threads:[~2026-11-03 19:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 18:45 [PATCH 0/3] kprobes: Fix optprobe state after forced unoptimization Mani Tofigh via B4 Relay
2026-11-03 18:45 ` Mani Tofigh
2026-11-03 18:45 ` [PATCH 1/3] kprobes: Disarm disabled optprobe on " Mani Tofigh via B4 Relay
2026-11-03 18:45 ` Mani Tofigh
2026-11-04 6:49 ` Masami Hiramatsu (Google)
2026-11-03 18:46 ` [PATCH 2/3] kprobes: Do not disarm unhashed optprobe on dispatch Mani Tofigh via B4 Relay
2026-11-03 18:46 ` Mani Tofigh
2026-11-03 18:46 ` [PATCH 3/3] kprobes: Arm reused optprobe on cooling list Mani Tofigh via B4 Relay
2026-11-03 18:46 ` Mani Tofigh
2026-11-03 19:12 ` sashiko-bot [this message]
2026-11-04 16:44 ` Masami Hiramatsu (Google)
2026-11-05 1:03 ` [PATCH 0/3] kprobes: Fix optprobe state after forced unoptimization 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=sashiko-outbox-195906@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mt4022@columbia.edu \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.