diff options
author | Thomas Weißschuh <[email protected]> | 2024-09-05 09:46:01 +0200 |
---|---|---|
committer | Rob Herring (Arm) <[email protected]> | 2024-09-05 08:19:47 -0500 |
commit | 000f6d588a8f3d128f89351058dc04d38e54a327 (patch) | |
tree | 36bcc02fe8d3b0b20a515f8030de5c222a669774 | |
parent | 05144ab7b7eaf531fc728fcb79dcf36b621ff42d (diff) |
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]>
-rw-r--r-- | drivers/of/address.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/of/address.c b/drivers/of/address.c index d669ce25b5f9..7e59283a4472 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -8,6 +8,7 @@ #include <linux/logic_pio.h> #include <linux/module.h> #include <linux/of_address.h> +#include <linux/overflow.h> #include <linux/pci.h> #include <linux/pci_regs.h> #include <linux/sizes.h> @@ -1061,7 +1062,11 @@ static int __of_address_to_resource(struct device_node *dev, int index, int bar_ if (of_mmio_is_nonposted(dev)) flags |= IORESOURCE_MEM_NONPOSTED; + if (overflows_type(taddr, r->start)) + return -EOVERFLOW; r->start = taddr; + if (overflows_type(taddr + size - 1, r->end)) + return -EOVERFLOW; r->end = taddr + size - 1; r->flags = flags; r->name = name ? name : dev->full_name; |