From: "Jan Beulich" Subject: [PATCH] linux/privcmd: fix for proper operation in compat mode Date: Tue, 05 Jan 2010 12:52:04 +0000 Message-ID: <4B4344040200007800028412@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartB19BB4E4.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartB19BB4E4.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline - sizeof(struct privcmd_mmapbatch_32) was wrong - MFN array must be translated for IOCTL_PRIVCMD_MMAPBATCH Also, the error indicator of IOCTL_PRIVCMD_MMAPBATCH should be in the top nibble (it is documented that way in include/xen/public/privcmd.h and include/xen/compat_ioctl.h), but since that is an incompatible change it is not being done here (instead, a new ioctl with proper behavior will need to be added). As usual, written against 2.6.32.2 and made apply to the 2.6.18 tree without further testing. Signed-off-by: Jan Beulich --- head-2010-01-04.orig/drivers/xen/privcmd/compat_privcmd.c 2009-11-06 = 10:45:48.000000000 +0100 +++ head-2010-01-04/drivers/xen/privcmd/compat_privcmd.c 2010-01-04 = 13:50:00.000000000 +0100 @@ -51,17 +51,49 @@ int privcmd_ioctl_32(int fd, unsigned in struct privcmd_mmapbatch *p; struct privcmd_mmapbatch_32 *p32; struct privcmd_mmapbatch_32 n32; +#ifdef xen_pfn32_t + xen_pfn_t *__user arr; + xen_pfn32_t *__user arr32; + unsigned int i; +#endif =20 p32 =3D compat_ptr(arg); p =3D compat_alloc_user_space(sizeof(*p)); if (copy_from_user(&n32, p32, sizeof(n32)) || put_user(n32.num, &p->num) || put_user(n32.dom, &p->dom) || - put_user(n32.addr, &p->addr) || - put_user(compat_ptr(n32.arr), &p->arr)) + put_user(n32.addr, &p->addr)) return -EFAULT; +#ifdef xen_pfn32_t + arr =3D compat_alloc_user_space(n32.num * sizeof(*arr) + + sizeof(*p)); + arr32 =3D compat_ptr(n32.arr); + for (i =3D 0; i < n32.num; ++i) { + xen_pfn32_t mfn; + + if (get_user(mfn, arr32 + i) || put_user(mfn, arr = + i)) + return -EFAULT; + } + + if (put_user(arr, &p->arr)) + return -EFAULT; +#else + if (put_user(compat_ptr(n32.arr), &p->arr)) + return -EFAULT; +#endif =09 ret =3D sys_ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, (unsigned = long)p); + +#ifdef xen_pfn32_t + for (i =3D 0; !ret && i < n32.num; ++i) { + xen_pfn_t mfn; + + if (get_user(mfn, arr + i) || put_user(mfn, arr32 = + i)) + ret =3D -EFAULT; + else if (mfn !=3D (xen_pfn32_t)mfn) + ret =3D -ERANGE; + } +#endif } break; default: --- head-2010-01-04.orig/include/xen/compat_ioctl.h 2007-07-10 = 09:42:30.000000000 +0200 +++ head-2010-01-04/include/xen/compat_ioctl.h 2009-12-17 15:40:40.0000000= 00 +0100 @@ -23,6 +23,11 @@ #define __LINUX_XEN_COMPAT_H__=20 =20 #include +#include + +#if defined(CONFIG_X86) || defined(CONFIG_IA64) +#define xen_pfn32_t __u32 +#endif =20 extern int privcmd_ioctl_32(int fd, unsigned int cmd, unsigned long arg); struct privcmd_mmap_32 { @@ -34,7 +39,14 @@ struct privcmd_mmap_32 { struct privcmd_mmapbatch_32 { int num; /* number of pages to populate */ domid_t dom; /* target domain */ +#if defined(CONFIG_X86) || defined(CONFIG_IA64) + union { /* virtual address */ + __u64 addr __packed; + __u32 va; + }; +#else __u64 addr; /* virtual address */ +#endif compat_uptr_t arr; /* array of mfns - top nibble set on err */ }; #define IOCTL_PRIVCMD_MMAP_32 \ --=__PartB19BB4E4.0__= Content-Type: text/plain; name="xenlinux-privcmd-compat.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xenlinux-privcmd-compat.patch" Subject: privcmd: fix for proper operation in compat mode=0A=0A- sizeof(str= uct privcmd_mmapbatch_32) was wrong=0A- MFN array must be translated for = IOCTL_PRIVCMD_MMAPBATCH=0A=0AAlso, the error indicator of IOCTL_PRIVCMD_MMA= PBATCH should be in the=0Atop nibble (it is documented that way in = include/xen/public/privcmd.h=0Aand include/xen/compat_ioctl.h), but since = that is an incompatible=0Achange it is not being done here (instead, a new = ioctl with proper=0Abehavior will need to be added).=0A=0AAs usual, = written against 2.6.32.2 and made apply to the 2.6.18=0Atree without = further testing.=0A=0ASigned-off-by: Jan Beulich =0A= =0A--- head-2010-01-04.orig/drivers/xen/privcmd/compat_privcmd.c = 2009-11-06 10:45:48.000000000 +0100=0A+++ head-2010-01-04/drivers/xen/privc= md/compat_privcmd.c 2010-01-04 13:50:00.000000000 +0100=0A@@ -51,17 = +51,49 @@ int privcmd_ioctl_32(int fd, unsigned in=0A struct = privcmd_mmapbatch *p;=0A struct privcmd_mmapbatch_32 = *p32;=0A struct privcmd_mmapbatch_32 n32;=0A+#ifdef = xen_pfn32_t=0A+ xen_pfn_t *__user arr;=0A+ xen_pfn32_t= *__user arr32;=0A+ unsigned int i;=0A+#endif=0A =0A = p32 =3D compat_ptr(arg);=0A p =3D compat_alloc_user_space(sizeo= f(*p));=0A if (copy_from_user(&n32, p32, sizeof(n32)) ||=0A = put_user(n32.num, &p->num) ||=0A put_user(n32.do= m, &p->dom) ||=0A- put_user(n32.addr, &p->addr) ||=0A- = put_user(compat_ptr(n32.arr), &p->arr))=0A+ put_user(n32.ad= dr, &p->addr))=0A return -EFAULT;=0A+#ifdef = xen_pfn32_t=0A+ arr =3D compat_alloc_user_space(n32.num * = sizeof(*arr)=0A+ + sizeof(*p))= ;=0A+ arr32 =3D compat_ptr(n32.arr);=0A+ for (i =3D = 0; i < n32.num; ++i) {=0A+ xen_pfn32_t mfn;=0A+=0A+ = if (get_user(mfn, arr32 + i) || put_user(mfn, arr + = i))=0A+ return -EFAULT;=0A+ }=0A+=0A+ = if (put_user(arr, &p->arr))=0A+ return -EFAULT;=0A+= #else=0A+ if (put_user(compat_ptr(n32.arr), &p->arr))=0A+ = return -EFAULT;=0A+#endif=0A =0A ret =3D = sys_ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, (unsigned long)p);=0A+=0A+#ifdef = xen_pfn32_t=0A+ for (i =3D 0; !ret && i < n32.num; ++i) {=0A+ = xen_pfn_t mfn;=0A+=0A+ if (get_user(mfn, arr + i) = || put_user(mfn, arr32 + i))=0A+ ret =3D = -EFAULT;=0A+ else if (mfn !=3D (xen_pfn32_t)mfn)=0A+ = ret =3D -ERANGE;=0A+ }=0A+#endif=0A }=0A = break;=0A default:=0A--- head-2010-01-04.orig/include/xen/compat_ioct= l.h 2007-07-10 09:42:30.000000000 +0200=0A+++ head-2010-01-04/include/x= en/compat_ioctl.h 2009-12-17 15:40:40.000000000 +0100=0A@@ -23,6 = +23,11 @@=0A #define __LINUX_XEN_COMPAT_H__ =0A =0A #include =0A+#include =0A+=0A+#if defined(CONFIG_X86) || = defined(CONFIG_IA64)=0A+#define xen_pfn32_t __u32=0A+#endif=0A =0A extern = int privcmd_ioctl_32(int fd, unsigned int cmd, unsigned long arg);=0A = struct privcmd_mmap_32 {=0A@@ -34,7 +39,14 @@ struct privcmd_mmap_32 {=0A = struct privcmd_mmapbatch_32 {=0A int num; /* number of pages to = populate */=0A domid_t dom; /* target domain */=0A+#if defined(CONFIG_X86)= || defined(CONFIG_IA64)=0A+ union { /* virtual address */=0A+ = __u64 addr __packed;=0A+ __u32 va;=0A+ };=0A+#else=0A = __u64 addr; /* virtual address */=0A+#endif=0A compat_uptr_t arr; = /* array of mfns - top nibble set on err */=0A };=0A #define IOCTL_PRIVCMD_= MMAP_32 \=0A --=__PartB19BB4E4.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartB19BB4E4.0__=--