diff options
author | Geert Uytterhoeven <geert+renesas@glider.be> | 2017-12-08 08:13:02 -0500 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2017-12-08 10:32:10 -0500 |
commit | 35e691eddca565f475ba69ff84ca0c9db3b3257b (patch) | |
tree | 9f317f1df3badfd882e93412bff8475abbaff013 | |
parent | 5e4748175fe942c86cbab840e2fa41a92b4d6cf6 (diff) |
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: 61b4de4e0b384f4a ("of: overlay: minor restructuring")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r-- | drivers/of/overlay.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index fcce5cdbe229..83bb2edfc65c 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c | |||
@@ -572,9 +572,10 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, | |||
572 | 572 | ||
573 | cnt = 0; | 573 | cnt = 0; |
574 | for_each_child_of_node(tree, node) { | 574 | for_each_child_of_node(tree, node) { |
575 | fragment = &fragments[cnt]; | 575 | overlay_node = of_get_child_by_name(node, "__overlay__"); |
576 | fragment->overlay = of_get_child_by_name(node, "__overlay__"); | 576 | if (overlay_node) { |
577 | if (fragment->overlay) { | 577 | fragment = &fragments[cnt]; |
578 | fragment->overlay = overlay_node; | ||
578 | fragment->target = find_target_node(node); | 579 | fragment->target = find_target_node(node); |
579 | if (!fragment->target) { | 580 | if (!fragment->target) { |
580 | of_node_put(fragment->overlay); | 581 | of_node_put(fragment->overlay); |