lkml.org 
[lkml]   [2019]   [Jun]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: "lib: rework bitmap_parse()" triggers invalid access errors
On Thu, Jun 06, 2019 at 12:09:46PM -0400, Qian Cai wrote:
> On Wed, 2019-06-05 at 08:01 +0000, Yuri Norov wrote:
> > (Sorry for top-posting)
> >
> > I can reproduce this on next-20190604. Is it new trace, or like one you've
> > posted before?
>
> Same thing, "nbits" causes an invalid access.
>
> # ./scripts/faddr2line vmlinux bitmap_parse+0x20c/0x2d8
> bitmap_parse+0x20c/0x2d8:
> __bitmap_clear at lib/bitmap.c:280
> (inlined by) bitmap_clear at include/linux/bitmap.h:390
> (inlined by) bitmap_parse at lib/bitmap.c:662
>
> This line,
>
> while (len - bits_to_clear >= 0) {

[...]

The problem is in my code, and the fix is:

diff --git a/lib/bitmap.c b/lib/bitmap.c
index ebcf4700ebed..6b3e921f4e91 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -664,7 +664,7 @@ int bitmap_parse(const char *start, unsigned int buflen,

unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32;
if (unset_bit < nmaskbits) {
- bitmap_clear(maskp, unset_bit, nmaskbits);
+ bitmap_clear(maskp, unset_bit, nmaskbits - unset_bit);
return 0;
}

I'll add a test for this case and submit v3 soon.
Yury

\
 
 \ /
  Last update: 2019-06-07 03:58    [W:0.066 / U:2.168 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site