Skip to content

Commit

Permalink
tracing: Fix some alloc_event_probe() error handling bugs
Browse files Browse the repository at this point in the history
There are two bugs in this code.  First, if the kzalloc() fails it leads
to a NULL dereference of "ep" on the next line.  Second, if the
alloc_event_probe() function returns an error then it leads to an
error pointer dereference in the caller.

Link: https://lkml.kernel.org/r/20210824115150.GI31143@kili

Fixes: 7491e2c ("tracing: Add a probe that attaches to trace events")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Dan Carpenter authored and rostedt committed Sep 8, 2021
1 parent 54357f0 commit 5615e08
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions kernel/trace/trace_eprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static struct trace_eprobe *alloc_event_probe(const char *group,

ep = kzalloc(struct_size(ep, tp.args, nargs), GFP_KERNEL);
if (!ep) {
trace_event_put_ref(ep->event);
trace_event_put_ref(event);
goto error;
}
ep->event = event;
Expand Down Expand Up @@ -851,7 +851,8 @@ static int __trace_eprobe_create(int argc, const char *argv[])
ret = PTR_ERR(ep);
/* This must return -ENOMEM, else there is a bug */
WARN_ON_ONCE(ret != -ENOMEM);
goto error; /* We know ep is not allocated */
ep = NULL;
goto error;
}

argc -= 2; argv += 2;
Expand Down

0 comments on commit 5615e08

Please sign in to comment.