Message ID | 1407408695-19626-10-git-send-email-haojian.zhuang@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Thu, Aug 7, 2014 at 5:51 AM, Haojian Zhuang <haojian.zhuang@linaro.org> wrote: > early_init_dt_add_memory_arch() accepts base & size parameters as u64 > type. memblock_add() accepts base & size parameters as phys_addr_t type. > But phys_addr_t isn't equal to u64. In 32-bit system, phys_addr_t is > 32-bit long. If 64-bit memory address is specified in DTS file, it'll be > truncated into 32-bit address. > > So create two values to store base & size first as phys_addr_t type. > Then compare them with u64 base & u64 size. If they don't match, discard > them. This is fixed already in v3.16: commit a67a6ed15513541579d38bcbd127e7be170710e5 Author: Laura Abbott <lauraa@codeaurora.org> Date: Thu Jun 19 20:13:38 2014 -0700 of: Check for phys_addr_t overflows in early_init_dt_add_memory_arch The common early_init_dt_add_memory_arch takes the base and size of a memory region as u64 types. The function never checks if the base and size can actually fit in a phys_addr_t which may be smaller than 64-bits. This may result in incorrect memory being passed to memblock_add if the memory falls outside the range of phys_addr_t. Add range checks for the base and size if phys_addr_t is smaller than u64. Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Tested-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Laura Abbott <lauraa@codeaurora.org> Acked-by: Nicolas Pitre <nico@linaro.org> Signed-off-by: Grant Likely <grant.likely@linaro.org> In the future, please use get_maintainers.pl to cc the correct people. Rob
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index c4cddf0..10d5382 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -878,6 +878,8 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) { const u64 phys_offset = __pa(PAGE_OFFSET); + phys_addr_t mbase, msize; + base &= PAGE_MASK; size &= PAGE_MASK; if (base + size < phys_offset) { @@ -885,6 +887,14 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) base, base + size); return; } + /* phys_addr_t may not be equal to u64 */ + mbase = base; + msize = size; + if ((mbase != base) || (msize != size)) { + pr_warning("Ignoring memory block 0x%llx - 0x%llx\n", + base, base + size); + return; + } if (base < phys_offset) { pr_warning("Ignoring memory range 0x%llx - 0x%llx\n", base, phys_offset);
early_init_dt_add_memory_arch() accepts base & size parameters as u64 type. memblock_add() accepts base & size parameters as phys_addr_t type. But phys_addr_t isn't equal to u64. In 32-bit system, phys_addr_t is 32-bit long. If 64-bit memory address is specified in DTS file, it'll be truncated into 32-bit address. So create two values to store base & size first as phys_addr_t type. Then compare them with u64 base & u64 size. If they don't match, discard them. Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org> --- drivers/of/fdt.c | 10 ++++++++++ 1 file changed, 10 insertions(+)