Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2528a8b

Browse files
Chris Metcalftorvalds
authored andcommitted
__bitmap_parselist: fix bug in empty string handling
bitmap_parselist("", &mask, nmaskbits) will erroneously set bit zero in the mask. The same bug is visible in cpumask_parselist() since it is layered on top of the bitmask code, e.g. if you boot with "isolcpus=", you will actually end up with cpu zero isolated. The bug was introduced in commit 4b06042 ("bitmap, irq: add smp_affinity_list interface to /proc/irq") when bitmap_parselist() was generalized to support userspace as well as kernelspace. Fixes: 4b06042 ("bitmap, irq: add smp_affinity_list interface to /proc/irq") Signed-off-by: Chris Metcalf <[email protected]> Cc: Rasmus Villemoes <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4f973c6 commit 2528a8b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/bitmap.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,12 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
506506
unsigned a, b;
507507
int c, old_c, totaldigits;
508508
const char __user __force *ubuf = (const char __user __force *)buf;
509-
int exp_digit, in_range;
509+
int at_start, in_range;
510510

511511
totaldigits = c = 0;
512512
bitmap_zero(maskp, nmaskbits);
513513
do {
514-
exp_digit = 1;
514+
at_start = 1;
515515
in_range = 0;
516516
a = b = 0;
517517

@@ -540,11 +540,10 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
540540
break;
541541

542542
if (c == '-') {
543-
if (exp_digit || in_range)
543+
if (at_start || in_range)
544544
return -EINVAL;
545545
b = 0;
546546
in_range = 1;
547-
exp_digit = 1;
548547
continue;
549548
}
550549

@@ -554,16 +553,18 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
554553
b = b * 10 + (c - '0');
555554
if (!in_range)
556555
a = b;
557-
exp_digit = 0;
556+
at_start = 0;
558557
totaldigits++;
559558
}
560559
if (!(a <= b))
561560
return -EINVAL;
562561
if (b >= nmaskbits)
563562
return -ERANGE;
564-
while (a <= b) {
565-
set_bit(a, maskp);
566-
a++;
563+
if (!at_start) {
564+
while (a <= b) {
565+
set_bit(a, maskp);
566+
a++;
567+
}
567568
}
568569
} while (buflen && c == ',');
569570
return 0;

0 commit comments

Comments
 (0)