Commit 8cccffc5 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Grant Likely

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: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarGrant Likely <grant.likely@linaro.org>
parent 50ba08f3
...@@ -928,6 +928,11 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) ...@@ -928,6 +928,11 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
const u64 phys_offset = __pa(PAGE_OFFSET); const u64 phys_offset = __pa(PAGE_OFFSET);
if (!PAGE_ALIGNED(base)) { 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); size -= PAGE_SIZE - (base & ~PAGE_MASK);
base = PAGE_ALIGN(base); base = PAGE_ALIGN(base);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment