Re: [PATCH] Fix argument checking in sched_setaffinity

From: Andi Kleen
Date: Mon Sep 06 2004 - 13:24:40 EST


On Sat, Sep 04, 2004 at 09:52:05PM -0700, Paul Jackson wrote:
> > starting with backing out the changes made to it this week.
>
> Andi,
>
> Given that Linus has gutted most of your patch to sched_setaffinity,
> do you have a preference between where the code started the week,
> and where it ended?
>
> If I'm reading Linus' mind right (well ... there's a first time
> for everything) then your preference, either way, would likely
> carry the day.

The only change I would like to have is to check the excess bytes
to make sure they don't contain some random value. They should
be either all 0 or all 0xff.

-Andi

Here's a patch for bk12:

Linus, does this look better?

--------------------------------------------------------

For excess cpumask bits passed from user space ensure
they are all zero or all one. This minimizes binary incompatibilities
when the kernel is recompiled with a bigger cpumask_t type.

diff -u linux-2.6.8/kernel/sched.c-o linux-2.6.8/kernel/sched.c
--- linux-2.6.8/kernel/sched.c-o 2004-09-06 20:06:58.000000000 +0200
+++ linux-2.6.8/kernel/sched.c 2004-09-06 20:16:33.940579241 +0200
@@ -3368,6 +3368,19 @@
if (len < sizeof(cpumask_t)) {
memset(new_mask, 0, sizeof(cpumask_t));
} else if (len > sizeof(cpumask_t)) {
+ unsigned i;
+ unsigned char val, initval;
+ if (len > PAGE_SIZE)
+ return -EINVAL;
+ /* excess bytes must be all 0 or all 0xff */
+ for (i = sizeof(cpumask_t); i < len; i++) {
+ if (get_user(val, (char *)new_mask + i))
+ return -EFAULT;
+ if (i == sizeof(cpumask_t))
+ initval = val;
+ if (!(val == 0 || val == 0xff) || val != initval)
+ return -EINVAL;
+ }
len = sizeof(cpumask_t);
}
return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/