]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
lib: fix stall in __bitmap_parselist()
authorYury Norov <ynorov@caviumnetworks.com>
Thu, 5 Apr 2018 23:18:25 +0000 (16:18 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 6 Apr 2018 04:36:21 +0000 (21:36 -0700)
syzbot is catching stalls at __bitmap_parselist()
(https://syzkaller.appspot.com/bug?id=ad7e0351fbc90535558514a71cd3edc11681997a).
The trigger is

  unsigned long v = 0;
  bitmap_parselist("7:,", &v, BITS_PER_LONG);

which results in hitting infinite loop at

    while (a <= b) {
    off = min(b - a + 1, used_size);
    bitmap_set(maskp, a, off);
    a += group_size;
    }

due to used_size == group_size == 0.

Link: http://lkml.kernel.org/r/20180404162647.15763-1-ynorov@caviumnetworks.com
Fixes: 0a5ce0831d04382a ("lib/bitmap.c: make bitmap_parselist() thread-safe and much faster")
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: syzbot <syzbot+6887cbb011c8054e8a3d@syzkaller.appspotmail.com>
Cc: Noam Camus <noamca@mellanox.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/bitmap.c
lib/test_bitmap.c

index 9e498c77ed0e8a9d9b63a3d7b8471eb9e5afd245..a42eff7e8c48bd81dd3db841a1e04f1672980b91 100644 (file)
@@ -607,7 +607,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
                /* if no digit is after '-', it's wrong*/
                if (at_start && in_range)
                        return -EINVAL;
-               if (!(a <= b) || !(used_size <= group_size))
+               if (!(a <= b) || group_size == 0 || !(used_size <= group_size))
                        return -EINVAL;
                if (b >= nmaskbits)
                        return -ERANGE;
index b3f235baa05d666279934fada119d63cedceac0b..413367cf569ea69bb9369ccebed686eca337d3b4 100644 (file)
@@ -255,6 +255,10 @@ static const struct test_bitmap_parselist parselist_tests[] __initconst = {
        {-EINVAL, "-1", NULL, 8, 0},
        {-EINVAL, "-0", NULL, 8, 0},
        {-EINVAL, "10-1", NULL, 8, 0},
+       {-EINVAL, "0-31:", NULL, 8, 0},
+       {-EINVAL, "0-31:0", NULL, 8, 0},
+       {-EINVAL, "0-31:0/0", NULL, 8, 0},
+       {-EINVAL, "0-31:1/0", NULL, 8, 0},
        {-EINVAL, "0-31:10/1", NULL, 8, 0},
 };