Skip to contentSkip to conversation

lguest: make sure cpu is initialized before accessing it

PATCH In review Eugene Teo 2 participants 2 messages Feb 9, 2008 – Mar 4, 2008 1 message not in the archive

lore
Share & tools
lore

Eugene Teo

author
#0 lore raw

PATCH 1/1 lguest: make sure cpu is initialized before accessing it

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.

---
 drivers/lguest/lguest_user.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
drivers/lguest/lguest_user.c +7 -7
index 85d42d3..9cbb285 100644
@@ -241,15 +241,15 @@ 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, all you can do is read() why it died. */
+		if (lg && 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, you can only break */
+		if (lg && current != cpu->tsk && req != LHREQ_BREAK)
+			return -EPERM;
+	}
 
 	switch (req) {
 	case LHREQ_INITIALIZE:

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 6 lines · On Tuesday 04 March 2008 10:15:47 Rusty Russell wrote:
Quoted 5 lines · On Sunday 10 February 2008 02:53:17 Eugene Teo wrote:

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.

Thanks Eugene, I've applied this with some wrapping of the comments and removal of the now-redundant lg != NULL tests:

Quoted 11 lines

drivers/lguest/lguest_user.c static ssize_t write(struct file *file, const char __user *in, · line 252

Quoted 11 lines
drivers/lguest/lguest_user.c +7 -3
+		/* Once the Guest is dead, all you can do is read() why it died. */
+		if (lg && 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, you can only break */
+		if (lg && current != cpu->tsk && req != LHREQ_BREAK)
+			return -EPERM;
+	}

Cheers,
Rusty.