From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753300Ab1ARTH4 (ORCPT ); Tue, 18 Jan 2011 14:07:56 -0500 Received: from hera.kernel.org ([140.211.167.34]:50275 "EHLO hera.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751530Ab1ARTHz (ORCPT ); Tue, 18 Jan 2011 14:07:55 -0500 Date: Tue, 18 Jan 2011 19:07:23 GMT From: tip-bot for Oleg Nesterov Cc: linux-kernel@vger.kernel.org, paulus@samba.org, acme@redhat.com, hpa@zytor.com, mingo@redhat.com, stern@rowland.harvard.edu, a.p.zijlstra@chello.nl, roland@redhat.com, fweisbec@gmail.com, tglx@linutronix.de, oleg@redhat.com, mingo@elte.hu, prasad@linux.vnet.ibm.com Reply-To: mingo@redhat.com, hpa@zytor.com, acme@redhat.com, paulus@samba.org, linux-kernel@vger.kernel.org, stern@rowland.harvard.edu, a.p.zijlstra@chello.nl, fweisbec@gmail.com, roland@redhat.com, oleg@redhat.com, tglx@linutronix.de, prasad@linux.vnet.ibm.com, mingo@elte.hu In-Reply-To: <20110118161032.GC693@redhat.com> References: <20110118161032.GC693@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf: Validate cpu early in perf_event_alloc() Message-ID: Git-Commit-ID: 66832eb4baaaa9abe4c993ddf9113a79e39b9915 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.3 (hera.kernel.org [127.0.0.1]); Tue, 18 Jan 2011 19:07:23 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 66832eb4baaaa9abe4c993ddf9113a79e39b9915 Gitweb: http://git.kernel.org/tip/66832eb4baaaa9abe4c993ddf9113a79e39b9915 Author: Oleg Nesterov AuthorDate: Tue, 18 Jan 2011 17:10:32 +0100 Committer: Ingo Molnar CommitDate: Tue, 18 Jan 2011 19:34:23 +0100 perf: Validate cpu early in perf_event_alloc() Starting from perf_event_alloc()->perf_init_event(), the kernel assumes that event->cpu is either -1 or the valid CPU number. Change perf_event_alloc() to validate this argument early. This also means we can remove the similar check in find_get_context(). Signed-off-by: Oleg Nesterov Acked-by: Peter Zijlstra Cc: Alan Stern Cc: Arnaldo Carvalho de Melo Cc: Frederic Weisbecker Cc: Paul Mackerras Cc: Prasad Cc: Roland McGrath Cc: gregkh@suse.de Cc: stable@kernel.org LKML-Reference: <20110118161032.GC693@redhat.com> Signed-off-by: Ingo Molnar --- kernel/perf_event.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/perf_event.c b/kernel/perf_event.c index a962b19..67d9bd7 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c @@ -2233,9 +2233,6 @@ find_get_context(struct pmu *pmu, struct task_struct *task, int cpu) if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) return ERR_PTR(-EACCES); - if (cpu < 0 || cpu >= nr_cpumask_bits) - return ERR_PTR(-EINVAL); - /* * We could be clever and allow to attach a event to an * offline CPU and activate it when the CPU comes up, but @@ -5541,6 +5538,11 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, struct hw_perf_event *hwc; long err; + if ((unsigned)cpu >= nr_cpu_ids) { + if (!task || cpu != -1) + return ERR_PTR(-EINVAL); + } + event = kzalloc(sizeof(*event), GFP_KERNEL); if (!event) return ERR_PTR(-ENOMEM); @@ -5589,7 +5591,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, if (!overflow_handler && parent_event) overflow_handler = parent_event->overflow_handler; - + event->overflow_handler = overflow_handler; if (attr->disabled)