summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2021-02-23 09:50:35 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-02-23 09:50:37 +0100
commit82574e9e7e3c357ef2fe36abed9efc82b73b5f5b (patch)
tree371e87148c365fab52a09dad9d6350a45a396ccd
parent2575ef9d523e8aa1f7a187c44cdff9dc8ee172d3 (diff)
downloadbarebox-82574e9e7e3c357ef2fe36abed9efc82b73b5f5b.tar.gz
barebox-82574e9e7e3c357ef2fe36abed9efc82b73b5f5b.tar.xz
of: fdt: Add root name checks during unflattening
In a valid dtb the root node must have an empty name. Also, every other node name must be non empty. Add additional checks for this for better protection against invalid dtbs. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/of/fdt.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a31e2c348a..d98913e54a 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -184,10 +184,21 @@ static struct device_node *__of_unflatten_dtb(const void *infdt, bool constprops
goto err;
}
- if (!node)
+ if (!node) {
+ /* The root node must have an empty name */
+ if (*pathp) {
+ ret = -EINVAL;
+ goto err;
+ }
node = root;
- else
+ } else {
+ /* Only the root node may have an empty name */
+ if (!*pathp) {
+ ret = -EINVAL;
+ goto err;
+ }
node = of_new_node(node, pathp);
+ }
dt_struct = dt_struct_advance(&f, dt_struct,
sizeof(struct fdt_node_header) + len + 1);