>OTOH, extra checking rarely hurts and would be easy to add.
Here my take at it. This actually also replaces the patch sent under
the same subject yesterday, as I meanwhile realized there's a simpler
way to achieve the desired effect. It also converts the 64-bit store
to a 32-bit one, as only the upper 32 bits need clearing.
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>
Index: 2006-08-28/xen/include/public/arch-x86_32.h
===================================================================
--- 2006-08-28.orig/xen/include/public/arch-x86_32.h 2006-08-28
08:32:38.000000000 +0200
+++ 2006-08-28/xen/include/public/arch-x86_32.h 2006-08-29 11:15:44.000000000
+0200
@@ -29,11 +29,11 @@
/* Structural guest handles introduced in 0x00030201. */
#if (defined(__XEN__) || defined(__XEN_TOOLS__)) && !defined(__ASSEMBLY__)
-typedef uint64_t __attribute__((aligned(8))) uint64_aligned_t;
+#define uint64_aligned_t uint64_t __attribute__((__aligned__(8)))
#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
typedef struct { type *p; } \
__guest_handle_ ## name; \
- typedef struct { union { type *p; uint64_aligned_t q; }; } \
+ typedef struct { type *p __attribute__((__aligned__(8))); } \
__guest_handle_64_ ## name
#elif __XEN_INTERFACE_VERSION__ >= 0x00030201
#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
@@ -49,7 +49,7 @@ typedef uint64_t __attribute__((aligned(
#ifdef __XEN_TOOLS__
#define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0)
#define set_xen_guest_handle(hnd, val) \
- do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \
+ do { if ( sizeof(hnd) == 8 ) (&(hnd).p)[1] = NULL; \
(hnd).p = val; \
} while ( 0 )
#else
Index: 2006-08-28/xen/include/asm-x86/guest_access.h
===================================================================
--- 2006-08-28.orig/xen/include/asm-x86/guest_access.h 2006-08-07
09:07:03.000000000 +0200
+++ 2006-08-28/xen/include/asm-x86/guest_access.h 2006-08-29
11:52:57.000000000 +0200
@@ -17,6 +17,14 @@
/* Offset the given guest handle into the array it refers to. */
#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
+#if defined(__i386__)
+#define __guest_handle_okay(hnd) \
+ (sizeof(hnd) == sizeof((hnd).p) || \
+ (&(hnd).p)[1] == NULL)
+#elif defined(__x86_64__)
+#define __guest_handle_okay(hnd) ((void)(hnd), 1)
+#endif
+
/* Cast a guest handle to the specified type of handle. */
#define guest_handle_cast(hnd, type) ({ \
type *_x = (hnd).p; \
@@ -33,9 +41,11 @@
#define copy_to_guest_offset(hnd, off, ptr, nr) ({ \
const typeof(ptr) _x = (hnd).p; \
const typeof(ptr) _y = (ptr); \
+ __guest_handle_okay(hnd) ? \
hvm_guest(current) ? \
copy_to_user_hvm(_x+(off), _y, sizeof(*_x)*(nr)) : \
- copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \
+ copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)) : \
+ sizeof(*_x) * (nr); \
})
/*
@@ -45,27 +55,33 @@
#define copy_from_guest_offset(ptr, hnd, off, nr) ({ \
const typeof(ptr) _x = (hnd).p; \
const typeof(ptr) _y = (ptr); \
+ __guest_handle_okay(hnd) ? \
hvm_guest(current) ? \
copy_from_user_hvm(_y, _x+(off), sizeof(*_x)*(nr)) :\
- copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \
+ copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)) : \
+ sizeof(*_x) * (nr); \
})
/* Copy sub-field of a structure to guest context via a guest handle. */
#define copy_field_to_guest(hnd, ptr, field) ({ \
const typeof(&(ptr)->field) _x = &(hnd).p->field; \
const typeof(&(ptr)->field) _y = &(ptr)->field; \
+ __guest_handle_okay(hnd) ? \
hvm_guest(current) ? \
copy_to_user_hvm(_x, _y, sizeof(*_x)) : \
- copy_to_user(_x, _y, sizeof(*_x)); \
+ copy_to_user(_x, _y, sizeof(*_x)) : \
+ sizeof(*_x); \
})
/* Copy sub-field of a structure from guest context via a guest handle. */
#define copy_field_from_guest(ptr, hnd, field) ({ \
const typeof(&(ptr)->field) _x = &(hnd).p->field; \
const typeof(&(ptr)->field) _y = &(ptr)->field; \
+ __guest_handle_okay(hnd) ? \
hvm_guest(current) ? \
copy_from_user_hvm(_y, _x, sizeof(*_x)) : \
- copy_from_user(_y, _x, sizeof(*_x)); \
+ copy_from_user(_y, _x, sizeof(*_x)) : \
+ sizeof(*_x); \
})
/*
@@ -73,7 +89,9 @@
* Allows use of faster __copy_* functions.
*/
#define guest_handle_okay(hnd, nr) \
- (hvm_guest(current) || array_access_ok((hnd).p, (nr), sizeof(*(hnd).p)))
+ (__guest_handle_okay(hnd) && \
+ (hvm_guest(current) || \
+ array_access_ok((hnd).p, (nr), sizeof(*(hnd).p))))
#define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \
const typeof(ptr) _x = (hnd).p; \
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|