diff mbox series

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

Message ID 7c354554-006f-6b31-c195-cdfe4caee392@omp.ru
State Accepted, archived
Headers show
Series of: fdt: fix off-by-one error in unflatten_dt_nodes() | expand

Checks

Context Check Description
robh/checkpatch warning total: 0 errors, 2 warnings, 8 lines checked
robh/patch-applied fail build log

Commit Message

Sergey Shtylyov Aug. 13, 2022, 8:34 p.m. UTC
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")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
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(-)
diff mbox series

Patch

Index: linux/drivers/of/fdt.c
===================================================================
--- linux.orig/drivers/of/fdt.c
+++ 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) &&