Devicetree
 help / color / mirror / Atom feed
* [PATCH] of: fdt: reject oversized unflattened trees
@ 2026-11-07  9:35 Sung Byeongchan
  2026-11-07  9:44 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Sung Byeongchan @ 2026-11-07  9:35 UTC (permalink / raw)
  To: Rob Herring; +Cc: Saravana Kannan, devicetree


unflatten_dt_nodes() computes the expanded tree size by advancing a dry
pointer cursor, but returns the result as int. A valid flattened tree whose
expanded nodes and properties exceed the signed range can consequently
wrap to a small positive allocation before the full second write pass.

On a 64-bit UML build, a 157,133,160-byte FDT expanded to 4,294,971,394
bytes and narrowed to 4,098. The undersized write pass left a corrupted OF
tree whose property pointer later caused a kernel segfault in
__of_add_property_sysfs(), reproducibly in three fresh processes.

Reject the dry scan before its cursor can exceed the signed caller extent,
leaving room for the following alignment and four-byte end marker. This
prevents the write pass from starting with a narrowed allocation.

The fixed target rejected the trigger before allocation or write in three
of three fresh processes. Normal, near-boundary, malformed-header and
recovery controls passed in both lanes.

The demonstrated impact is host or VMM boot input corrupting and crashing
a guest kernel. Information disclosure, controlled write, code execution,
host escape, RCE and LPE were not demonstrated.

Assisted-by: OpenAI Codex

Signed-off-by: Sung Byeongchan <tjdqudcks0424@naver.com>
---
 drivers/of/fdt.c |    5 +++++
 1 file changed, 5 insertions(+)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index ecc9231026224..135502b882020 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -310,6 +310,11 @@ static int unflatten_dt_nodes(const void *blob,
 				   &nps[depth+1], dryrun);
 		if (ret < 0)
 			return ret;
+		/* Leave room for the alignment and end marker below. */
+		if (dryrun && (unsigned long)mem > INT_MAX - 7) {
+			pr_err("Unflattened device tree is too large\n");
+			return -EOVERFLOW;
+		}
 
 		if (!dryrun && nodepp && !*nodepp)
 			*nodepp = nps[depth+1];

base-commit: d48723711bae9b8cdc56719c448ba42fef28cbee
-- 
2.43.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-07  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-07  9:35 [PATCH] of: fdt: reject oversized unflattened trees Sung Byeongchan
2026-11-07  9:44 ` sashiko-bot

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