mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
tracing/perf: Use strndup_user() instead of buggy open-coded version
commit83540fbc88upstream. The first version of this method was missing the check for `ret == PATH_MAX`; then such a check was added, but it didn't call kfree() on error, so there was still a small memory leak in the error case. Fix it by using strndup_user() instead of open-coding it. Link: http://lkml.kernel.org/r/20190220165443.152385-1-jannh@google.com Cc: Ingo Molnar <mingo@kernel.org> Cc: stable@vger.kernel.org Fixes:0eadcc7a7b("perf/core: Fix perf_uprobe_init()") Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
aca126f4a4
commit
020c90c694
@@ -299,15 +299,13 @@ int perf_uprobe_init(struct perf_event *p_event,
|
|||||||
|
|
||||||
if (!p_event->attr.uprobe_path)
|
if (!p_event->attr.uprobe_path)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
path = kzalloc(PATH_MAX, GFP_KERNEL);
|
|
||||||
if (!path)
|
path = strndup_user(u64_to_user_ptr(p_event->attr.uprobe_path),
|
||||||
return -ENOMEM;
|
PATH_MAX);
|
||||||
ret = strncpy_from_user(
|
if (IS_ERR(path)) {
|
||||||
path, u64_to_user_ptr(p_event->attr.uprobe_path), PATH_MAX);
|
ret = PTR_ERR(path);
|
||||||
if (ret == PATH_MAX)
|
return (ret == -EINVAL) ? -E2BIG : ret;
|
||||||
return -E2BIG;
|
}
|
||||||
if (ret < 0)
|
|
||||||
goto out;
|
|
||||||
if (path[0] == '\0') {
|
if (path[0] == '\0') {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
Reference in New Issue
Block a user