From: "Jan Beulich" Subject: Re: [PATCH] Don't allow MICROCODE built as a modul Date: Wed, 18 Oct 2006 09:44:05 +0100 Message-ID: <45360575.76E4.0078.0@novell.com> References: <200610172320.11387.caglar@pardus.org.tr> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser , xen-devel@lists.xensource.com, caglar@pardus.org.tr List-Id: xen-devel@lists.xenproject.org >>> Keir Fraser 17.10.06 22:19 >>> >On 17/10/06 9:20 pm, "S.=C7a*lar Onur" wrote: > >> 17 Eki 2006 Sal 22:54 tarihinde, Keir Fraser *unlar* yazm**t*: >>> That's not fixing the underlying problem. Why would the microcode = driver >>> require sys_munlock()? I'm sure one of the distros would have provided = a >>> patch already if they were seeing this problem. >>=20 >> Hmm, a little google search shows SUSE already has [1], im not sure = original >> author submits or not but here it is [2] >>=20 >> [1] http://lists.opensuse.org/opensuse-commit/2006-04/msg00962.html=20 >> [2] http://cekirdek.pardus.org.tr/~caglar/xen-microcode-modular=20 > >Ah yes, that looks sensible. Perhaps if we ask nicely Jan will post it to >the list with a signed-off-by attribution. :-) Eliminating the dependency on sys_m{,un}lock as well as the needless use = of static variables. Signed-off-by: Jan Beulich Index: sle10-sp1-2006-10-05/arch/i386/kernel/microcode-xen.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sle10-sp1-2006-10-05.orig/arch/i386/kernel/microcode-xen.c 2006-10-05 = 12:23:01.000000000 +0200 +++ sle10-sp1-2006-10-05/arch/i386/kernel/microcode-xen.c 2006-10-05 = 13:37:27.000000000 +0200 @@ -50,9 +50,6 @@ MODULE_LICENSE("GPL"); =20 /* no concurrent ->write()s are allowed on /dev/cpu/microcode */ static DECLARE_MUTEX(microcode_sem); - -static void __user *user_buffer; /* user area microcode data buffer = */ -static unsigned int user_buffer_size; /* it's size */ =09 static int microcode_open (struct inode *unused1, struct file *unused2) { @@ -60,21 +57,26 @@ static int microcode_open (struct inode=20 } =20 =20 -static int do_microcode_update (void) +static int do_microcode_update (const void __user *ubuf, size_t len) { int err; - dom0_op_t op; + void *kbuf; =20 - err =3D sys_mlock((unsigned long)user_buffer, user_buffer_size); - if (err !=3D 0) - return err; - - op.cmd =3D DOM0_MICROCODE; - set_xen_guest_handle(op.u.microcode.data, user_buffer); - op.u.microcode.length =3D user_buffer_size; - err =3D HYPERVISOR_dom0_op(&op); + kbuf =3D vmalloc(len); + if (!kbuf) + return -ENOMEM; + + if (copy_from_user(kbuf, ubuf, len) =3D=3D 0) { + dom0_op_t op; + + op.cmd =3D DOM0_MICROCODE; + set_xen_guest_handle(op.u.microcode.data, kbuf); + op.u.microcode.length =3D len; + err =3D HYPERVISOR_dom0_op(&op); + } else + err =3D -EFAULT; =20 - (void)sys_munlock((unsigned long)user_buffer, user_buffer_size); + vfree(kbuf); =20 return err; } @@ -88,17 +90,9 @@ static ssize_t microcode_write (struct f return -EINVAL; } =20 - if ((len >> PAGE_SHIFT) > num_physpages) { - printk(KERN_ERR "microcode: too much data (max %ld = pages)\n", num_physpages); - return -EINVAL; - } - down(µcode_sem); =20 - user_buffer =3D (void __user *) buf; - user_buffer_size =3D (int) len; - - ret =3D do_microcode_update(); + ret =3D do_microcode_update(buf, len); if (!ret) ret =3D (ssize_t)len; =20