[PATCH] perf_events: fix invalid pointer when pid is invalid

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Stephane Eranian
Date: Monday, October 4, 2010 - 3:00 am

This patch fixes an error in perf_event_open() when the pid
provided by the user is invalid. find_lively_task_by_vpid()
does not return NULL on error but an error code. Without the
fix the error code was silently passed to find_get_context()
which would eventually cause a invalid pointer dereference.

Signed-off-by: Stephane Eranian <eranian@google.com>

---
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index c16158c..64507ea 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -5616,8 +5616,13 @@ SYSCALL_DEFINE5(perf_event_open,
 		}
 	}
 
-	if (pid != -1)
+	if (pid != -1) {
 		task = find_lively_task_by_vpid(pid);
+		if (IS_ERR(task)) {
+			err = PTR_ERR(task);
+			goto err_group_fd;
+		}
+	}
 
 	/*
 	 * Get the target context (task or percpu):
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] perf_events: fix invalid pointer when pid is invalid, Stephane Eranian, (Mon Oct 4, 3:00 am)
[tip:perf/core] perf_events: Fix invalid pointer when pid ..., tip-bot for Stephane ..., (Mon Oct 4, 1:35 pm)