mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] of: fdt: Add root name checks during unflattening
@ 2021-02-23  8:52 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2021-02-23  8:52 UTC (permalink / raw)
  To: Barebox List

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>
---
 drivers/of/fdt.c | 15 +++++++++++++--
 1 file 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);
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-23  8:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-23  8:52 [PATCH] of: fdt: Add root name checks during unflattening Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox