Skip to contentSkip to conversation

msr: Fix NULL pointer deref due to msr_open on nonexistent CPUs

PATCH Applied Darrick J. Wong 3 participants 3 messages Aug 14, 2008 – Aug 15, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 msr: Fix NULL pointer deref due to msr_open on nonexistent CPUs

msr_open tests for someone trying to open a device for a nonexistent CPU. However, the function always returns 0, not ret like it should, hence userspace can BUG the kernel trivially. This bug was introduced by the cdev lock_kernel pushdown patch last May.

The BUG can be reproduced with these commands:

# mknod fubar c 202 8 <-- pick a number less than NR_CPUS that is not
                          the number of an online CPU
# cat fubar

---

 arch/x86/kernel/msr.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/msr.c +1 -1
index 9fd8095..e439380 100644
@@ -131,7 +131,7 @@ static int msr_open(struct inode *inode, struct file *file)
 		ret = -EIO;	/* MSR not supported */
 out:
 	unlock_kernel();
-	return 0;
+	return ret;
 }
 
 /*
Applied
#1 lore raw
Quoted 10 lines · Darrick J. Wong

msr_open tests for someone trying to open a device for a nonexistent CPU. However, the function always returns 0, not ret like it should, hence userspace can BUG the kernel trivially. This bug was introduced by the cdev lock_kernel pushdown patch last May.

The BUG can be reproduced with these commands:

# mknod fubar c 202 8 <-- pick a number less than NR_CPUS that is not
                          the number of an online CPU
# cat fubar

applied to tip/x86/urgent - thanks Darrick.

Ingo

#2 lore raw
In reply to Darrick J. Wong

arch/x86/kernel/msr.c static int msr_open(struct inode *inode, struct file *file) · line 134

Quoted 7 lines · On Thu, 14 Aug 2008 15:43:33 -0700 "Darrick J. Wong" <[email protected]> wrote:

msr_open tests for someone trying to open a device for a nonexistent CPU. However, the function always returns 0, not ret like it should, hence userspace can BUG the kernel trivially. This bug was introduced by the cdev lock_kernel pushdown patch last May.

arch/x86/kernel/msr.c +1 -1
-	return 0;
+	return ret;

Oops, that was pretty silly. Apologies for the screwup.

jon