FAILED: patch "[PATCH] kprobes: Protect kprobe_blacklist with RCU" 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 0c4256196b3a105307e2235fbfd85e768bbcdd0f
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090833-aptitude-antibody-c550@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 0c4256196b3a105307e2235fbfd85e768bbcdd0f Mon Sep 17 00:00:00 2001
From: "Masami Hiramatsu (Google)" <[email protected]>
Date: Sun, 30 Aug 2026 23:27:23 +0900
Subject: [PATCH] kprobes: Protect kprobe_blacklist with RCU
__within_kprobe_blacklist() traverses kprobe_blacklist without holding kprobe_mutex. When a module is unloaded, kprobe_remove_area_blacklist() removes blacklist entries and immediately frees them with kfree(). A concurrent call to within_kprobe_blacklist() can therefore dereference freed memory.
Furthermore, within_kprobe_blacklist() can be called in atomic or non-preemptible contexts where the sleeping kprobe_mutex cannot be taken.
Protect kprobe_blacklist with RCU. Use guard(rcu)() and list_for_each_entry_rcu() for traversal, list_add_tail_rcu() for insertions, list_del_rcu() for deletions, and kfree_rcu() to reclaim entries safely after a grace period.
include/linux/kprobes.h +1 -0
@@ -181,6 +181,7 @@ struct kprobe_blacklist_entry {struct list_head list;unsigned long start_addr;unsigned long end_addr; +struct rcu_head rcu; };#ifdef CONFIG_KPROBES
kernel/kprobes.c +10 -4
@@ -1447,8 +1447,14 @@ static bool __within_kprobe_blacklist(unsigned long addr)/* * If 'kprobe_blacklist' is defined, check the address and * reject any probe registration in the prohibited area. +* Note: this can return true during transition period where +* (start_addr, end_addr) in the black list is shrinking +* but old entry has not been removed yet. This is acceptable +* because the worst case is that we reject more probes than +* we should. */ -list_for_each_entry (ent, &kprobe_blacklist, list) { +guard (rcu)(); +list_for_each_entry_rcu (ent, &kprobe_blacklist, list) {if (addr >= ent->start_addr && addr < ent->end_addr)return true; }
@@ -2509,7 +2515,7 @@ int kprobe_add_ksym_blacklist(unsigned long entry) ent->start_addr = entry; ent->end_addr = entry + size;INIT_LIST_HEAD (&ent->list); -list_add_tail (&ent->list, &kprobe_blacklist); +list_add_tail_rcu (&ent->list, &kprobe_blacklist);return (int )size; }
@@ -2603,8 +2609,8 @@ static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end)list_for_each_entry_safe (ent, n, &kprobe_blacklist, list) {if (ent->start_addr < start || ent->start_addr >= end)continue ; -list_del (&ent->list); -kfree (ent); +list_del_rcu (&ent->list); +kfree_rcu (ent, rcu); } }
Sasha Levin
maintainerPATCH 1/1 kprobes: Protect kprobe_blacklist with RCU
From: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit 0c4256196b3a105307e2235fbfd85e768bbcdd0f ]
__within_kprobe_blacklist() traverses kprobe_blacklist without holding kprobe_mutex. When a module is unloaded, kprobe_remove_area_blacklist() removes blacklist entries and immediately frees them with kfree(). A concurrent call to within_kprobe_blacklist() can therefore dereference freed memory.
Furthermore, within_kprobe_blacklist() can be called in atomic or non-preemptible contexts where the sleeping kprobe_mutex cannot be taken.
Protect kprobe_blacklist with RCU. Use guard(rcu)() and list_for_each_entry_rcu() for traversal, list_add_tail_rcu() for insertions, list_del_rcu() for deletions, and kfree_rcu() to reclaim entries safely after a grace period.
--- include/linux/kprobes.h | 1 + kernel/kprobes.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-)
include/linux/kprobes.h +1 -0
@@ -177,6 +177,7 @@ struct kprobe_blacklist_entry {struct list_head list;unsigned long start_addr;unsigned long end_addr; +struct rcu_head rcu; };#ifdef CONFIG_KPROBES
kernel/kprobes.c +14 -5
@@ -1427,11 +1427,20 @@ static bool __within_kprobe_blacklist(unsigned long addr)/* * If there exists a kprobe_blacklist, verify and * fail any probe registration in the prohibited area +* Note: this can return true during transition period where +* (start_addr, end_addr) in the black list is shrinking +* but old entry has not been removed yet. This is acceptable +* because the worst case is that we reject more probes than +* we should. */ -list_for_each_entry (ent, &kprobe_blacklist, list) { -if (addr >= ent->start_addr && addr < ent->end_addr) +rcu_read_lock (); +list_for_each_entry_rcu (ent, &kprobe_blacklist, list) { +if (addr >= ent->start_addr && addr < ent->end_addr) { +rcu_read_unlock ();return true; + } } +rcu_read_unlock ();return false; }
@@ -2258,7 +2267,7 @@ int kprobe_add_ksym_blacklist(unsigned long entry) ent->start_addr = entry; ent->end_addr = entry + size;INIT_LIST_HEAD (&ent->list); -list_add_tail (&ent->list, &kprobe_blacklist); +list_add_tail_rcu (&ent->list, &kprobe_blacklist);return (int )size; }
@@ -2287,8 +2296,8 @@ static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end)list_for_each_entry_safe (ent, n, &kprobe_blacklist, list) {if (ent->start_addr < start || ent->start_addr >= end)continue ; -list_del (&ent->list); -kfree (ent); +list_del_rcu (&ent->list); +kfree_rcu (ent, rcu); } }
Signature · 1 line
2.53.0