vm: fix overflow in memblock do_alloc when allocating large aligned blocks
allocating a large power-of-2 block with memblock may cause the base pointer of a region to exceed the limit pointer after it has been aligned during the free region scan in do_alloc().
This commit is contained in:
@@ -252,7 +252,12 @@ static phys_addr_t do_alloc(size_t size, phys_addr_t align)
|
|||||||
base += align;
|
base += align;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t region_size = it.it_limit - base + 1;
|
size_t region_size = 0;
|
||||||
|
|
||||||
|
if (it.it_limit > base) {
|
||||||
|
region_size = it.it_limit - base + 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (region_size >= size) {
|
if (region_size >= size) {
|
||||||
allocated_base = it.it_base;
|
allocated_base = it.it_base;
|
||||||
allocated_limit = base + size;
|
allocated_limit = base + size;
|
||||||
|
|||||||
Reference in New Issue
Block a user