Commit 35e691ed authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Rob Herring

of: overlay: Fix out-of-bounds write in init_overlay_changeset()

If an overlay has no "__symbols__" node, but it has nodes without
"__overlay__" subnodes at the end (e.g. a "__fixups__" node), after
filling in all fragments for nodes with "__overlay__" subnodes,
"fragment = &fragments[cnt]" will point beyond the end of the allocated
array.

Hence writing to "fragment->overlay" will overwrite unallocated memory,
which may lead to a crash later.

Fix this by deferring both the assignment to "fragment" and the
offending write afterwards until we know for sure the node has an
"__overlay__" subnode, and thus a valid entry in "fragments[]".

Fixes: 61b4de4e ("of: overlay: minor restructuring")
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
parent 5e474817
...@@ -572,9 +572,10 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, ...@@ -572,9 +572,10 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs,
cnt = 0; cnt = 0;
for_each_child_of_node(tree, node) { for_each_child_of_node(tree, node) {
overlay_node = of_get_child_by_name(node, "__overlay__");
if (overlay_node) {
fragment = &fragments[cnt]; fragment = &fragments[cnt];
fragment->overlay = of_get_child_by_name(node, "__overlay__"); fragment->overlay = overlay_node;
if (fragment->overlay) {
fragment->target = find_target_node(node); fragment->target = find_target_node(node);
if (!fragment->target) { if (!fragment->target) {
of_node_put(fragment->overlay); of_node_put(fragment->overlay);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment