probes: Fixes for v7.3-rc1
Masami Hiramatsu (Google)
maintainerLinus,
Probes fixes for v7.3-rc1:
- kprobes: Protect kprobe_blacklist with RCU
. RCU-protect kprobe_blacklist and use kfree_rcu() to prevent UAF
races during module unloading and enable safe atomic lookups.
- tracing/probes: Fix multi-probe field use-after-free and BTF parsing . Multi-probe UAF fix: Duplicate field and type strings on trace_probe_event to prevent UAF when freeing primary probe. . BTF member lookup fixes:
- Check the containing inner struct/union kflag when resolving anonymous members to ensure correct bitfield offset calculation.
- Prevent unnamed bitfields from being pushed to anon_stack in btf_find_struct_member(), avoiding false lookup errors.
- Fix code block indentation in get_bitoffset_of_field().
- uprobes: Error pointer safety
. Guard free_trace_uprobe() with IS_ERR_OR_NULL() to avoid crashing
during automatic cleanup when an error pointer is returned.
Please pull the latest probes-fixes-v7.3-rc1 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
probes-fixes-v7.3-rc1
Tag SHA1: af3575e771353db2aef2a03f8b91a3a80d7ec513 Head SHA1: 0c4256196b3a105307e2235fbfd85e768bbcdd0f
Andi Kleen (1):
uprobes: guard trace cleanup against error pointers
Henry Martin (1):
tracing/probes: Fix use-after-free on field name/type of events with multiple probes
Masami Hiramatsu (Google) (4):
tracing/probes: Fix anon_stack check for unnamed bitfields in btf_find_struct_member tracing/probes: Fix BTF kflag check for anonymous struct member access tracing/probes: Fix code indent in get_bitoffset_of_field()
kprobes: Protect kprobe_blacklist with RCU
----
include/linux/kprobes.h | 1 + kernel/kprobes.c | 14 +++++++--- kernel/trace/trace_btf.c | 31 ++++++++++++---------- kernel/trace/trace_btf.h | 3 ++- kernel/trace/trace_probe.c | 63 +++++++++++++++++++++++++++++++++++++++------ kernel/trace/trace_probe.h | 2 ++ kernel/trace/trace_uprobe.c | 4 +-- 7 files changed, 89 insertions(+), 29 deletions(-)
---------------------------
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); } }
kernel/trace/trace_btf.c +17 -14
@@ -61,47 +61,50 @@ struct btf_anon_stack {/* * Find a member of data structure/union by name and return it. -* Return NULL if not found, or -EINVAL if parameter is invalid. -* If the member is an member of anonymous union/structure, the offset -* of that anonymous union/structure is stored into @anon_offset. Caller -* can calculate the correct offset from the root data structure by -* adding anon_offset to the member's offset. +* Return NULL if not found, or ERR_PTR(-EINVAL) if parameter is invalid. +* If the member is a member of an anonymous union/structure, the bit offset +* of that anonymous union/structure is stored into @anon_offset. +* If @member_type is non-NULL, the actual containing structure/union type +* of the found member is stored into @member_type. */ const struct btf_member *btf_find_struct_member (struct btf *btf,const struct btf_type *type,const char *member_name, -u32 *anon_offset) +u32 *anon_offset, +const struct btf_type **member_type) {struct btf_anon_stack *anon_stack;const struct btf_member *member; +const struct btf_type *mtype;u32 tid, cur_offset =0 ;const char *name;int i, top =0 ; +if (!btf_type_is_struct (type)) +return ERR_PTR (-EINVAL ); + anon_stack =kzalloc_objs (*anon_stack,BTF_ANON_STACK_MAX );if (!anon_stack)return ERR_PTR (-ENOMEM ); retry: -if (!btf_type_is_struct (type)) { - member =ERR_PTR (-EINVAL ); - goto out; - } -for_each_member (i, type, member) {if (!member->name_off) {/* Anonymous union/struct: push it for later use */ -if (btf_type_skip_modifiers (btf, member->type, &tid) && + mtype =btf_type_skip_modifiers (btf, member->type, &tid); +if (mtype &&btf_type_is_struct (mtype) && top <BTF_ANON_STACK_MAX ) { anon_stack[top].tid = tid; - anon_stack[top++].offset = - cur_offset + member->offset; + anon_stack[top++].offset = cur_offset + +__btf_member_bit_offset (type, member); } }else { name =btf_name_by_offset (btf, member->name_off);if (name && !strcmp (member_name, name)) {if (anon_offset) *anon_offset = cur_offset; +if (member_type) + *member_type = type; goto out; } }
kernel/trace/trace_btf.h +2 -1
@@ -8,4 +8,5 @@ const struct btf_param *btf_get_func_param(const struct btf_type *func_proto,const struct btf_member *btf_find_struct_member (struct btf *btf,const struct btf_type *type,const char *member_name, -u32 *anon_offset); +u32 *anon_offset, +const struct btf_type **member_type);
kernel/trace/trace_probe.c +55 -8
111 lines not on this page · raw message
kernel/trace/trace_probe.h +2 -0
@@ -264,6 +264,8 @@ struct trace_probe_event {struct trace_event_call call;struct list_head files;struct list_head probes; +char **field_strings; +int nr_field_strings;struct trace_uprobe_filter filter[]; };
kernel/trace/trace_uprobe.c +2 -2
@@ -368,7 +368,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)static void free_trace_uprobe (struct trace_uprobe *tu) { -if (!tu) +if (IS_ERR_OR_NULL (tu))return ;path_put (&tu->path);
@@ -533,7 +533,7 @@ static int register_trace_uprobe(struct trace_uprobe *tu)return ret; } -DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, if (_T) free_trace_uprobe(_T)) +DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, free_trace_uprobe(_T))/* * Argument syntax:
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
The pull request you sent on Fri, 4 Sep 2026 17:48:56 +0900:
The pull request you sent on Fri, 4 Sep 2026 17:48:56 +0900:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.gitprobes-fixes-v7.3-rc1
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/421066905cbceca1f78cba5f7d92b4980317ab2b
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html
The pull request you sent on Fri, 4 Sep 2026 17:48:56 +0900:
The pull request you sent on Fri, 4 Sep 2026 17:48:56 +0900:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.gitprobes-fixes-v7.3-rc1
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/421066905cbceca1f78cba5f7d92b4980317ab2b
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html