Skip to content

Commit d657d28

Browse files
t-8chgregkh
authored andcommitted
of: address: Report error on resource bounds overflow
commit 000f6d5 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 25b7a67 commit d657d28

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>
@@ -1142,7 +1143,11 @@ static int __of_address_to_resource(struct device_node *dev, int index, int bar_
11421143
if (of_mmio_is_nonposted(dev))
11431144
flags |= IORESOURCE_MEM_NONPOSTED;
11441145

1146+
if (overflows_type(taddr, r->start))
1147+
return -EOVERFLOW;
11451148
r->start = taddr;
1149+
if (overflows_type(taddr + size - 1, r->end))
1150+
return -EOVERFLOW;
11461151
r->end = taddr + size - 1;
11471152
r->flags = flags;
11481153
r->name = name ? name : dev->full_name;

0 commit comments

Comments
 (0)