Skip to content

Commit faecdd4

Browse files
ISCAS-Vulabrobherring
authored andcommitted
of: unittest: fix use-after-free in of_unittest_changeset()
The variable 'parent' is assigned the value of 'nchangeset' earlier in the function, meaning both point to the same struct device_node. The call to of_node_put(nchangeset) can decrement the reference count to zero and free the node if there are no other holders. After that, the code still uses 'parent' to check for the presence of a property and to read a string property, leading to a use-after-free. Fix this by moving the of_node_put() call after the last access to 'parent', avoiding the UAF. Fixes: 1c668ea ("of: unittest: Use of_property_present()") Cc: stable@vger.kernel.org Signed-off-by: Wentao Liang <vulab@iscas.ac.cn> Link: https://patch.msgid.link/20260409022233.418103-1-vulab@iscas.ac.cn Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
1 parent e9cd85a commit faecdd4

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

drivers/of/unittest.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,6 @@ static void __init of_unittest_changeset(void)
896896

897897
unittest(!of_changeset_apply(&chgset), "apply failed\n");
898898

899-
of_node_put(nchangeset);
900-
901899
/* Make sure node names are constructed correctly */
902900
unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")),
903901
"'%pOF' not added\n", n21);
@@ -919,6 +917,7 @@ static void __init of_unittest_changeset(void)
919917
if (!ret)
920918
unittest(strcmp(propstr, "hello") == 0, "original value not in updated property after revert");
921919

920+
of_node_put(nchangeset);
922921
of_changeset_destroy(&chgset);
923922

924923
of_node_put(n1);

0 commit comments

Comments
 (0)