]> git.baikalelectronics.ru Git - kernel.git/commit
of: overlay: Fix out-of-bounds write in init_overlay_changeset()
authorGeert Uytterhoeven <geert+renesas@glider.be>
Fri, 8 Dec 2017 13:13:02 +0000 (14:13 +0100)
committerRob Herring <robh@kernel.org>
Fri, 8 Dec 2017 15:32:10 +0000 (09:32 -0600)
commitb3ac41b4b7131b6a5c576d30ade4fa70f1bcf2bb
tree9f317f1df3badfd882e93412bff8475abbaff013
parentc58a85af3d14092872c6f28cb793c5185dff070a
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: 0039dca651be8686 ("of: overlay: minor restructuring")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Rob Herring <robh@kernel.org>
drivers/of/overlay.c