Messages in this thread Patch in this message | | | Date | Wed, 1 Sep 2004 11:59:22 +1000 | From | Anton Blanchard <> | Subject | Re: [PATCH] Fix argument checking in sched_setaffinity |
| |
> I notice that you didn't bother with the fractional byte that is handled > by 'endmask' in mm/mempolicy.c:get_nodes(). But I really don't give a > hoot - either way is fine by me. > > I've written a couple of code snippets that manage to intuit the size of > the kernel's cpumask dynamically from user space, by probing with > various sched_getaffinity() calls. But since your patch only changes > the errors generated by sched_setaffinity() [that's "set", not "get"], I > will not experience any grief from this subtle change in the kernel's > API. > > Should you lock hotplug before calling get_user_cpu_mask(), since > get_user_cpu_mask() depends on cpu_online_mask()?
FYI the NUMA API and affinity code is broken on 64bit big endian. We really need a get/set compat bitmap and use it. How does this look? Not well tested yet...
Anton
diff -puN kernel/compat.c~compat_bitmap kernel/compat.c --- gr_work/kernel/compat.c~compat_bitmap 2004-06-16 10:32:11.590272927 -0500 +++ gr_work-anton/kernel/compat.c 2004-06-16 10:32:11.607270238 -0500 @@ -561,3 +561,83 @@ long compat_clock_nanosleep(clockid_t wh /* timer_create is architecture specific because it needs sigevent conversion */ +long compat_get_bitmap(unsigned long *mask, compat_ulong_t __user *umask, + unsigned long bitmap_size) +{ + int i, j; + unsigned long m; + compat_ulong_t um; + unsigned long nr_compat_longs; + + /* align bitmap up to nearest compat_long_t boundary */ + bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG); + + if (verify_area(VERIFY_READ, umask, bitmap_size / 8)) + return -EFAULT; + + nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size); + + for (i = 0; i < BITS_TO_LONGS(bitmap_size); i++) { + m = 0; + + for (j = 0; j < sizeof(m)/sizeof(um); j++) { + /* + * We dont want to read past the end of the userspace + * bitmap. We must however ensure the end of the + * kernel bitmap is zeroed. + */ + if (nr_compat_longs-- > 0) { + if (__get_user(um, umask)) + return -EFAULT; + } else { + um = 0; + } + + umask++; + m |= (long)um << (j * BITS_PER_COMPAT_LONG); + } + *mask++ = m; + } + + return 0; +} + +long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask, + unsigned long bitmap_size) +{ + int i, j; + unsigned long m; + compat_ulong_t um; + unsigned long nr_compat_longs; + + /* align bitmap up to nearest compat_long_t boundary */ + bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG); + + if (verify_area(VERIFY_WRITE, umask, bitmap_size / 8)) + return -EFAULT; + + nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size); + + for (i = 0; i < BITS_TO_LONGS(bitmap_size); i++) { + m = *mask++; + + for (j = 0; j < sizeof(m)/sizeof(um); j++) { + um = m; + + /* + * We dont want to write past the end of the userspace + * bitmap. + */ + if (nr_compat_longs-- > 0) { + if (__put_user(um, umask)) + return -EFAULT; + } + + umask++; + m >>= 4*sizeof(um); + m >>= 4*sizeof(um); + } + } + + return 0; +} diff -puN include/linux/compat.h~compat_bitmap include/linux/compat.h --- gr_work/include/linux/compat.h~compat_bitmap 2004-06-16 10:32:11.595272136 -0500 +++ gr_work-anton/include/linux/compat.h 2004-06-16 10:32:11.608270080 -0500 @@ -130,5 +130,15 @@ asmlinkage long compat_sys_select(int n, compat_ulong_t __user *outp, compat_ulong_t __user *exp, struct compat_timeval __user *tvp); +#define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t)) + +#define BITS_TO_COMPAT_LONGS(bits) \ + (((bits)+BITS_PER_COMPAT_LONG-1)/BITS_PER_COMPAT_LONG) + +long compat_get_bitmap(unsigned long *mask, compat_ulong_t __user *umask, + unsigned long bitmap_size); +long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask, + unsigned long bitmap_size); + #endif /* CONFIG_COMPAT */ #endif /* _LINUX_COMPAT_H */ _ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |