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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Darrick J. Wong
Date: Thursday, August 14, 2008 - 3:43 pm

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

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
---

 arch/x86/kernel/msr.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
index 9fd8095..e439380 100644
--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -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;
 }
 
 /*
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] msr: Fix NULL pointer deref due to msr_open on non ..., Darrick J. Wong, (Thu Aug 14, 3:43 pm)