1
0
Fork 0

of: check for size < 0 after rounding in early_init_dt_add_memory_arch

Memory regions passed to early_init_dt_add_memory_arch() are rounded to
PAGE_SIZE by subtracting the size of the leading fractional page from
the 'size' argument. However, size being a u64 type, if its value is
sufficiently small, the subtraction wraps around and produces a bogus
value, potentially leading to crashes.

Fix this by ignoring the memory range in such cases.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
hifive-unleashed-5.1
Ard Biesheuvel 2014-10-29 17:09:32 +01:00 committed by Grant Likely
parent 50ba08f301
commit 8cccffc526
1 changed files with 5 additions and 0 deletions

View File

@ -928,6 +928,11 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
const u64 phys_offset = __pa(PAGE_OFFSET);
if (!PAGE_ALIGNED(base)) {
if (size < PAGE_SIZE - (base & ~PAGE_MASK)) {
pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
base, base + size);
return;
}
size -= PAGE_SIZE - (base & ~PAGE_MASK);
base = PAGE_ALIGN(base);
}