Re: [PATCH] Add 64-bit get_user and __get_user for i386
From: Jamie Lokier
Date: Mon Apr 19 2004 - 05:18:26 EST
Ignore the previous patch. It didn't include the access_ok() check in
64-bit get_user(). Use this instead.
Enjoy,
-- Jamie
Subject: [PATCH] Add 64-bit get_user and __get_user for i386
Patch: uaccess64-2.6.5-jl2
Add 64-bit get_user and __get_user for i386.
This time, include the access_ok() check.
Don't ask me how, but this shrinks the kernel too.
--- orig-2.6.5/include/asm-i386/uaccess.h 2003-12-18 02:58:16.000000000 +0000
+++ uaccess64-2.6.5/include/asm-i386/uaccess.h 2004-04-19 11:06:52.000000000 +0100
@@ -168,17 +168,19 @@
* Returns zero on success, or -EFAULT on error.
* On error, the variable @x is set to zero.
*/
-#define get_user(x,ptr) \
-({ int __ret_gu,__val_gu; \
- switch(sizeof (*(ptr))) { \
- case 1: __get_user_x(1,__ret_gu,__val_gu,ptr); break; \
- case 2: __get_user_x(2,__ret_gu,__val_gu,ptr); break; \
- case 4: __get_user_x(4,__ret_gu,__val_gu,ptr); break; \
- default: __get_user_x(X,__ret_gu,__val_gu,ptr); break; \
- } \
- (x) = (__typeof__(*(ptr)))__val_gu; \
- __ret_gu; \
-})
+#define get_user(x,ptr) \
+(sizeof (*(ptr)) == 8 ? (copy_from_user((void *)&(x),(ptr),8) ? -EFAULT : 0): \
+({ \
+ int __ret_gu,__val_gu; \
+ switch(sizeof (*(ptr))) { \
+ case 1: __get_user_x(1,__ret_gu,__val_gu,ptr); break; \
+ case 2: __get_user_x(2,__ret_gu,__val_gu,ptr); break; \
+ case 4: __get_user_x(4,__ret_gu,__val_gu,ptr); break; \
+ default: __get_user_bad(); break; \
+ } \
+ (x) = (__typeof__(*(ptr)))__val_gu; \
+ __ret_gu; \
+}))
extern void __put_user_bad(void);
@@ -333,13 +335,14 @@
: ltype (x), "m"(__m(addr)), "i"(errret), "0"(err))
-#define __get_user_nocheck(x,ptr,size) \
-({ \
- long __gu_err, __gu_val; \
- __get_user_size(__gu_val,(ptr),(size),__gu_err,-EFAULT);\
- (x) = (__typeof__(*(ptr)))__gu_val; \
- __gu_err; \
-})
+#define __get_user_nocheck(x,ptr,size) \
+((size) == 8 ? (__copy_from_user_ll((void *)&(x), (ptr), 8) ? -EFAULT : 0) : \
+({ \
+ long __gu_err, __gu_val; \
+ __get_user_size(__gu_val,(ptr),(size),__gu_err,-EFAULT); \
+ (x) = (__typeof__(*(ptr)))__gu_val; \
+ __gu_err; \
+}))
extern long __get_user_bad(void);
>
> Enjoy,
> -- Jamie
>
> Subject: [PATCH] Add 64-bit get_user and __get_user for i386
> Patch: uaccess64-2.6.5
>
> Add 64-bit get_user and __get_user for i386.
> Don't ask me how, but this shrinks the kernel too.
>
> --- orig-2.6.5/include/asm-i386/uaccess.h 2003-12-18 02:58:16.000000000 +0000
> +++ uaccess64-2.6.5/include/asm-i386/uaccess.h 2004-04-19 10:33:20.000000000 +0100
> @@ -169,16 +169,19 @@
> * On error, the variable @x is set to zero.
> */
> #define get_user(x,ptr) \
> -({ int __ret_gu,__val_gu; \
> +(sizeof (*(ptr)) == 8 \
> + ? (__copy_from_user_ll((void *)&(x), (ptr), 8) ? -EFAULT : 0) : \
> +({ \
> + int __ret_gu,__val_gu; \
> switch(sizeof (*(ptr))) { \
> case 1: __get_user_x(1,__ret_gu,__val_gu,ptr); break; \
> case 2: __get_user_x(2,__ret_gu,__val_gu,ptr); break; \
> case 4: __get_user_x(4,__ret_gu,__val_gu,ptr); break; \
> - default: __get_user_x(X,__ret_gu,__val_gu,ptr); break; \
> + default: __get_user_bad(); break; \
> } \
> (x) = (__typeof__(*(ptr)))__val_gu; \
> __ret_gu; \
> -})
> +}))
>
> extern void __put_user_bad(void);
>
> @@ -333,13 +336,14 @@
> : ltype (x), "m"(__m(addr)), "i"(errret), "0"(err))
>
>
> -#define __get_user_nocheck(x,ptr,size) \
> -({ \
> - long __gu_err, __gu_val; \
> - __get_user_size(__gu_val,(ptr),(size),__gu_err,-EFAULT);\
> - (x) = (__typeof__(*(ptr)))__gu_val; \
> - __gu_err; \
> -})
> +#define __get_user_nocheck(x,ptr,size) \
> +((size) == 8 ? (__copy_from_user_ll((void *)&(x), (ptr), 8) ? -EFAULT : 0) : \
> +({ \
> + long __gu_err, __gu_val; \
> + __get_user_size(__gu_val,(ptr),(size),__gu_err,-EFAULT); \
> + (x) = (__typeof__(*(ptr)))__gu_val; \
> + __gu_err; \
> +}))
>
> extern long __get_user_bad(void);
>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/