lguest: make sure cpu is initialized before accessing it
authorEugene Teo <eugeneteo@kernel.sg>
Sat, 9 Feb 2008 15:53:17 +0000 (23:53 +0800)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 10 Mar 2008 22:35:56 +0000 (09:35 +1100)
If req is LHREQ_INITIALIZE, and the guest has been initialized before
(unlikely), it will attempt to access cpu->tsk even though cpu is not yet
initialized.

Signed-off-by: Eugene Teo <eugeneteo@kernel.sg>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/lguest/lguest_user.c

index 85d42d3d01a9a9bbeb739ce422271848cd4be3ff..2221485b07739a48114f44dc38b4f4249a93360c 100644 (file)
@@ -241,15 +241,16 @@ static ssize_t write(struct file *file, const char __user *in,
                cpu = &lg->cpus[cpu_id];
                if (!cpu)
                        return -EINVAL;
-       }
 
-       /* Once the Guest is dead, all you can do is read() why it died. */
-       if (lg && lg->dead)
-               return -ENOENT;
+               /* Once the Guest is dead, you can only read() why it died. */
+               if (lg->dead)
+                       return -ENOENT;
 
-       /* If you're not the task which owns the Guest, you can only break */
-       if (lg && current != cpu->tsk && req != LHREQ_BREAK)
-               return -EPERM;
+               /* If you're not the task which owns the Guest, all you can do
+                * is break the Launcher out of running the Guest. */
+               if (current != cpu->tsk && req != LHREQ_BREAK)
+                       return -EPERM;
+       }
 
        switch (req) {
        case LHREQ_INITIALIZE: