From 82574e9e7e3c357ef2fe36abed9efc82b73b5f5b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 23 Feb 2021 09:50:35 +0100 Subject: 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 --- drivers/of/fdt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'drivers/of/fdt.c') 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); -- cgit v1.2.3