aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Moll <pawel.moll@arm.com>2014-06-13 11:03:32 -0400
committerIngo Molnar <mingo@kernel.org>2014-08-20 03:42:13 -0400
commitb3f207855f57b9c8f43a547a801340bb5cbc59e5 (patch)
tree81845f485708aec5c07e52e119bb48a2bda5985a
parentf96f56780ca584930bb3a2769d73fd9a101bcbbe (diff)
perf: Handle compat ioctl
When running a 32-bit userspace on a 64-bit kernel (eg. i386 application on x86_64 kernel or 32-bit arm userspace on arm64 kernel) some of the perf ioctls must be treated with special care, as they have a pointer size encoded in the command. For example, PERF_EVENT_IOC_ID in 32-bit world will be encoded as 0x80042407, but 64-bit kernel will expect 0x80082407. In result the ioctl will fail returning -ENOTTY. This patch solves the problem by adding code fixing up the size as compat_ioctl file operation. Reported-by: Drew Richardson <drew.richardson@arm.com> Signed-off-by: Pawel Moll <pawel.moll@arm.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Link: http://lkml.kernel.org/r/1402671812-9078-1-git-send-email-pawel.moll@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--kernel/events/core.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 1cf24b3e42ec..f9c1ed002dbc 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -41,6 +41,7 @@
41#include <linux/cgroup.h> 41#include <linux/cgroup.h>
42#include <linux/module.h> 42#include <linux/module.h>
43#include <linux/mman.h> 43#include <linux/mman.h>
44#include <linux/compat.h>
44 45
45#include "internal.h" 46#include "internal.h"
46 47
@@ -3717,6 +3718,26 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3717 return 0; 3718 return 0;
3718} 3719}
3719 3720
3721#ifdef CONFIG_COMPAT
3722static long perf_compat_ioctl(struct file *file, unsigned int cmd,
3723 unsigned long arg)
3724{
3725 switch (_IOC_NR(cmd)) {
3726 case _IOC_NR(PERF_EVENT_IOC_SET_FILTER):
3727 case _IOC_NR(PERF_EVENT_IOC_ID):
3728 /* Fix up pointer size (usually 4 -> 8 in 32-on-64-bit case */
3729 if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) {
3730 cmd &= ~IOCSIZE_MASK;
3731 cmd |= sizeof(void *) << IOCSIZE_SHIFT;
3732 }
3733 break;
3734 }
3735 return perf_ioctl(file, cmd, arg);
3736}
3737#else
3738# define perf_compat_ioctl NULL
3739#endif
3740
3720int perf_event_task_enable(void) 3741int perf_event_task_enable(void)
3721{ 3742{
3722 struct perf_event *event; 3743 struct perf_event *event;
@@ -4222,7 +4243,7 @@ static const struct file_operations perf_fops = {
4222 .read = perf_read, 4243 .read = perf_read,
4223 .poll = perf_poll, 4244 .poll = perf_poll,
4224 .unlocked_ioctl = perf_ioctl, 4245 .unlocked_ioctl = perf_ioctl,
4225 .compat_ioctl = perf_ioctl, 4246 .compat_ioctl = perf_compat_ioctl,
4226 .mmap = perf_mmap, 4247 .mmap = perf_mmap,
4227 .fasync = perf_fasync, 4248 .fasync = perf_fasync,
4228}; 4249};