|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH] bootfdt: Fix infinite loop in device_tree_for_each_node()
When a node's depth exceeds DEVICE_TREE_MAX_DEPTH inside the
device_tree_for_each_node() loop, the code prints a warning and
executes 'continue;' statement, which jumps to condition check,
bypassing the iterator update step:
node = fdt_next_node(fdt, node, &depth).
The node and depth are not updated, the loop repeatedly evaluates
the same too-deep node, causing a hang.
Fix this by wrapping the node processing logic in an 'else' block.
This ensures the loop update step is executed on every iteration,
safely skipping deeply nested nodes and doing the traversal.
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2615174670
Local tests.
Tests were based on "qemu-xtf.sh".
In the "/chosen" node were added these "levelN" nesting nodes:
chosen {
stdout-path = "/pl011@9000000";
kaslr-seed = <0x6ae81a67 0x26e92d62>;
level1 {
level2 {
...
level19 {
level20 {
compatible = "test";
value = <1234>;
};
};
...
};
};
};
Without a patch Xen stuck printing the same message in a loop:
(XEN) Checking for initrd in /chosen
(XEN) Checking for "xen,static-mem" in domain node
(XEN) Warning: device tree node `level15' is nested too deep
(XEN) Warning: device tree node `level15' is nested too deep
(XEN) Warning: device tree node `level15' is nested too deep
(XEN) Warning: device tree node `level15' is nested too deep
(XEN) Warning: device tree node `level15' is nested too deep
...
With a patch these too-deep nodes were successfully skipped and Xen
continued to boot:
(XEN) Checking for initrd in /chosen
(XEN) Checking for "xen,static-mem" in domain node
(XEN) Warning: device tree node `level15' is nested too deep
(XEN) Warning: device tree node `level16' is nested too deep
(XEN) Warning: device tree node `level17' is nested too deep
(XEN) Warning: device tree node `level18' is nested too deep
(XEN) Warning: device tree node `level19' is nested too deep
(XEN) Warning: device tree node `level20' is nested too deep
(XEN) RAM: 0000000040000000 - 00000000bfffffff
(XEN)
(XEN) MODULE[0]: 0000000043200000 - 000000004337afff Xen
(XEN) MODULE[1]: 0000000043400000 - 0000000043402fff Device Tree
(XEN) MODULE[2]: 0000000043000000 - 00000000430ef7f6 Ramdisk
(XEN) MODULE[3]: 0000000040600000 - 0000000042f4ffff Kernel
(XEN) MODULE[4]: 0000000040400000 - 0000000040412fff Kernel
(XEN)
(XEN) CMDLINE[0000000040600000]:domU0 console=ttyAMA0
...
---
xen/common/device-tree/bootfdt.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/xen/common/device-tree/bootfdt.c b/xen/common/device-tree/bootfdt.c
index 7c790b9a4d..4d10013b2d 100644
--- a/xen/common/device-tree/bootfdt.c
+++ b/xen/common/device-tree/bootfdt.c
@@ -90,23 +90,24 @@ int __init device_tree_for_each_node(const void *fdt, int
node,
{
printk("Warning: device tree node `%s' is nested too deep\n",
name);
- continue;
}
-
- as = depth > 0 ? address_cells[depth-1] :
DT_ROOT_NODE_ADDR_CELLS_DEFAULT;
- ss = depth > 0 ? size_cells[depth-1] : DT_ROOT_NODE_SIZE_CELLS_DEFAULT;
-
- address_cells[depth] = device_tree_get_u32(fdt, node,
- "#address-cells", as);
- size_cells[depth] = device_tree_get_u32(fdt, node,
- "#size-cells", ss);
-
- /* skip the first node */
- if ( node != first_node )
+ else
{
- ret = func(fdt, node, name, depth, as, ss, data);
- if ( ret != 0 )
- return ret;
+ as = depth > 0 ? address_cells[depth-1] :
DT_ROOT_NODE_ADDR_CELLS_DEFAULT;
+ ss = depth > 0 ? size_cells[depth-1] :
DT_ROOT_NODE_SIZE_CELLS_DEFAULT;
+
+ address_cells[depth] = device_tree_get_u32(fdt, node,
+ "#address-cells", as);
+ size_cells[depth] = device_tree_get_u32(fdt, node,
+ "#size-cells", ss);
+
+ /* skip the first node */
+ if ( node != first_node )
+ {
+ ret = func(fdt, node, name, depth, as, ss, data);
+ if ( ret != 0 )
+ return ret;
+ }
}
node = fdt_next_node(fdt, node, &depth);
--
2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |