Skip to content

Commit 000f6d5

Browse files
t-8chrobherring
authored andcommitted
of: address: Report error on resource bounds overflow
The members "start" and "end" of struct resource are of type "resource_size_t" which can be 32bit wide. Values read from OF however are always 64bit wide. Avoid silently truncating the value and instead return an error value. This can happen on real systems when the DT was created for a PAE-enabled kernel and a non-PAE kernel is actually running. For example with an arm defconfig and "qemu-system-arm -M virt". Link: https://bugs.launchpad.net/qemu/+bug/1790975 Signed-off-by: Thomas Weißschuh <[email protected]> Tested-by: Nam Cao <[email protected]> Reviewed-by: Nam Cao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent 05144ab commit 000f6d5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/of/address.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/logic_pio.h>
99
#include <linux/module.h>
1010
#include <linux/of_address.h>
11+
#include <linux/overflow.h>
1112
#include <linux/pci.h>
1213
#include <linux/pci_regs.h>
1314
#include <linux/sizes.h>
@@ -1061,7 +1062,11 @@ static int __of_address_to_resource(struct device_node *dev, int index, int bar_
10611062
if (of_mmio_is_nonposted(dev))
10621063
flags |= IORESOURCE_MEM_NONPOSTED;
10631064

1065+
if (overflows_type(taddr, r->start))
1066+
return -EOVERFLOW;
10641067
r->start = taddr;
1068+
if (overflows_type(taddr + size - 1, r->end))
1069+
return -EOVERFLOW;
10651070
r->end = taddr + size - 1;
10661071
r->flags = flags;
10671072
r->name = name ? name : dev->full_name;

0 commit comments

Comments
 (0)