All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: Handle compat ioctl
@ 2014-06-13 15:03 Pawel Moll
  2014-06-17 12:13 ` Peter Zijlstra
  2014-08-20  8:18 ` [tip:perf/urgent] " tip-bot for Pawel Moll
  0 siblings, 2 replies; 10+ messages in thread
From: Pawel Moll @ 2014-06-13 15:03 UTC (permalink / raw)
  To: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Drew Richardson, Pawel Moll

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>
---
 kernel/events/core.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 24d35cc..967af2c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3700,6 +3700,26 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	return 0;
 }
 
+#ifdef CONFIG_COMPAT
+static long perf_compat_ioctl(struct file *file, unsigned int cmd,
+				unsigned long arg)
+{
+	switch (_IOC_NR(cmd)) {
+	case _IOC_NR(PERF_EVENT_IOC_SET_FILTER):
+	case _IOC_NR(PERF_EVENT_IOC_ID):
+		/* Fix up pointer size (usually 4 -> 8 in 32-on-64-bit case */
+		if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) {
+			cmd &= ~IOCSIZE_MASK;
+			cmd |= sizeof(void *) << IOCSIZE_SHIFT;
+		}
+		break;
+	}
+	return perf_ioctl(file, cmd, arg);
+}
+#else
+#define perf_compat_ioctl NULL
+#endif
+
 int perf_event_task_enable(void)
 {
 	struct perf_event *event;
@@ -4205,7 +4225,7 @@ static const struct file_operations perf_fops = {
 	.read			= perf_read,
 	.poll			= perf_poll,
 	.unlocked_ioctl		= perf_ioctl,
-	.compat_ioctl		= perf_ioctl,
+	.compat_ioctl		= perf_compat_ioctl,
 	.mmap			= perf_mmap,
 	.fasync			= perf_fasync,
 };
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] perf: Handle compat ioctl
  2014-06-13 15:03 [PATCH] perf: Handle compat ioctl Pawel Moll
@ 2014-06-17 12:13 ` Peter Zijlstra
  2014-06-17 12:43   ` [PATCH v2] " Pawel Moll
  2014-06-17 13:19   ` [PATCH] " Pawel Moll
  2014-08-20  8:18 ` [tip:perf/urgent] " tip-bot for Pawel Moll
  1 sibling, 2 replies; 10+ messages in thread
From: Peter Zijlstra @ 2014-06-17 12:13 UTC (permalink / raw)
  To: Pawel Moll
  Cc: Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Drew Richardson

[-- Attachment #1: Type: text/plain, Size: 1052 bytes --]

On Fri, Jun 13, 2014 at 04:03:32PM +0100, Pawel Moll wrote:
> 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>
> ---

This gets me (on my favourite x86_64 .config):

kernel/events/core.c: In function ‘perf_compat_ioctl’:
kernel/events/core.c:3726:32: error: ‘compat_uptr_t’ undeclared (first use in this function)
kernel/events/core.c:3726:32: note: each undeclared identifier is reported only once for each function it appears in


[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2] perf: Handle compat ioctl
  2014-06-17 12:13 ` Peter Zijlstra
@ 2014-06-17 12:43   ` Pawel Moll
  2014-07-01 16:06     ` Pawel Moll
  2014-06-17 13:19   ` [PATCH] " Pawel Moll
  1 sibling, 1 reply; 10+ messages in thread
From: Pawel Moll @ 2014-06-17 12:43 UTC (permalink / raw)
  To: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Drew Richardson, Pawel Moll

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>
---
 kernel/events/core.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

Changes from v1:
- added missing #include

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 5fa58e4..f081335 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -40,6 +40,7 @@
 #include <linux/mm_types.h>
 #include <linux/cgroup.h>
 #include <linux/module.h>
+#include <linux/compat.h>
 
 #include "internal.h"
 
@@ -3716,6 +3717,26 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	return 0;
 }
 
+#ifdef CONFIG_COMPAT
+static long perf_compat_ioctl(struct file *file, unsigned int cmd,
+				unsigned long arg)
+{
+	switch (_IOC_NR(cmd)) {
+	case _IOC_NR(PERF_EVENT_IOC_SET_FILTER):
+	case _IOC_NR(PERF_EVENT_IOC_ID):
+		/* Fix up pointer size (usually 4 -> 8 in 32-on-64-bit case */
+		if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) {
+			cmd &= ~IOCSIZE_MASK;
+			cmd |= sizeof(void *) << IOCSIZE_SHIFT;
+		}
+		break;
+	}
+	return perf_ioctl(file, cmd, arg);
+}
+#else
+#define perf_compat_ioctl NULL
+#endif
+
 int perf_event_task_enable(void)
 {
 	struct perf_event *event;
@@ -4221,7 +4242,7 @@ static const struct file_operations perf_fops = {
 	.read			= perf_read,
 	.poll			= perf_poll,
 	.unlocked_ioctl		= perf_ioctl,
-	.compat_ioctl		= perf_ioctl,
+	.compat_ioctl		= perf_compat_ioctl,
 	.mmap			= perf_mmap,
 	.fasync			= perf_fasync,
 };
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] perf: Handle compat ioctl
  2014-06-17 12:13 ` Peter Zijlstra
  2014-06-17 12:43   ` [PATCH v2] " Pawel Moll
@ 2014-06-17 13:19   ` Pawel Moll
  1 sibling, 0 replies; 10+ messages in thread
From: Pawel Moll @ 2014-06-17 13:19 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Drew Richardson

On Tue, 2014-06-17 at 13:13 +0100, Peter Zijlstra wrote:
> On Fri, Jun 13, 2014 at 04:03:32PM +0100, Pawel Moll wrote:
> > 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>
> > ---
> 
> This gets me (on my favourite x86_64 .config):
> 
> kernel/events/core.c: In function ‘perf_compat_ioctl’:
> kernel/events/core.c:3726:32: error: ‘compat_uptr_t’ undeclared (first use in this function)
> kernel/events/core.c:3726:32: note: each undeclared identifier is reported only once for each function it appears in

Right, sorry. I've added the size check last minute and haven't
re-tested it with x86_64. #include for compat.h was missing (wonder
where was it included for arm64 ;-)

Already posted v2.

Pawel


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] perf: Handle compat ioctl
  2014-06-17 12:43   ` [PATCH v2] " Pawel Moll
@ 2014-07-01 16:06     ` Pawel Moll
  2014-07-07 12:43       ` Peter Zijlstra
  0 siblings, 1 reply; 10+ messages in thread
From: Pawel Moll @ 2014-07-01 16:06 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Drew Richardson

On Tue, 2014-06-17 at 13:43 +0100, Pawel Moll wrote:
> 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>

This just is a polite and friendly nag...

Any, strong or not, opinions on the matter?

Cheers!

Pawel


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] perf: Handle compat ioctl
  2014-07-01 16:06     ` Pawel Moll
@ 2014-07-07 12:43       ` Peter Zijlstra
  2014-08-14 10:17         ` Pawel Moll
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Zijlstra @ 2014-07-07 12:43 UTC (permalink / raw)
  To: Pawel Moll
  Cc: Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Drew Richardson

[-- Attachment #1: Type: text/plain, Size: 995 bytes --]

On Tue, Jul 01, 2014 at 05:06:00PM +0100, Pawel Moll wrote:
> On Tue, 2014-06-17 at 13:43 +0100, Pawel Moll wrote:
> > 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>
> 
> This just is a polite and friendly nag...
> 
> Any, strong or not, opinions on the matter?

Sorry, travel, cracks, falling, etc..

Queued it, we'll see what happens with this one ;-)

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] perf: Handle compat ioctl
  2014-07-07 12:43       ` Peter Zijlstra
@ 2014-08-14 10:17         ` Pawel Moll
  2014-08-14 10:51           ` Peter Zijlstra
  0 siblings, 1 reply; 10+ messages in thread
From: Pawel Moll @ 2014-08-14 10:17 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Drew Richardson

On Mon, 2014-07-07 at 13:43 +0100, Peter Zijlstra wrote:
> On Tue, Jul 01, 2014 at 05:06:00PM +0100, Pawel Moll wrote:
> > On Tue, 2014-06-17 at 13:43 +0100, Pawel Moll wrote:
> > > 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>
> > 
> > This just is a polite and friendly nag...
> > 
> > Any, strong or not, opinions on the matter?
> 
> Sorry, travel, cracks, falling, etc..
> 
> Queued it, we'll see what happens with this one ;-)

Has it managed to hold on to the ground between the cracks then? ;-)

(asking because can't see it in your perf/core branch on git.kernel.org)

Pawel


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] perf: Handle compat ioctl
  2014-08-14 10:17         ` Pawel Moll
@ 2014-08-14 10:51           ` Peter Zijlstra
  2014-08-14 12:25             ` Pawel Moll
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Zijlstra @ 2014-08-14 10:51 UTC (permalink / raw)
  To: Pawel Moll
  Cc: Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Drew Richardson

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

On Thu, Aug 14, 2014 at 11:17:48AM +0100, Pawel Moll wrote:
> Has it managed to hold on to the ground between the cracks then? ;-)
> 
> (asking because can't see it in your perf/core branch on git.kernel.org)

Damn this patch is cursed; I've no idea where it went. Lemme stick it in
perf/urgent, this is ridiculous.

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] perf: Handle compat ioctl
  2014-08-14 10:51           ` Peter Zijlstra
@ 2014-08-14 12:25             ` Pawel Moll
  0 siblings, 0 replies; 10+ messages in thread
From: Pawel Moll @ 2014-08-14 12:25 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Drew Richardson

On Thu, 2014-08-14 at 11:51 +0100, Peter Zijlstra wrote:
> On Thu, Aug 14, 2014 at 11:17:48AM +0100, Pawel Moll wrote:
> > Has it managed to hold on to the ground between the cracks then? ;-)
> > 
> > (asking because can't see it in your perf/core branch on git.kernel.org)
> 
> Damn this patch is cursed;

So it seems :-)

>  I've no idea where it went. Lemme stick it in
> perf/urgent, this is ridiculous.

... but it was supposed to be v2, not v1 ;-) as v1 was missing an
include...

8<------------------------------------------------
>From 0ce6aa357790a3423751954d7f094cc53871cc72 Mon Sep 17 00:00:00 2001
From: Pawel Moll <pawel.moll@arm.com>
Date: Thu, 14 Aug 2014 13:25:07 +0100
Subject: [PATCH] perf: Add missing compat header

Patch 783c1428fa91798090a0ace57f35e9a72646088f "perf:
Handle compat ioctl" is using a type defined in compat.h
header, but wasn't including it. Fixed now.

Signed-off-by: Pawel Moll <pawel.moll@arm.com>
---
 kernel/events/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 2c5cbda..cc7065c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -41,6 +41,7 @@
 #include <linux/cgroup.h>
 #include <linux/module.h>
 #include <linux/mman.h>
+#include <linux/compat.h>
 
 #include "internal.h"
 
-- 
1.9.1




^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [tip:perf/urgent] perf: Handle compat ioctl
  2014-06-13 15:03 [PATCH] perf: Handle compat ioctl Pawel Moll
  2014-06-17 12:13 ` Peter Zijlstra
@ 2014-08-20  8:18 ` tip-bot for Pawel Moll
  1 sibling, 0 replies; 10+ messages in thread
From: tip-bot for Pawel Moll @ 2014-08-20  8:18 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, peterz, drew.richardson, acme, jolsa,
	pawel.moll, tglx

Commit-ID:  b3f207855f57b9c8f43a547a801340bb5cbc59e5
Gitweb:     http://git.kernel.org/tip/b3f207855f57b9c8f43a547a801340bb5cbc59e5
Author:     Pawel Moll <pawel.moll@arm.com>
AuthorDate: Fri, 13 Jun 2014 16:03:32 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 20 Aug 2014 09:42:13 +0200

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>
---
 kernel/events/core.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 1cf24b3..f9c1ed0 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -41,6 +41,7 @@
 #include <linux/cgroup.h>
 #include <linux/module.h>
 #include <linux/mman.h>
+#include <linux/compat.h>
 
 #include "internal.h"
 
@@ -3717,6 +3718,26 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	return 0;
 }
 
+#ifdef CONFIG_COMPAT
+static long perf_compat_ioctl(struct file *file, unsigned int cmd,
+				unsigned long arg)
+{
+	switch (_IOC_NR(cmd)) {
+	case _IOC_NR(PERF_EVENT_IOC_SET_FILTER):
+	case _IOC_NR(PERF_EVENT_IOC_ID):
+		/* Fix up pointer size (usually 4 -> 8 in 32-on-64-bit case */
+		if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) {
+			cmd &= ~IOCSIZE_MASK;
+			cmd |= sizeof(void *) << IOCSIZE_SHIFT;
+		}
+		break;
+	}
+	return perf_ioctl(file, cmd, arg);
+}
+#else
+# define perf_compat_ioctl NULL
+#endif
+
 int perf_event_task_enable(void)
 {
 	struct perf_event *event;
@@ -4222,7 +4243,7 @@ static const struct file_operations perf_fops = {
 	.read			= perf_read,
 	.poll			= perf_poll,
 	.unlocked_ioctl		= perf_ioctl,
-	.compat_ioctl		= perf_ioctl,
+	.compat_ioctl		= perf_compat_ioctl,
 	.mmap			= perf_mmap,
 	.fasync			= perf_fasync,
 };

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-08-20  8:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-13 15:03 [PATCH] perf: Handle compat ioctl Pawel Moll
2014-06-17 12:13 ` Peter Zijlstra
2014-06-17 12:43   ` [PATCH v2] " Pawel Moll
2014-07-01 16:06     ` Pawel Moll
2014-07-07 12:43       ` Peter Zijlstra
2014-08-14 10:17         ` Pawel Moll
2014-08-14 10:51           ` Peter Zijlstra
2014-08-14 12:25             ` Pawel Moll
2014-06-17 13:19   ` [PATCH] " Pawel Moll
2014-08-20  8:18 ` [tip:perf/urgent] " tip-bot for Pawel Moll

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.