Skip to contentSkip to conversation

drm: Only use DRM_IOCTL_UPDATE_DRAW compat wrapper for compat X86.

PATCH In review David Miller 3 participants 5 messages Feb 18, 2009 – Feb 20, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: Only use DRM_IOCTL_UPDATE_DRAW compat wrapper for compat X86.

Ben, I'm pretty sure you're hitting this too on powerpc. Every time a 32-bit process tries to upload cliprects it's going to fail with -EFAULT or similar.

Nothing in userspace checks the return value for errors, etc. :-/

The only reason I caught this is because I have a debugging check on sparc64 that makes sure that faults on kernel accesses to 32-bit userspace never have any of the high 32-bits set.

--------------------

drm: Only use DRM_IOCTL_UPDATE_DRAW compat wrapper for compat X86.

Only X86 32-bit uses a different alignment for "unsigned long long" than it's 64-bit counterpart.

Therefore this compat translation is only correct, and only needed, when either CONFIG_X86 or CONFIG_IA64.

---
 drivers/gpu/drm/drm_ioc32.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_ioc32.c +4 -0
index 920b72f..282d9fd 100644
@@ -954,6 +954,7 @@ static int compat_drm_sg_free(struct file *file, unsigned int cmd,
 			 DRM_IOCTL_SG_FREE, (unsigned long)request);
 }
 
+#if defined(CONFIG_X86) || defined(CONFIG_IA64)
 typedef struct drm_update_draw32 {
 	drm_drawable_t handle;
 	unsigned int type;
@@ -984,6 +985,7 @@ static int compat_drm_update_draw(struct file *file, unsigned int cmd,
 			DRM_IOCTL_UPDATE_DRAW, (unsigned long)request);
 	return err;
 }
+#endif
 
 struct drm_wait_vblank_request32 {
 	enum drm_vblank_seq_type type;
@@ -1066,7 +1068,9 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
 #endif
 	[DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC32)] = compat_drm_sg_alloc,
 	[DRM_IOCTL_NR(DRM_IOCTL_SG_FREE32)] = compat_drm_sg_free,
+#if defined(CONFIG_X86) || defined(CONFIG_IA64)
 	[DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW32)] = compat_drm_update_draw,
+#endif
 	[DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32)] = compat_drm_wait_vblank,
 };
 
Signature · 1 line
1.6.1.2.350.g88cc
#1 lore raw
Quoted 3 lines · David Miller

Ben, I'm pretty sure you're hitting this too on powerpc. Every time a 32-bit process tries to upload cliprects it's going to fail with -EFAULT or similar.

Heh, quite possibly

Could that be related to the kernel spewing a bunch of

[drm:drm_update_drawable_info] *ERROR* Failed to copy cliprects from userspace

?

I've seen that yesterday on the Bimini, was planning to dig today until I got stuck home with a cold...

Quoted 1 line

Nothing in userspace checks the return value for errors, etc. :-/

Surprise !

Quoted 3 lines

The only reason I caught this is because I have a debugging check on sparc64 that makes sure that faults on kernel accesses to 32-bit userspace never have any of the high 32-bits set.

That's a nice trick, I might do something similar on power..

Cheers,
Ben.

Quoted 45 lines

--------------------

drm: Only use DRM_IOCTL_UPDATE_DRAW compat wrapper for compat X86.

Only X86 32-bit uses a different alignment for "unsigned long long" than it's 64-bit counterpart.

Therefore this compat translation is only correct, and only needed, when either CONFIG_X86 or CONFIG_IA64.

---
 drivers/gpu/drm/drm_ioc32.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_ioc32.c +4 -0
index 920b72f..282d9fd 100644
@@ -954,6 +954,7 @@ static int compat_drm_sg_free(struct file *file, unsigned int cmd,
 			 DRM_IOCTL_SG_FREE, (unsigned long)request);
 }
 
+#if defined(CONFIG_X86) || defined(CONFIG_IA64)
 typedef struct drm_update_draw32 {
 	drm_drawable_t handle;
 	unsigned int type;
@@ -984,6 +985,7 @@ static int compat_drm_update_draw(struct file *file, unsigned int cmd,
 			DRM_IOCTL_UPDATE_DRAW, (unsigned long)request);
 	return err;
 }
+#endif
 
 struct drm_wait_vblank_request32 {
 	enum drm_vblank_seq_type type;
@@ -1066,7 +1068,9 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
 #endif
 	[DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC32)] = compat_drm_sg_alloc,
 	[DRM_IOCTL_NR(DRM_IOCTL_SG_FREE32)] = compat_drm_sg_free,
+#if defined(CONFIG_X86) || defined(CONFIG_IA64)
 	[DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW32)] = compat_drm_update_draw,
+#endif
 	[DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32)] = compat_drm_wait_vblank,
 };
 
#2 lore raw

From: Benjamin Herrenschmidt <[email protected]>
Date: Thu, 19 Feb 2009 08:59:50 +1100

Quoted 3 lines

Could that be related to the kernel spewing a bunch of

[drm:drm_update_drawable_info] *ERROR* Failed to copy cliprects from userspace

Yep, that is exactly caused by this bug.

#3 lore raw
In reply to David Miller
Quoted 9 lines · David Miller

drm: Only use DRM_IOCTL_UPDATE_DRAW compat wrapper for compat X86.

Only X86 32-bit uses a different alignment for "unsigned long long" than it's 64-bit counterpart.

Therefore this compat translation is only correct, and only needed, when either CONFIG_X86 or CONFIG_IA64.

The patch is correct AFAICT, but I'd like to point out that the problem could have been avoided (besides using a non-padded layout) by using a compat_u64 member in the struct definition instead of the packed attribute:

typedef struct drm_update_draw32 {
	drm_drawable_t handle;
	unsigned int type;
	unsigned int num;
	compat_u64 data;	/**< Pointer */
} drm_update_draw32_t;

I find that too often __attribute__((packed)) is used on whole structures where some other much more gentle solution can be applied. In fact, there are very few files (e.g. linux/unaligned/packed_struct.h) that look like they want all of the implied meanings (pack members, drop alignment on whole structure, access members as unaligned).

A grep for "packed" in compat_ioctl definitions revealed the same bug as in drm_update_draw32 to be present in raw32_config_request, and I'm rather sure that there are more of these.

	Arnd <><
#4 lore raw

From: Arnd Bergmann <[email protected]>
Date: Thu, 19 Feb 2009 15:19:01 +0100

Quoted 9 lines · David Miller
Quoted 8 lines

drm: Only use DRM_IOCTL_UPDATE_DRAW compat wrapper for compat X86.

Only X86 32-bit uses a different alignment for "unsigned long long" than it's 64-bit counterpart.

Therefore this compat translation is only correct, and only needed, when either CONFIG_X86 or CONFIG_IA64.

Quoted 6 lines
Quoted 1 line

The patch is correct AFAICT, but I'd like to point out that the problem could have been avoided (besides using a non-padded layout) by using a compat_u64 member in the struct definition instead of the packed attribute:

Indeed, David A. showed me compat_u64 et al. and I'm fine with it being fixed that way too. Feel free to submit a patch :)