[PATCH v4 4/7] of/overlay: put property on deadprops only after changeset add succeeds
From: Abdurrahman Hussain
Date: Wed Jul 22 2026 - 03:14:25 EST
add_changeset_property() links a new property of a not-yet-live
target node into the node's deadprops list before handing it to
of_changeset_add_property(). If that fails, the error path frees the
property with __of_prop_free() but leaves the freed pointer linked in
deadprops. When the aborted overlay's node is later released,
of_node_release() walks deadprops and frees the property a second
time — a use-after-free followed by a double-free.
Record the changeset entry first and link the property into deadprops
only on success. of_changeset_add_property() only allocates and
queues the changeset entry — it never looks at the node's property
lists — so the order of the two steps is otherwise immaterial, and
the error path is left freeing a property that nothing references.
Assisted-by: Claude:claude-fable-5 [Claude Code]
Signed-off-by: Abdurrahman Hussain <abdurrahman@xxxxxxxxxx>
---
drivers/of/overlay.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 74aea704835a..284c9bc6c9cf 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -358,12 +358,13 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
return -ENOMEM;
if (!prop) {
- if (!target->in_livetree) {
+ ret = of_changeset_add_property(&ovcs->cset, target->np,
+ new_prop);
+ /* the detached node owns the property until the apply */
+ if (!ret && !target->in_livetree) {
new_prop->next = target->np->deadprops;
target->np->deadprops = new_prop;
}
- ret = of_changeset_add_property(&ovcs->cset, target->np,
- new_prop);
} else {
ret = of_changeset_update_property(&ovcs->cset, target->np,
new_prop);
--
2.54.0