mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
of: address: Report error on resource bounds overflow
commit 000f6d588a8f3d128f89351058dc04d38e54a327 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 <thomas.weissschuh@linutronix.de> Tested-by: Nam Cao <namcao@linutronix.de> Reviewed-by: Nam Cao <namcao@linutronix.de> Link: https://lore.kernel.org/r/20240905-of-resource-overflow-v1-1-0cd8bb92cc1f@linutronix.de Cc: stable@vger.kernel.org Signed-off-by: Rob Herring (Arm) <robh@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
25b7a67037
commit
d657d28641
1 changed files with 5 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include <linux/logic_pio.h>
|
#include <linux/logic_pio.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/of_address.h>
|
#include <linux/of_address.h>
|
||||||
|
#include <linux/overflow.h>
|
||||||
#include <linux/pci.h>
|
#include <linux/pci.h>
|
||||||
#include <linux/pci_regs.h>
|
#include <linux/pci_regs.h>
|
||||||
#include <linux/sizes.h>
|
#include <linux/sizes.h>
|
||||||
|
@ -1142,7 +1143,11 @@ static int __of_address_to_resource(struct device_node *dev, int index, int bar_
|
||||||
if (of_mmio_is_nonposted(dev))
|
if (of_mmio_is_nonposted(dev))
|
||||||
flags |= IORESOURCE_MEM_NONPOSTED;
|
flags |= IORESOURCE_MEM_NONPOSTED;
|
||||||
|
|
||||||
|
if (overflows_type(taddr, r->start))
|
||||||
|
return -EOVERFLOW;
|
||||||
r->start = taddr;
|
r->start = taddr;
|
||||||
|
if (overflows_type(taddr + size - 1, r->end))
|
||||||
|
return -EOVERFLOW;
|
||||||
r->end = taddr + size - 1;
|
r->end = taddr + size - 1;
|
||||||
r->flags = flags;
|
r->flags = flags;
|
||||||
r->name = name ? name : dev->full_name;
|
r->name = name ? name : dev->full_name;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue