of: check for size < 0 after rounding in early_init_dt_add_memory_arch
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 29 Oct 2014 16:09:32 +0000 (17:09 +0100)
committerGrant Likely <grant.likely@linaro.org>
Tue, 4 Nov 2014 16:43:10 +0000 (16:43 +0000)
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>
drivers/of/fdt.c

index 53512467025735b5202def3e5d16167e35faa273..83a8e11546021d3d312d314ff654f3742cff9086 100644 (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);
        }