diff options
author | Ard Biesheuvel <ard.biesheuvel@linaro.org> | 2014-10-29 12:09:32 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@linaro.org> | 2014-11-04 11:43:10 -0500 |
commit | 8cccffc52694938fc88f3d90bc7fed8460e27191 (patch) | |
tree | 76ea435917e5cfd97859a813103a3aaa52ae5124 /drivers/of | |
parent | 50ba08f301a1b0310775deeed00c9b24ba75fe8a (diff) |
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>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/fdt.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 535124670257..83a8e1154602 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c | |||
@@ -928,6 +928,11 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) | |||
928 | const u64 phys_offset = __pa(PAGE_OFFSET); | 928 | const u64 phys_offset = __pa(PAGE_OFFSET); |
929 | 929 | ||
930 | if (!PAGE_ALIGNED(base)) { | 930 | if (!PAGE_ALIGNED(base)) { |
931 | if (size < PAGE_SIZE - (base & ~PAGE_MASK)) { | ||
932 | pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", | ||
933 | base, base + size); | ||
934 | return; | ||
935 | } | ||
931 | size -= PAGE_SIZE - (base & ~PAGE_MASK); | 936 | size -= PAGE_SIZE - (base & ~PAGE_MASK); |
932 | base = PAGE_ALIGN(base); | 937 | base = PAGE_ALIGN(base); |
933 | } | 938 | } |