Commit c6c67bf9 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'trace-probes-v6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull tracing/probes fixes from Steven Rostedt:

 - Fix possible NULL pointer dereference on trace_event_file in
   kprobe_event_gen_test_exit()

 - Fix NULL pointer dereference for trace_array in
   kprobe_event_gen_test_exit()

 - Fix memory leak of filter string for eprobes

 - Fix a possible memory leak in rethook_alloc()

 - Skip clearing aggrprobe's post_handler in kprobe-on-ftrace case which
   can cause a possible use-after-free

 - Fix warning in eprobe filter creation

 - Fix eprobe filter creation as it picked the wrong event for the
   fields

* tag 'trace-probes-v6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
  tracing/eprobe: Fix eprobe filter to make a filter correctly
  tracing/eprobe: Fix warning in filter creation
  kprobes: Skip clearing aggrprobe's post_handler in kprobe-on-ftrace case
  rethook: fix a potential memleak in rethook_alloc()
  tracing/eprobe: Fix memory leak of filter string
  tracing: kprobe: Fix potential null-ptr-deref on trace_array in kprobe_event_gen_test_exit()
  tracing: kprobe: Fix potential null-ptr-deref on trace_event_file in kprobe_event_gen_test_exit()
parents 5239ddeb 40adaf51
...@@ -1766,7 +1766,13 @@ static int __unregister_kprobe_top(struct kprobe *p) ...@@ -1766,7 +1766,13 @@ static int __unregister_kprobe_top(struct kprobe *p)
if ((list_p != p) && (list_p->post_handler)) if ((list_p != p) && (list_p->post_handler))
goto noclean; goto noclean;
} }
ap->post_handler = NULL; /*
* For the kprobe-on-ftrace case, we keep the
* post_handler setting to identify this aggrprobe
* armed with kprobe_ipmodify_ops.
*/
if (!kprobe_ftrace(ap))
ap->post_handler = NULL;
} }
noclean: noclean:
/* /*
......
...@@ -73,6 +73,10 @@ static struct trace_event_file *gen_kretprobe_test; ...@@ -73,6 +73,10 @@ static struct trace_event_file *gen_kretprobe_test;
#define KPROBE_GEN_TEST_ARG3 NULL #define KPROBE_GEN_TEST_ARG3 NULL
#endif #endif
static bool trace_event_file_is_valid(struct trace_event_file *input)
{
return input && !IS_ERR(input);
}
/* /*
* Test to make sure we can create a kprobe event, then add more * Test to make sure we can create a kprobe event, then add more
...@@ -139,6 +143,8 @@ static int __init test_gen_kprobe_cmd(void) ...@@ -139,6 +143,8 @@ static int __init test_gen_kprobe_cmd(void)
kfree(buf); kfree(buf);
return ret; return ret;
delete: delete:
if (trace_event_file_is_valid(gen_kprobe_test))
gen_kprobe_test = NULL;
/* We got an error after creating the event, delete it */ /* We got an error after creating the event, delete it */
ret = kprobe_event_delete("gen_kprobe_test"); ret = kprobe_event_delete("gen_kprobe_test");
goto out; goto out;
...@@ -202,6 +208,8 @@ static int __init test_gen_kretprobe_cmd(void) ...@@ -202,6 +208,8 @@ static int __init test_gen_kretprobe_cmd(void)
kfree(buf); kfree(buf);
return ret; return ret;
delete: delete:
if (trace_event_file_is_valid(gen_kretprobe_test))
gen_kretprobe_test = NULL;
/* We got an error after creating the event, delete it */ /* We got an error after creating the event, delete it */
ret = kprobe_event_delete("gen_kretprobe_test"); ret = kprobe_event_delete("gen_kretprobe_test");
goto out; goto out;
...@@ -217,10 +225,12 @@ static int __init kprobe_event_gen_test_init(void) ...@@ -217,10 +225,12 @@ static int __init kprobe_event_gen_test_init(void)
ret = test_gen_kretprobe_cmd(); ret = test_gen_kretprobe_cmd();
if (ret) { if (ret) {
WARN_ON(trace_array_set_clr_event(gen_kretprobe_test->tr, if (trace_event_file_is_valid(gen_kretprobe_test)) {
"kprobes", WARN_ON(trace_array_set_clr_event(gen_kretprobe_test->tr,
"gen_kretprobe_test", false)); "kprobes",
trace_put_event_file(gen_kretprobe_test); "gen_kretprobe_test", false));
trace_put_event_file(gen_kretprobe_test);
}
WARN_ON(kprobe_event_delete("gen_kretprobe_test")); WARN_ON(kprobe_event_delete("gen_kretprobe_test"));
} }
...@@ -229,24 +239,30 @@ static int __init kprobe_event_gen_test_init(void) ...@@ -229,24 +239,30 @@ static int __init kprobe_event_gen_test_init(void)
static void __exit kprobe_event_gen_test_exit(void) static void __exit kprobe_event_gen_test_exit(void)
{ {
/* Disable the event or you can't remove it */ if (trace_event_file_is_valid(gen_kprobe_test)) {
WARN_ON(trace_array_set_clr_event(gen_kprobe_test->tr, /* Disable the event or you can't remove it */
"kprobes", WARN_ON(trace_array_set_clr_event(gen_kprobe_test->tr,
"gen_kprobe_test", false)); "kprobes",
"gen_kprobe_test", false));
/* Now give the file and instance back */
trace_put_event_file(gen_kprobe_test);
}
/* Now give the file and instance back */
trace_put_event_file(gen_kprobe_test);
/* Now unregister and free the event */ /* Now unregister and free the event */
WARN_ON(kprobe_event_delete("gen_kprobe_test")); WARN_ON(kprobe_event_delete("gen_kprobe_test"));
/* Disable the event or you can't remove it */ if (trace_event_file_is_valid(gen_kretprobe_test)) {
WARN_ON(trace_array_set_clr_event(gen_kretprobe_test->tr, /* Disable the event or you can't remove it */
"kprobes", WARN_ON(trace_array_set_clr_event(gen_kretprobe_test->tr,
"gen_kretprobe_test", false)); "kprobes",
"gen_kretprobe_test", false));
/* Now give the file and instance back */
trace_put_event_file(gen_kretprobe_test);
}
/* Now give the file and instance back */
trace_put_event_file(gen_kretprobe_test);
/* Now unregister and free the event */ /* Now unregister and free the event */
WARN_ON(kprobe_event_delete("gen_kretprobe_test")); WARN_ON(kprobe_event_delete("gen_kretprobe_test"));
......
...@@ -83,8 +83,10 @@ struct rethook *rethook_alloc(void *data, rethook_handler_t handler) ...@@ -83,8 +83,10 @@ struct rethook *rethook_alloc(void *data, rethook_handler_t handler)
{ {
struct rethook *rh = kzalloc(sizeof(struct rethook), GFP_KERNEL); struct rethook *rh = kzalloc(sizeof(struct rethook), GFP_KERNEL);
if (!rh || !handler) if (!rh || !handler) {
kfree(rh);
return NULL; return NULL;
}
rh->data = data; rh->data = data;
rh->handler = handler; rh->handler = handler;
......
...@@ -52,6 +52,7 @@ static void trace_event_probe_cleanup(struct trace_eprobe *ep) ...@@ -52,6 +52,7 @@ static void trace_event_probe_cleanup(struct trace_eprobe *ep)
kfree(ep->event_system); kfree(ep->event_system);
if (ep->event) if (ep->event)
trace_event_put_ref(ep->event); trace_event_put_ref(ep->event);
kfree(ep->filter_str);
kfree(ep); kfree(ep);
} }
...@@ -645,7 +646,7 @@ new_eprobe_trigger(struct trace_eprobe *ep, struct trace_event_file *file) ...@@ -645,7 +646,7 @@ new_eprobe_trigger(struct trace_eprobe *ep, struct trace_event_file *file)
INIT_LIST_HEAD(&trigger->list); INIT_LIST_HEAD(&trigger->list);
if (ep->filter_str) { if (ep->filter_str) {
ret = create_event_filter(file->tr, file->event_call, ret = create_event_filter(file->tr, ep->event,
ep->filter_str, false, &filter); ep->filter_str, false, &filter);
if (ret) if (ret)
goto error; goto error;
...@@ -903,7 +904,7 @@ static int trace_eprobe_tp_update_arg(struct trace_eprobe *ep, const char *argv[ ...@@ -903,7 +904,7 @@ static int trace_eprobe_tp_update_arg(struct trace_eprobe *ep, const char *argv[
static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, const char *argv[]) static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, const char *argv[])
{ {
struct event_filter *dummy; struct event_filter *dummy = NULL;
int i, ret, len = 0; int i, ret, len = 0;
char *p; char *p;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment