Skip to content

Commit

Permalink
x86: Simplify bound checks in the MTRR code
Browse files Browse the repository at this point in the history
The current bound checks for copy_from_user in the MTRR driver are
not as obvious as they could be, and gcc agrees with that.

This patch simplifies the boundary checks to the point that gcc can
now prove to itself that the copy_from_user() is never going past
its bounds.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
LKML-Reference: <20090926205150.30797709@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Arjan van de Ven authored and Ingo Molnar committed Oct 2, 2009
1 parent 0d18b2e commit 11879ba
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions arch/x86/kernel/cpu/mtrr/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,24 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
unsigned long long base, size;
char *ptr;
char line[LINE_SIZE];
int length;
size_t linelen;

if (!capable(CAP_SYS_ADMIN))
return -EPERM;
if (!len)
return -EINVAL;

memset(line, 0, LINE_SIZE);
if (len > LINE_SIZE)
len = LINE_SIZE;
if (copy_from_user(line, buf, len - 1))

length = len;
length--;

if (length > LINE_SIZE - 1)
length = LINE_SIZE - 1;

if (length < 0)
return -EINVAL;

if (copy_from_user(line, buf, length))
return -EFAULT;

linelen = strlen(line);
Expand Down

0 comments on commit 11879ba

Please sign in to comment.