Skip to content

Commit

Permalink
mm/vmalloc.c: fix an overflow bug in alloc_vmap_area()
Browse files Browse the repository at this point in the history
When searching a vmap area in the vmalloc space, we use (addr + size -
1) to check if the value is less than addr, which is an overflow.  But
we assign (addr + size) to vmap_area->va_end.

So if we come across the below case:

  (addr + size - 1) : not overflow
  (addr + size)     : overflow

we will assign an overflow value (e.g 0) to vmap_area->va_end, And this
will trigger BUG in __insert_vmap_area, causing system panic.

So using (addr + size) to check the overflow should be the correct
behaviour, not (addr + size - 1).

Signed-off-by: Zhang Yanfei <[email protected]>
Reported-by: Ghennadi Procopciuc <[email protected]>
Tested-by: Daniel Baluta <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: KOSAKI Motohiro <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Zhang Yanfei authored and torvalds committed Jul 9, 2013
1 parent 64363aa commit bcb615a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mm/vmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
addr = ALIGN(first->va_end, align);
if (addr < vstart)
goto nocache;
if (addr + size - 1 < addr)
if (addr + size < addr)
goto overflow;

} else {
addr = ALIGN(vstart, align);
if (addr + size - 1 < addr)
if (addr + size < addr)
goto overflow;

n = vmap_area_root.rb_node;
Expand All @@ -420,7 +420,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
if (addr + cached_hole_size < first->va_start)
cached_hole_size = first->va_start - addr;
addr = ALIGN(first->va_end, align);
if (addr + size - 1 < addr)
if (addr + size < addr)
goto overflow;

if (list_is_last(&first->list, &vmap_area_list))
Expand Down

0 comments on commit bcb615a

Please sign in to comment.