The patch titled bitmap: bitmap_parse takes a kernel buffer instead of a user buffer has been added to the -mm tree. Its filename is bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer.patch See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: bitmap: bitmap_parse takes a kernel buffer instead of a user buffer From: Reinette Chatre <reinette.chatre@xxxxxxxxxxxxxxx> lib/bitmap.c:bitmap_parse() is a library function that received as input a user buffer. This seemed to have originated from the way the write_proc function of the /proc filesystem operates. This function will be useful for other uses as well; for example, taking input for /sysfs instead of /proc, so it was changed to accept kernel buffers. We have this use for the Linux UWB project, as part as the upcoming bandwidth allocator code. Only a few routines used this function and they were changed too. Signed-off-by: Reinette Chatre <reinette.chatre@xxxxxxxxxxxxxxx> Signed-off-by: Inaky Perez-Gonzalez <inaky@xxxxxxxxxxxxxxx> Cc: Paul Jackson <pj@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxx> --- include/linux/bitmap.h | 4 ++-- include/linux/cpumask.h | 2 +- include/linux/nodemask.h | 2 +- kernel/irq/proc.c | 13 ++++++++++++- kernel/profile.c | 13 ++++++++++++- lib/bitmap.c | 15 +++++++-------- 6 files changed, 35 insertions(+), 14 deletions(-) diff -puN include/linux/bitmap.h~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer include/linux/bitmap.h --- a/include/linux/bitmap.h~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer +++ a/include/linux/bitmap.h @@ -46,7 +46,7 @@ * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) * bitmap_scnprintf(buf, len, src, nbits) Print bitmap src to buf - * bitmap_parse(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf + * bitmap_parse(buf, len, dst, nbits) Parse bitmap dst from buf * bitmap_scnlistprintf(buf, len, src, nbits) Print bitmap src as list to buf * bitmap_parselist(buf, dst, nbits) Parse bitmap dst from list * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region @@ -106,7 +106,7 @@ extern int __bitmap_weight(const unsigne extern int bitmap_scnprintf(char *buf, unsigned int len, const unsigned long *src, int nbits); -extern int bitmap_parse(const char __user *ubuf, unsigned int ulen, +extern int bitmap_parse(const char *buf, unsigned int len, unsigned long *dst, int nbits); extern int bitmap_scnlistprintf(char *buf, unsigned int len, const unsigned long *src, int nbits); diff -puN include/linux/cpumask.h~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer include/linux/cpumask.h --- a/include/linux/cpumask.h~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer +++ a/include/linux/cpumask.h @@ -275,7 +275,7 @@ static inline int __cpumask_scnprintf(ch #define cpumask_parse(ubuf, ulen, dst) \ __cpumask_parse((ubuf), (ulen), &(dst), NR_CPUS) -static inline int __cpumask_parse(const char __user *buf, int len, +static inline int __cpumask_parse(const char *buf, int len, cpumask_t *dstp, int nbits) { return bitmap_parse(buf, len, dstp->bits, nbits); diff -puN include/linux/nodemask.h~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer include/linux/nodemask.h --- a/include/linux/nodemask.h~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer +++ a/include/linux/nodemask.h @@ -290,7 +290,7 @@ static inline int __nodemask_scnprintf(c #define nodemask_parse(ubuf, ulen, dst) \ __nodemask_parse((ubuf), (ulen), &(dst), MAX_NUMNODES) -static inline int __nodemask_parse(const char __user *buf, int len, +static inline int __nodemask_parse(const char *buf, int len, nodemask_t *dstp, int nbits) { return bitmap_parse(buf, len, dstp->bits, nbits); diff -puN kernel/irq/proc.c~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer kernel/irq/proc.c --- a/kernel/irq/proc.c~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer +++ a/kernel/irq/proc.c @@ -53,11 +53,22 @@ static int irq_affinity_write_proc(struc { unsigned int irq = (int)(long)data, full_count = count, err; cpumask_t new_value, tmp; + char *kbuf; + unsigned long ret; if (!irq_desc[irq].chip->set_affinity || no_irq_affinity) return -EIO; - err = cpumask_parse(buffer, count, new_value); + kbuf = kmalloc(count, GFP_KERNEL); + if (kbuf == NULL) + return -ENOMEM; + ret = copy_from_user(kbuf, buffer, count); + if (ret != 0) { + kfree(kbuf); + return -EFAULT; + } + err = cpumask_parse(kbuf, count, new_value); + kfree(kbuf); if (err) return err; diff -puN kernel/profile.c~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer kernel/profile.c --- a/kernel/profile.c~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer +++ a/kernel/profile.c @@ -395,8 +395,19 @@ static int prof_cpu_mask_write_proc (str cpumask_t *mask = (cpumask_t *)data; unsigned long full_count = count, err; cpumask_t new_value; + char *kbuf; + unsigned long ret; - err = cpumask_parse(buffer, count, new_value); + kbuf = kmalloc(count, GFP_KERNEL); + if (kbuf == NULL) + return -ENOMEM; + ret = copy_from_user(kbuf, buffer, count); + if (ret != 0) { + kfree(kbuf); + return -EFAULT; + } + err = cpumask_parse(kbuf, count, new_value); + kfree(kbuf); if (err) return err; diff -puN lib/bitmap.c~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer lib/bitmap.c --- a/lib/bitmap.c~bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer +++ a/lib/bitmap.c @@ -317,8 +317,8 @@ EXPORT_SYMBOL(bitmap_scnprintf); /** * bitmap_parse - convert an ASCII hex string into a bitmap. - * @ubuf: pointer to buffer in user space containing string. - * @ubuflen: buffer size in bytes. If string is smaller than this + * @buf: pointer to buffer containing string. + * @buflen: buffer size in bytes. If string is smaller than this * then it must be terminated with a \0. * @maskp: pointer to bitmap array that will contain result. * @nmaskbits: size of bitmap, in bits. @@ -330,7 +330,7 @@ EXPORT_SYMBOL(bitmap_scnprintf); * characters and for grouping errors such as "1,,5", ",44", "," and "". * Leading and trailing whitespace accepted, but not embedded whitespace. */ -int bitmap_parse(const char __user *ubuf, unsigned int ubuflen, +int bitmap_parse(const char *buf, unsigned int buflen, unsigned long *maskp, int nmaskbits) { int c, old_c, totaldigits, ndigits, nchunks, nbits; @@ -343,11 +343,10 @@ int bitmap_parse(const char __user *ubuf chunk = ndigits = 0; /* Get the next chunk of the bitmap */ - while (ubuflen) { + while (buflen) { old_c = c; - if (get_user(c, ubuf++)) - return -EFAULT; - ubuflen--; + c = *buf++; + buflen--; if (isspace(c)) continue; @@ -388,7 +387,7 @@ int bitmap_parse(const char __user *ubuf nbits += (nchunks == 1) ? nbits_to_hold_value(chunk) : CHUNKSZ; if (nbits > nmaskbits) return -EOVERFLOW; - } while (ubuflen && c == ','); + } while (buflen && c == ','); return 0; } _ Patches currently in -mm which might be from reinette.chatre@xxxxxxxxxxxxxxx are bitmap-bitmap_parse-takes-a-kernel-buffer-instead-of-a-user-buffer.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html