Commit c3ca375d authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Fix i386/x86_64 cpuid/msr BUG() on impossible CPUs

From: Rusty Russell <rusty@rustcorp.com.au>

Matthieu Castet <castet.matthieu@free.fr> pointed out that testing
cpu_online(cpu) on a UP system goes BUG().

That's because you're never supposed to ask cpu_online() about a CPU which
is >= NR_CPUS.  msr and cpuid devices use the minor to indicate the CPU
number.  Oops.

Fix is to explicitly test cpu < NR_CPUS.  Using cpu_online() is OK;
although the CPU might go down before you actually read the file, that will
simply cause junk to be returned.
parent b7e09f03
......@@ -132,10 +132,10 @@ static ssize_t cpuid_read(struct file *file, char *buf,
static int cpuid_open(struct inode *inode, struct file *file)
{
int cpu = iminor(file->f_dentry->d_inode);
unsigned int cpu = iminor(file->f_dentry->d_inode);
struct cpuinfo_x86 *c = &(cpu_data)[cpu];
if (!cpu_online(cpu))
if (cpu >= NR_CPUS || !cpu_online(cpu))
return -ENXIO; /* No such CPU */
if (c->cpuid_level < 0)
return -EIO; /* CPUID not supported */
......
......@@ -233,10 +233,10 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
static int msr_open(struct inode *inode, struct file *file)
{
int cpu = iminor(file->f_dentry->d_inode);
unsigned int cpu = iminor(file->f_dentry->d_inode);
struct cpuinfo_x86 *c = &(cpu_data)[cpu];
if (!cpu_online(cpu))
if (cpu >= NR_CPUS || !cpu_online(cpu))
return -ENXIO; /* No such CPU */
if (!cpu_has(c, X86_FEATURE_MSR))
return -EIO; /* MSR not supported */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment