Skip to content

Commit

Permalink
of: Fix NULL dereference in selftest removal code
Browse files Browse the repository at this point in the history
The selftest code removes its testcase data from the live tree when
exiting, but if the testcases data tree contains an empty child of the
root, then it causes an oops due to a NULL dereference. The reason is
that the code tries to directly dereference the child pointer without
checking first if a child is actually there.

The solution is to pass the parent node into detach_node_and_children()
instead of trying to pass the child. This required removing the code
that attempts to remove all of the sibling nodes in
detach_node_and_children(), which was never sensible in the first place.

At the same time add a check to make sure the bounds of the nodes list
are not exceeded by the testdata tree. If they are then abort.

Signed-off-by: Grant Likely <[email protected]>
Cc: Gaurav Minocha <[email protected]>
  • Loading branch information
glikely committed Oct 1, 2014
1 parent fe82dce commit e66c98c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions drivers/of/selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ static int attach_node_and_children(struct device_node *np)
dup = np;

while (dup) {
if (WARN_ON(last_node_index >= NO_OF_NODES))
return -EINVAL;
nodes[last_node_index++] = dup;
dup = dup->sibling;
}
Expand Down Expand Up @@ -717,10 +719,6 @@ static void detach_node_and_children(struct device_node *np)
{
while (np->child)
detach_node_and_children(np->child);

while (np->sibling)
detach_node_and_children(np->sibling);

of_detach_node(np);
}

Expand Down Expand Up @@ -749,8 +747,7 @@ static void selftest_data_remove(void)
if (nodes[last_node_index]) {
np = of_find_node_by_path(nodes[last_node_index]->full_name);
if (strcmp(np->full_name, "/aliases") != 0) {
detach_node_and_children(np->child);
of_detach_node(np);
detach_node_and_children(np);
} else {
for_each_property_of_node(np, prop) {
if (strcmp(prop->name, "testcase-alias") == 0)
Expand Down

0 comments on commit e66c98c

Please sign in to comment.