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:
2023-12-24 09:37:52 +00:00
parent 63b69d8d85
commit 8b99158d66

View File

@@ -252,7 +252,12 @@ static phys_addr_t do_alloc(size_t size, phys_addr_t 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) {
allocated_base = it.it_base;
allocated_limit = base + size;