x86, SGI UV: uv_ptc_proc_write fix
authorCliff Wickman <cpw@sgi.com>
Mon, 23 Jun 2008 13:32:25 +0000 (08:32 -0500)
committerIngo Molnar <mingo@elte.hu>
Tue, 8 Jul 2008 10:23:31 +0000 (12:23 +0200)
Someone could write 0 bytes to /proc/sgi_uv/ptc_statistics,
causing
  optstr[count - 1] = '\0';
to write to who-knows-where.

(Andi Kleen noticed this need from a patch I sent for
 similar code in the ia64 world (sn2_ptc_proc_write()).)

(count less than zero is not possible here, as count is unsigned)

Signed-off-by: Cliff Wickman <cpw@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/kernel/tlb_uv.c

index c503b7f04481a271914459ead5be09a41d771f4b..d0fbb7712ab05d5ae0359c0b10db4287db742d9f 100644 (file)
@@ -492,7 +492,7 @@ static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
        long newmode;
        char optstr[64];
 
-       if (count > 64)
+       if (count == 0 || count > sizeof(optstr))
                return -EINVAL;
        if (copy_from_user(optstr, user, count))
                return -EFAULT;