Skip to content

Commit 405e6c3

Browse files
committed
Merge tag 'probes-fixes-v6.15-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull probes fixes from Masami Hiramatsu: - fprobe: Fix RCU warning message in list traversal fprobe_module_callback() using hlist_for_each_entry_rcu() traverse the fprobe list but it locks fprobe_mutex() instead of rcu lock because it is enough. So add lockdep_is_held() to avoid warning. - tracing: eprobe: Add missing trace_probe_log_clear for eprobe __trace_eprobe_create() uses trace_probe_log but forgot to clear it at exit. Add trace_probe_log_clear() calls. - tracing: probes: Fix possible race in trace_probe_log APIs trace_probe_log APIs are used in probe event (dynamic_events, kprobe_events and uprobe_events) creation. Only dynamic_events uses the dyn_event_ops_mutex mutex to serialize it. This makes kprobe and uprobe events to lock the same mutex to serialize its creation to avoid race in trace_probe_log APIs. * tag 'probes-fixes-v6.15-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing: probes: Fix a possible race in trace_probe_log APIs tracing: add missing trace_probe_log_clear for eprobes tracing: fprobe: Fix RCU warning message in list traversal
2 parents e9565e2 + fd837de commit 405e6c3

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

kernel/trace/fprobe.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ static void fprobe_remove_node_in_module(struct module *mod, struct hlist_head *
454454
struct fprobe_hlist_node *node;
455455
int ret = 0;
456456

457-
hlist_for_each_entry_rcu(node, head, hlist) {
457+
hlist_for_each_entry_rcu(node, head, hlist,
458+
lockdep_is_held(&fprobe_mutex)) {
458459
if (!within_module(node->addr, mod))
459460
continue;
460461
if (delete_fprobe_node(node))

kernel/trace/trace_dynevent.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "trace_output.h" /* for trace_event_sem */
1717
#include "trace_dynevent.h"
1818

19-
static DEFINE_MUTEX(dyn_event_ops_mutex);
19+
DEFINE_MUTEX(dyn_event_ops_mutex);
2020
static LIST_HEAD(dyn_event_ops_list);
2121

2222
bool trace_event_dyn_try_get_ref(struct trace_event_call *dyn_call)
@@ -116,6 +116,20 @@ int dyn_event_release(const char *raw_command, struct dyn_event_operations *type
116116
return ret;
117117
}
118118

119+
/*
120+
* Locked version of event creation. The event creation must be protected by
121+
* dyn_event_ops_mutex because of protecting trace_probe_log.
122+
*/
123+
int dyn_event_create(const char *raw_command, struct dyn_event_operations *type)
124+
{
125+
int ret;
126+
127+
mutex_lock(&dyn_event_ops_mutex);
128+
ret = type->create(raw_command);
129+
mutex_unlock(&dyn_event_ops_mutex);
130+
return ret;
131+
}
132+
119133
static int create_dyn_event(const char *raw_command)
120134
{
121135
struct dyn_event_operations *ops;

kernel/trace/trace_dynevent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void *dyn_event_seq_next(struct seq_file *m, void *v, loff_t *pos);
100100
void dyn_event_seq_stop(struct seq_file *m, void *v);
101101
int dyn_events_release_all(struct dyn_event_operations *type);
102102
int dyn_event_release(const char *raw_command, struct dyn_event_operations *type);
103+
int dyn_event_create(const char *raw_command, struct dyn_event_operations *type);
103104

104105
/*
105106
* for_each_dyn_event - iterate over the dyn_event list

kernel/trace/trace_eprobe.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,13 @@ static int __trace_eprobe_create(int argc, const char *argv[])
969969
goto error;
970970
}
971971
}
972+
trace_probe_log_clear();
972973
return ret;
974+
973975
parse_error:
974976
ret = -EINVAL;
975977
error:
978+
trace_probe_log_clear();
976979
trace_event_probe_cleanup(ep);
977980
return ret;
978981
}

kernel/trace/trace_kprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ static int create_or_delete_trace_kprobe(const char *raw_command)
10891089
if (raw_command[0] == '-')
10901090
return dyn_event_release(raw_command, &trace_kprobe_ops);
10911091

1092-
ret = trace_kprobe_create(raw_command);
1092+
ret = dyn_event_create(raw_command, &trace_kprobe_ops);
10931093
return ret == -ECANCELED ? -EINVAL : ret;
10941094
}
10951095

kernel/trace/trace_probe.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ static const struct fetch_type *find_fetch_type(const char *type, unsigned long
154154
}
155155

156156
static struct trace_probe_log trace_probe_log;
157+
extern struct mutex dyn_event_ops_mutex;
157158

158159
void trace_probe_log_init(const char *subsystem, int argc, const char **argv)
159160
{
161+
lockdep_assert_held(&dyn_event_ops_mutex);
162+
160163
trace_probe_log.subsystem = subsystem;
161164
trace_probe_log.argc = argc;
162165
trace_probe_log.argv = argv;
@@ -165,11 +168,15 @@ void trace_probe_log_init(const char *subsystem, int argc, const char **argv)
165168

166169
void trace_probe_log_clear(void)
167170
{
171+
lockdep_assert_held(&dyn_event_ops_mutex);
172+
168173
memset(&trace_probe_log, 0, sizeof(trace_probe_log));
169174
}
170175

171176
void trace_probe_log_set_index(int index)
172177
{
178+
lockdep_assert_held(&dyn_event_ops_mutex);
179+
173180
trace_probe_log.index = index;
174181
}
175182

@@ -178,6 +185,8 @@ void __trace_probe_log_err(int offset, int err_type)
178185
char *command, *p;
179186
int i, len = 0, pos = 0;
180187

188+
lockdep_assert_held(&dyn_event_ops_mutex);
189+
181190
if (!trace_probe_log.argv)
182191
return;
183192

kernel/trace/trace_uprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ static int create_or_delete_trace_uprobe(const char *raw_command)
741741
if (raw_command[0] == '-')
742742
return dyn_event_release(raw_command, &trace_uprobe_ops);
743743

744-
ret = trace_uprobe_create(raw_command);
744+
ret = dyn_event_create(raw_command, &trace_uprobe_ops);
745745
return ret == -ECANCELED ? -EINVAL : ret;
746746
}
747747

0 commit comments

Comments
 (0)