Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Pawel Moll and committed by
Ingo Molnar
b3f20785 f96f5678

+22 -1
+22 -1
kernel/events/core.c
··· 41 41 #include <linux/cgroup.h> 42 42 #include <linux/module.h> 43 43 #include <linux/mman.h> 44 + #include <linux/compat.h> 44 45 45 46 #include "internal.h" 46 47 ··· 3718 3717 return 0; 3719 3718 } 3720 3719 3720 + #ifdef CONFIG_COMPAT 3721 + static long perf_compat_ioctl(struct file *file, unsigned int cmd, 3722 + unsigned long arg) 3723 + { 3724 + switch (_IOC_NR(cmd)) { 3725 + case _IOC_NR(PERF_EVENT_IOC_SET_FILTER): 3726 + case _IOC_NR(PERF_EVENT_IOC_ID): 3727 + /* Fix up pointer size (usually 4 -> 8 in 32-on-64-bit case */ 3728 + if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) { 3729 + cmd &= ~IOCSIZE_MASK; 3730 + cmd |= sizeof(void *) << IOCSIZE_SHIFT; 3731 + } 3732 + break; 3733 + } 3734 + return perf_ioctl(file, cmd, arg); 3735 + } 3736 + #else 3737 + # define perf_compat_ioctl NULL 3738 + #endif 3739 + 3721 3740 int perf_event_task_enable(void) 3722 3741 { 3723 3742 struct perf_event *event; ··· 4243 4222 .read = perf_read, 4244 4223 .poll = perf_poll, 4245 4224 .unlocked_ioctl = perf_ioctl, 4246 - .compat_ioctl = perf_ioctl, 4225 + .compat_ioctl = perf_compat_ioctl, 4247 4226 .mmap = perf_mmap, 4248 4227 .fasync = perf_fasync, 4249 4228 };