FAILED: patch "[PATCH] kprobes: Skip disarmed probes when checking optkprobe overlap" failed to apply to 5.15-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 7a39c732a22ec4a369af9e19fbe3d666ec83eec4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026100344-anchor-outpost-f7ad@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 7a39c732a22ec4a369af9e19fbe3d666ec83eec4 Mon Sep 17 00:00:00 2001
From: Leon Hwang <[email protected]>
Date: Wed, 30 Sep 2026 13:36:18 +0800
Subject: [PATCH] kprobes: Skip disarmed probes when checking optkprobe overlap
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.
Continue past disarmed and unprepared probes to find the active optimized probe before arming a probe in its jump.
kernel/kprobes.c +5 -3
@@ -496,14 +496,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;
Sasha Levin
maintainerPATCH 1/3 kprobe: Simplify prepare_kprobe() by dropping redundant version
From: Punit Agrawal <[email protected]>
[ Upstream commit 02afb8d6048d6526619e6e2dcdc95ce9c2bdb52f ]
The function prepare_kprobe() is called during kprobe registration and is responsible for ensuring any architecture related preparation for the kprobe is done before returning.
One of two versions of prepare_kprobe() is chosen depending on the availability of KPROBE_ON_FTRACE in the kernel configuration.
Simplify the code by dropping the version when KPROBE_ON_FTRACE is not selected - instead relying on kprobe_ftrace() to return false when KPROBE_ON_FTRACE is not set.
No functional change.
Stable-dep-of: 7a39c732a22e ("kprobes: Skip disarmed probes when checking optkprobe overlap")
--- include/linux/kprobes.h | 5 +++++ kernel/kprobes.c | 23 +++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-)
include/linux/kprobes.h +5 -0
@@ -356,6 +356,11 @@ static inline void wait_for_kprobe_optimizer(void) { }extern void kprobe_ftrace_handler (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *ops,struct ftrace_regs *fregs);extern int arch_prepare_kprobe_ftrace (struct kprobe *p); +#else +static inline int arch_prepare_kprobe_ftrace (struct kprobe *p) +{ +return -EINVAL ; +}#endif int arch_check_ftrace_location (struct kprobe *p);
kernel/kprobes.c +9 -14
@@ -1033,15 +1033,6 @@ static struct ftrace_ops kprobe_ipmodify_ops __read_mostly = {static int kprobe_ipmodify_enabled;static int kprobe_ftrace_enabled; -/* Must ensure p->addr is really on ftrace */ -static int prepare_kprobe (struct kprobe *p) -{ -if (!kprobe_ftrace (p)) -return arch_prepare_kprobe (p); - -return arch_prepare_kprobe_ftrace (p); -} -/* Caller must lock kprobe_mutex */ static int __arm_kprobe_ftrace (struct kprobe *p,struct ftrace_ops *ops,int *cnt)
@@ -1108,11 +1099,6 @@ static int disarm_kprobe_ftrace(struct kprobe *p) ipmodify ? &kprobe_ipmodify_enabled : &kprobe_ftrace_enabled); }#else /* !CONFIG_KPROBES_ON_FTRACE */ -static inline int prepare_kprobe (struct kprobe *p) -{ -return arch_prepare_kprobe (p); -} -static inline int arm_kprobe_ftrace (struct kprobe *p) {return -ENODEV ;
@@ -1124,6 +1110,15 @@ static inline int disarm_kprobe_ftrace(struct kprobe *p) }#endif +static int prepare_kprobe (struct kprobe *p) +{ +/* Must ensure p->addr is really on ftrace */ +if (kprobe_ftrace (p)) +return arch_prepare_kprobe_ftrace (p); + +return arch_prepare_kprobe (p); +} +/* Arm a kprobe with text_mutex */ static int arm_kprobe (struct kprobe *kp) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 kprobes: Fix coding style issues
From: Masami Hiramatsu <[email protected]>
[ Upstream commit 223a76b268c9cfa265d454879ae09e2c9c808f87 ]
Fix coding style issues reported by checkpatch.pl and update comments to quote variable names and add "()" to function name.
One TODO comment in __disarm_kprobe() is removed because it has been done by following commit.
Limit the comment cleanup to optimized-probe lookup and its callers. Convert get_optimized_kprobe() and arch_within_optimized_kprobe() to kprobe_opcode_t * addresses, including all architecture implementations. Scale byte-sized bounds by sizeof(kprobe_opcode_t) when doing pointer arithmetic. This supplies the context needed by the subsequent fix for overlap checks skipping disarmed probes.
Keep the existing externally visible kprobe_disarmed() and the existing optimizer cleanup, blacklist and module validation behavior. Omit the unrelated comment, instruction-cache and error-code changes.
Stable-dep-of: 7a39c732a22e ("kprobes: Skip disarmed probes when checking optkprobe overlap")
--- arch/arm/probes/kprobes/opt-arm.c | 6 +++--- arch/powerpc/kernel/optprobes.c | 6 +++--- arch/x86/kernel/kprobes/opt.c | 6 +++--- include/linux/kprobes.h | 2 +- kernel/kprobes.c | 16 ++++++++-------- 5 files changed, 18 insertions(+), 18 deletions(-)
arch/arm/probes/kprobes/opt-arm.c +3 -3
@@ -345,10 +345,10 @@ void arch_unoptimize_kprobes(struct list_head *oplist, }int arch_within_optimized_kprobe (struct optimized_kprobe *op, -unsigned long addr) +kprobe_opcode_t *addr) { -return ((unsigned long )op->kp.addr <= addr && - (unsigned long )op->kp.addr +RELATIVEJUMP_SIZE > addr); +return (op->kp.addr <= addr && + op->kp.addr + (RELATIVEJUMP_SIZE /sizeof (kprobe_opcode_t)) > addr); }void arch_remove_optimized_kprobe (struct optimized_kprobe *op)
arch/powerpc/kernel/optprobes.c +3 -3
@@ -301,8 +301,8 @@ void arch_unoptimize_kprobes(struct list_head *oplist, struct list_head *done_li } } -int arch_within_optimized_kprobe (struct optimized_kprobe *op,unsigned long addr) +int arch_within_optimized_kprobe (struct optimized_kprobe *op,kprobe_opcode_t *addr) { -return ((unsigned long )op->kp.addr <= addr && - (unsigned long )op->kp.addr +RELATIVEJUMP_SIZE > addr); +return (op->kp.addr <= addr && + op->kp.addr + (RELATIVEJUMP_SIZE /sizeof (kprobe_opcode_t)) > addr); }
arch/x86/kernel/kprobes/opt.c +3 -3
@@ -355,10 +355,10 @@ int arch_check_optimized_kprobe(struct optimized_kprobe *op)/* Check the addr is within the optimized instructions. */ int arch_within_optimized_kprobe (struct optimized_kprobe *op, -unsigned long addr) +kprobe_opcode_t *addr) { -return ((unsigned long )op->kp.addr <= addr && - (unsigned long )op->kp.addr + op->optinsn.size > addr); +return (op->kp.addr <= addr && + op->kp.addr + op->optinsn.size > addr); }/* Free optimized instruction slot */
include/linux/kprobes.h +1 -1
@@ -334,7 +334,7 @@ extern void arch_unoptimize_kprobes(struct list_head *oplist, struct list_head *done_list);extern void arch_unoptimize_kprobe (struct optimized_kprobe *op);extern int arch_within_optimized_kprobe (struct optimized_kprobe *op, -unsigned long addr); +kprobe_opcode_t *addr);extern void opt_pre_handler (struct kprobe *p,struct pt_regs *regs);
kernel/kprobes.c +8 -8
@@ -480,17 +480,17 @@ static int kprobe_queued(struct kprobe *p)/* * Return an optimized kprobe whose optimizing code replaces -* instructions including addr (exclude breakpoint). +* instructions including 'addr' (exclude breakpoint). */ -static struct kprobe *get_optimized_kprobe (unsigned long addr) +static struct kprobe *get_optimized_kprobe (kprobe_opcode_t *addr) {int i;struct kprobe *p =NULL ;struct optimized_kprobe *op;/* Don't check i == 0, since that is a breakpoint case. */ -for (i =1 ; !p && i <MAX_OPTIMIZED_LENGTH ; i++) - p =get_kprobe ((void *)(addr - i)); +for (i =1 ; !p && i <MAX_OPTIMIZED_LENGTH /sizeof (kprobe_opcode_t); i++) + p =get_kprobe (addr - i);if (p &&kprobe_optready (p)) { op = container_of(p, struct optimized_kprobe, kp);
@@ -955,8 +955,8 @@ static void __arm_kprobe(struct kprobe *p) {struct kprobe *_p; -/* Check collision with other optimized kprobes */ - _p =get_optimized_kprobe ((unsigned long )p->addr); +/* Find the overlapping optimized kprobes. */ + _p =get_optimized_kprobe (p->addr);if (unlikely (_p))/* Fallback to unoptimized kprobe */ unoptimize_kprobe (_p, true);
@@ -975,8 +975,8 @@ static void __disarm_kprobe(struct kprobe *p, bool reopt)if (!kprobe_queued (p)) {arch_disarm_kprobe (p); -/* If another kprobe was blocked, optimize it. */ - _p =get_optimized_kprobe ((unsigned long )p->addr); +/* If another kprobe was blocked, re-optimize it. */ + _p =get_optimized_kprobe (p->addr);if (unlikely (_p) && reopt)optimize_kprobe (_p); }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 kprobes: Skip disarmed probes when checking optkprobe overlap
In reply to Sasha LevinFrom: Leon Hwang <[email protected]>
[ Upstream commit 7a39c732a22ec4a369af9e19fbe3d666ec83eec4 ]
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.
Continue past disarmed and unprepared probes to find the active optimized probe before arming a probe in its jump.
--- kernel/kprobes.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/kprobes.c +5 -3
@@ -485,14 +485,16 @@ static int 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;
Signature · 1 line
2.53.0