Skip to contentSkip to conversation

of: fdt: fix off-by-one error in unflatten_dt_nodes()

PATCH Applied Sergey Shtylyov 2 participants 2 messages Aug 13, 2022 – Aug 16, 2022 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of: fdt: fix off-by-one error in unflatten_dt_nodes()

Commit 78c44d910d3e ("drivers/of: Fix depth when unflattening devicetree") forgot to fix up the depth check in the loop body in unflatten_dt_nodes() which makes it possible to overflow the nps[] buffer...

Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.

Fixes 78c44d910d3e ("drivers/of: Fix depth when unflattening devicetree")

---
The patch is against the 'master' branch of Rob Herring's 'linux-git' repo...

 drivers/of/fdt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/fdt.c +1 -1
Index: linux/drivers/of/fdt.c
===================================================================
@@ -314,7 +314,7 @@ static int unflatten_dt_nodes(const void
 	for (offset = 0;
 	     offset >= 0 && depth >= initial_depth;
 	     offset = fdt_next_node(blob, offset, &depth)) {
-		if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH))
+		if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH - 1))
 			continue;
 
 		if (!IS_ENABLED(CONFIG_OF_KOBJ) &&
maintainer Applied
#1 lore raw
Quoted 7 lines · Sergey Shtylyov

Commit 78c44d910d3e ("drivers/of: Fix depth when unflattening devicetree") forgot to fix up the depth check in the loop body in unflatten_dt_nodes() which makes it possible to overflow the nps[] buffer...

Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.

Quoted 9 lines
Fixes 78c44d910d3e ("drivers/of: Fix depth when unflattening devicetree")

---
The patch is against the 'master' branch of Rob Herring's 'linux-git' repo...

 drivers/of/fdt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks!