From: "Jan Beulich" Subject: [PATCH] linux-2.6.18: fix type inconsistency with xenbus_conn() Date: Fri, 01 Apr 2011 11:56:02 +0100 Message-ID: <4D95CB6202000078000399A5@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part4D619852.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. --=__Part4D619852.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Its (bogus) declaration in xenbus_dev.c was inconsistent with the actual implementation, leaving room for stack corruption on 64-bit systems. Thus move the declaration to a header included by both parties, and use proper types for the parameters. Additionally, the function is needed on privileged kernels only, and hence neither the potentially forward-incompatible HAVE_UNLOCKED_IOCTL conditionals in xenbus_dev.c are needed, nor does the function (and its helper) need to be compiled in unprivileged builds. Signed-off-by: Jan Beulich --- a/drivers/xen/xenbus/xenbus_comms.h +++ b/drivers/xen/xenbus/xenbus_comms.h @@ -59,4 +59,11 @@ static inline int is_xenstored_ready(voi return s =3D=3D XENBUS_XSD_FOREIGN_READY || s =3D=3D XENBUS_XSD_LOC= AL_READY; } =20 +#if defined(CONFIG_XEN_XENBUS_DEV) && defined(CONFIG_XEN_PRIVILEGED_GUEST)= +#include +#include + +int xenbus_conn(domid_t, grant_ref_t *, evtchn_port_t *); +#endif + #endif /* _XENBUS_COMMS_H */ --- a/drivers/xen/xenbus/xenbus_dev.c +++ b/drivers/xen/xenbus/xenbus_dev.c @@ -395,12 +395,10 @@ static unsigned int xenbus_dev_poll(stru return 0; } =20 -#ifdef HAVE_UNLOCKED_IOCTL +#ifdef CONFIG_XEN_PRIVILEGED_GUEST static long xenbus_dev_ioctl(struct file *file, unsigned int cmd, unsigned long data) { - extern int xenbus_conn(domid_t remote_dom, int *grant_ref, - evtchn_port_t *local_port); void __user *udata =3D (void __user *) data; int ret =3D -ENOTTY; =09 @@ -453,7 +451,7 @@ static const struct file_operations xenb .open =3D xenbus_dev_open, .release =3D xenbus_dev_release, .poll =3D xenbus_dev_poll, -#ifdef HAVE_UNLOCKED_IOCTL +#ifdef CONFIG_XEN_PRIVILEGED_GUEST .unlocked_ioctl =3D xenbus_dev_ioctl #endif }; --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -887,7 +887,8 @@ void xenbus_probe(struct work_struct *un } =20 =20 -#if defined(CONFIG_PROC_FS) && defined(CONFIG_XEN_PRIVILEGED_GUEST) +#ifdef CONFIG_XEN_PRIVILEGED_GUEST +#ifdef CONFIG_PROC_FS static struct file_operations xsd_kva_fops; static struct proc_dir_entry *xsd_kva_intf; static struct proc_dir_entry *xsd_port_intf; @@ -949,6 +950,7 @@ static int xsd_port_read(char *page, cha } #endif =20 +#ifdef CONFIG_XEN_XENBUS_DEV static int xb_free_port(evtchn_port_t port) { struct evtchn_close close; @@ -956,7 +958,8 @@ static int xb_free_port(evtchn_port_t po return HYPERVISOR_event_channel_op(EVTCHNOP_close, &close); } =20 -int xenbus_conn(domid_t remote_dom, unsigned long *grant_ref, evtchn_port_= t *local_port) +int xenbus_conn(domid_t remote_dom, grant_ref_t *grant_ref, + evtchn_port_t *local_port) { struct evtchn_alloc_unbound alloc_unbound; int rc, rc2; @@ -964,10 +967,8 @@ int xenbus_conn(domid_t remote_dom, unsi BUG_ON(atomic_read(&xenbus_xsd_state) !=3D XENBUS_XSD_FOREIGN_INIT)= ; BUG_ON(!is_initial_xendomain()); =20 -#if defined(CONFIG_PROC_FS) && defined(CONFIG_XEN_PRIVILEGED_GUEST) remove_xen_proc_entry("xsd_kva"); remove_xen_proc_entry("xsd_port"); -#endif =20 rc =3D xb_free_port(xen_store_evtchn); if (rc !=3D 0) @@ -1004,6 +1005,8 @@ fail0: xen_store_evtchn =3D -1; return rc; } +#endif +#endif /* CONFIG_XEN_PRIVILEGED_GUEST */ =20 static int xenbus_probe_init(void) { --=__Part4D619852.0__= Content-Type: text/plain; name="xen-xenbus_conn-type.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-xenbus_conn-type.patch" Its (bogus) declaration in xenbus_dev.c was inconsistent with the=0Aactual = implementation, leaving room for stack corruption on 64-bit=0Asystems. = Thus move the declaration to a header included by both=0Aparties, and use = proper types for the parameters.=0A=0AAdditionally, the function is needed = on privileged kernels only, and=0Ahence neither the potentially forward-inc= ompatible HAVE_UNLOCKED_IOCTL=0Aconditionals in xenbus_dev.c are needed, = nor does the function (and=0Aits helper) need to be compiled in unprivilege= d builds.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/drivers/xen/xenbus/xenbus_comms.h=0A+++ b/drivers/xen/xenbus/xenbus_comms= .h=0A@@ -59,4 +59,11 @@ static inline int is_xenstored_ready(voi=0A = return s =3D=3D XENBUS_XSD_FOREIGN_READY || s =3D=3D XENBUS_XSD_LOCAL_READY= ;=0A }=0A =0A+#if defined(CONFIG_XEN_XENBUS_DEV) && defined(CONFIG_XEN_PRIV= ILEGED_GUEST)=0A+#include =0A+#include = =0A+=0A+int xenbus_conn(domid_t, grant_ref_t = *, evtchn_port_t *);=0A+#endif=0A+=0A #endif /* _XENBUS_COMMS_H */=0A--- = a/drivers/xen/xenbus/xenbus_dev.c=0A+++ b/drivers/xen/xenbus/xenbus_dev.c= =0A@@ -395,12 +395,10 @@ static unsigned int xenbus_dev_poll(stru=0A = return 0;=0A }=0A =0A-#ifdef HAVE_UNLOCKED_IOCTL=0A+#ifdef CONFIG_XEN_PRIVI= LEGED_GUEST=0A static long xenbus_dev_ioctl(struct file *file,=0A = unsigned int cmd, unsigned long data)=0A {=0A- = extern int xenbus_conn(domid_t remote_dom, int *grant_ref,=0A- = evtchn_port_t *local_port);=0A void __user *udata =3D = (void __user *) data;=0A int ret =3D -ENOTTY;=0A =0A@@ = -453,7 +451,7 @@ static const struct file_operations xenb=0A .open =3D = xenbus_dev_open,=0A .release =3D xenbus_dev_release,=0A .poll =3D = xenbus_dev_poll,=0A-#ifdef HAVE_UNLOCKED_IOCTL=0A+#ifdef CONFIG_XEN_PRIVILE= GED_GUEST=0A .unlocked_ioctl =3D xenbus_dev_ioctl=0A #endif=0A };=0A--- = a/drivers/xen/xenbus/xenbus_probe.c=0A+++ b/drivers/xen/xenbus/xenbus_probe= .c=0A@@ -887,7 +887,8 @@ void xenbus_probe(struct work_struct *un=0A }=0A = =0A =0A-#if defined(CONFIG_PROC_FS) && defined(CONFIG_XEN_PRIVILEGED_GUEST)= =0A+#ifdef CONFIG_XEN_PRIVILEGED_GUEST=0A+#ifdef CONFIG_PROC_FS=0A static = struct file_operations xsd_kva_fops;=0A static struct proc_dir_entry = *xsd_kva_intf;=0A static struct proc_dir_entry *xsd_port_intf;=0A@@ -949,6 = +950,7 @@ static int xsd_port_read(char *page, cha=0A }=0A #endif=0A = =0A+#ifdef CONFIG_XEN_XENBUS_DEV=0A static int xb_free_port(evtchn_port_t = port)=0A {=0A struct evtchn_close close;=0A@@ -956,7 +958,8 @@ static = int xb_free_port(evtchn_port_t po=0A return HYPERVISOR_event_channel_op(= EVTCHNOP_close, &close);=0A }=0A =0A-int xenbus_conn(domid_t remote_dom, = unsigned long *grant_ref, evtchn_port_t *local_port)=0A+int xenbus_conn(dom= id_t remote_dom, grant_ref_t *grant_ref,=0A+ evtchn_port_t = *local_port)=0A {=0A struct evtchn_alloc_unbound alloc_unbound;=0A = int rc, rc2;=0A@@ -964,10 +967,8 @@ int xenbus_conn(domid_t remote_dom, = unsi=0A BUG_ON(atomic_read(&xenbus_xsd_state) !=3D XENBUS_XSD_FOREI= GN_INIT);=0A BUG_ON(!is_initial_xendomain());=0A =0A-#if defined(CONFIG_= PROC_FS) && defined(CONFIG_XEN_PRIVILEGED_GUEST)=0A remove_xen_proc_ent= ry("xsd_kva");=0A remove_xen_proc_entry("xsd_port");=0A-#endif=0A = =0A rc =3D xb_free_port(xen_store_evtchn);=0A if (rc !=3D = 0)=0A@@ -1004,6 +1005,8 @@ fail0:=0A xen_store_evtchn =3D -1;=0A = return rc;=0A }=0A+#endif=0A+#endif /* CONFIG_XEN_PRIVILEGED_GUEST */=0A = =0A static int xenbus_probe_init(void)=0A {=0A --=__Part4D619852.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 --=__Part4D619852.0__=--