Skip to content

Commit 281327c

Browse files
YuryNorovtorvalds
authored andcommitted
lib: make bitmap_parselist_user() a wrapper on bitmap_parselist()
Patch series "lib: rework bitmap_parselist and tests", v5. bitmap_parselist has been evolved from a pretty simple idea for long and now lacks for refactoring. It is not structured, has nested loops and a set of opaque-named variables. Things are more complicated because bitmap_parselist() is a part of user interface, and its behavior should not change. In this patchset - bitmap_parselist_user() made a wrapper on bitmap_parselist(); - bitmap_parselist() reworked (patch 2); - time measurement in test_bitmap_parselist switched to ktime_get (patch 3); - new tests introduced (patch 4), and - bitmap_parselist_user() testing enabled with the same testset as bitmap_parselist() (patch 5). This patch (of 5): Currently we parse user data byte after byte which leads to overcomplification of parsing algorithm. The only user of bitmap_parselist_user() is not performance-critical, and so we can duplicate user data to kernel buffer and simply call bitmap_parselist(). This rework lets us unify and simplify bitmap_parselist() and bitmap_parselist_user(), which is done in the following patch. Link: http://lkml.kernel.org/r/20190405173211.11373-2-ynorov@marvell.com Signed-off-by: Yury Norov <ynorov@marvell.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Kees Cook <keescook@chromium.org> Cc: Matthew Wilcox <willy@infradead.org> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Mike Travis <travis@sgi.com> Cc: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9f61589 commit 281327c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/bitmap.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -632,19 +632,22 @@ EXPORT_SYMBOL(bitmap_parselist);
632632
* @nmaskbits: size of bitmap, in bits.
633633
*
634634
* Wrapper for bitmap_parselist(), providing it with user buffer.
635-
*
636-
* We cannot have this as an inline function in bitmap.h because it needs
637-
* linux/uaccess.h to get the access_ok() declaration and this causes
638-
* cyclic dependencies.
639635
*/
640636
int bitmap_parselist_user(const char __user *ubuf,
641637
unsigned int ulen, unsigned long *maskp,
642638
int nmaskbits)
643639
{
644-
if (!access_ok(ubuf, ulen))
645-
return -EFAULT;
646-
return __bitmap_parselist((const char __force *)ubuf,
647-
ulen, 1, maskp, nmaskbits);
640+
char *buf;
641+
int ret;
642+
643+
buf = memdup_user_nul(ubuf, ulen);
644+
if (IS_ERR(buf))
645+
return PTR_ERR(buf);
646+
647+
ret = bitmap_parselist(buf, maskp, nmaskbits);
648+
649+
kfree(buf);
650+
return ret;
648651
}
649652
EXPORT_SYMBOL(bitmap_parselist_user);
650653

0 commit comments

Comments
 (0)