From: "Jan Beulich" Subject: [PATCH] vNUMA: validate XEN_DOMCTL_setvnumainfo input Date: Tue, 03 Mar 2015 14:38:19 +0000 Message-ID: <54F5D56B0200007800065BB9@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part4570E94B.2__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YSnxx-0006vW-KD for xen-devel@lists.xenproject.org; Tue, 03 Mar 2015 14:38:33 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Keir Fraser , Tim Deegan , Dario Faggioli , Ian Jackson , Ian Campbell , Wei Liu 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. --=__Part4570E94B.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline As we get ready to use the information set for a domain here we should make sure it is actually valid: Both vNode and pNode numbers should be in range. Do a little bit of other cleanup so the code ends up looking reasonably consistent in style. Along with this goes that we don't need an array of unsigned int to store the pNode number - a nodeid_t one (a quarter the size) suffices. Signed-off-by: Jan Beulich --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -344,7 +344,7 @@ static struct vnuma_info *vnuma_alloc(un =20 vnuma->vdistance =3D xmalloc_array(unsigned int, nr_vnodes * = nr_vnodes); vnuma->vcpu_to_vnode =3D xmalloc_array(unsigned int, nr_vcpus); - vnuma->vnode_to_pnode =3D xmalloc_array(unsigned int, nr_vnodes); + vnuma->vnode_to_pnode =3D xmalloc_array(nodeid_t, nr_vnodes); vnuma->vmemrange =3D xmalloc_array(xen_vmemrange_t, nr_ranges); =20 if ( vnuma->vdistance =3D=3D NULL || vnuma->vmemrange =3D=3D NULL || @@ -382,30 +382,40 @@ static struct vnuma_info *vnuma_init(con nr_vnodes * nr_vnodes) ) goto vnuma_fail; =20 + if ( copy_from_guest(info->vmemrange, uinfo->vmemrange, + uinfo->nr_vmemranges) ) + goto vnuma_fail; + if ( copy_from_guest(info->vcpu_to_vnode, uinfo->vcpu_to_vnode, d->max_vcpus) ) goto vnuma_fail; =20 - if ( copy_from_guest(info->vnode_to_pnode, uinfo->vnode_to_pnode, - nr_vnodes) ) - goto vnuma_fail; + ret =3D -E2BIG; + for ( i =3D 0; i < d->max_vcpus; ++i ) + if ( info->vcpu_to_vnode[i] >=3D nr_vnodes ) + goto vnuma_fail; =20 - if (copy_from_guest(info->vmemrange, uinfo->vmemrange, - uinfo->nr_vmemranges)) - goto vnuma_fail; + for ( i =3D 0; i < nr_vnodes; ++i ) + { + unsigned int pnode; + + ret =3D -EFAULT; + if ( copy_from_guest_offset(&pnode, uinfo->vnode_to_pnode, i, 1) = ) + goto vnuma_fail; + ret =3D -E2BIG; + if ( pnode >=3D MAX_NUMNODES ) + goto vnuma_fail; + info->vnode_to_pnode[i] =3D pnode; + } =20 info->nr_vnodes =3D nr_vnodes; info->nr_vmemranges =3D uinfo->nr_vmemranges; =20 /* Check that vmemranges flags are zero. */ + ret =3D -EINVAL; for ( i =3D 0; i < info->nr_vmemranges; i++ ) - { if ( info->vmemrange[i].flags !=3D 0 ) - { - ret =3D -EINVAL; goto vnuma_fail; - } - } =20 return info; =20 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -4,6 +4,7 @@ =20 #include #include +#include =20 typedef union { struct vcpu_guest_context *nat; @@ -99,7 +100,7 @@ struct vnuma_info { unsigned int nr_vmemranges; unsigned int *vdistance; unsigned int *vcpu_to_vnode; - unsigned int *vnode_to_pnode; + nodeid_t *vnode_to_pnode; struct xen_vmemrange *vmemrange; }; =20 --=__Part4570E94B.2__= Content-Type: text/plain; name="vNUMA-validate.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vNUMA-validate.patch" vNUMA: validate XEN_DOMCTL_setvnumainfo input=0A=0AAs we get ready to use = the information set for a domain here we should=0Amake sure it is actually = valid: Both vNode and pNode numbers should be=0Ain range. Do a little bit = of other cleanup so the code ends up looking=0Areasonably consistent in = style.=0A=0AAlong with this goes that we don't need an array of unsigned = int to=0Astore the pNode number - a nodeid_t one (a quarter the size) = suffices.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/common/domctl.c=0A+++ b/xen/common/domctl.c=0A@@ -344,7 +344,7 @@ = static struct vnuma_info *vnuma_alloc(un=0A =0A vnuma->vdistance =3D = xmalloc_array(unsigned int, nr_vnodes * nr_vnodes);=0A vnuma->vcpu_to_v= node =3D xmalloc_array(unsigned int, nr_vcpus);=0A- vnuma->vnode_to_pnod= e =3D xmalloc_array(unsigned int, nr_vnodes);=0A+ vnuma->vnode_to_pnode = =3D xmalloc_array(nodeid_t, nr_vnodes);=0A vnuma->vmemrange =3D = xmalloc_array(xen_vmemrange_t, nr_ranges);=0A =0A if ( vnuma->vdistance= =3D=3D NULL || vnuma->vmemrange =3D=3D NULL ||=0A@@ -382,30 +382,40 @@ = static struct vnuma_info *vnuma_init(con=0A = nr_vnodes * nr_vnodes) )=0A goto vnuma_fail;=0A =0A+ if ( = copy_from_guest(info->vmemrange, uinfo->vmemrange,=0A+ = uinfo->nr_vmemranges) )=0A+ goto vnuma_fail;=0A+=0A if ( = copy_from_guest(info->vcpu_to_vnode, uinfo->vcpu_to_vnode,=0A = d->max_vcpus) )=0A goto vnuma_fail;=0A =0A- if ( = copy_from_guest(info->vnode_to_pnode, uinfo->vnode_to_pnode,=0A- = nr_vnodes) )=0A- goto vnuma_fail;=0A+ ret =3D = -E2BIG;=0A+ for ( i =3D 0; i < d->max_vcpus; ++i )=0A+ if ( = info->vcpu_to_vnode[i] >=3D nr_vnodes )=0A+ goto vnuma_fail;=0A = =0A- if (copy_from_guest(info->vmemrange, uinfo->vmemrange,=0A- = uinfo->nr_vmemranges))=0A- goto vnuma_fail;=0A+ = for ( i =3D 0; i < nr_vnodes; ++i )=0A+ {=0A+ unsigned int = pnode;=0A+=0A+ ret =3D -EFAULT;=0A+ if ( copy_from_guest_offs= et(&pnode, uinfo->vnode_to_pnode, i, 1) )=0A+ goto vnuma_fail;= =0A+ ret =3D -E2BIG;=0A+ if ( pnode >=3D MAX_NUMNODES )=0A+ = goto vnuma_fail;=0A+ info->vnode_to_pnode[i] =3D = pnode;=0A+ }=0A =0A info->nr_vnodes =3D nr_vnodes;=0A info->nr_v= memranges =3D uinfo->nr_vmemranges;=0A =0A /* Check that vmemranges = flags are zero. */=0A+ ret =3D -EINVAL;=0A for ( i =3D 0; i < = info->nr_vmemranges; i++ )=0A- {=0A if ( info->vmemrange[i].flag= s !=3D 0 )=0A- {=0A- ret =3D -EINVAL;=0A = goto vnuma_fail;=0A- }=0A- }=0A =0A return info;=0A =0A--- = a/xen/include/xen/domain.h=0A+++ b/xen/include/xen/domain.h=0A@@ -4,6 +4,7 = @@=0A =0A #include =0A #include =0A+#include = =0A =0A typedef union {=0A struct vcpu_guest_context = *nat;=0A@@ -99,7 +100,7 @@ struct vnuma_info {=0A unsigned int = nr_vmemranges;=0A unsigned int *vdistance;=0A unsigned int = *vcpu_to_vnode;=0A- unsigned int *vnode_to_pnode;=0A+ nodeid_t = *vnode_to_pnode;=0A struct xen_vmemrange *vmemrange;=0A };=0A =0A --=__Part4570E94B.2__= 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.xen.org http://lists.xen.org/xen-devel --=__Part4570E94B.2__=--