reset: Fix potential use-after-free in __of_reset_control_get()

Calling of_node_put() decreases the reference count of a device tree
object, and may free some data.

However, the of_phandle_args structure embedding it is passed to
reset_controller_dev.of_xlate() after that, so it may still be accessed.

Move the call to of_node_put() down to fix this.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
[p.zabel@pengutronix.de: moved of_node_put after mutex_unlock]
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
This commit is contained in:
Geert Uytterhoeven 2018-10-08 13:14:35 +02:00 committed by Philipp Zabel
parent eea2926b0a
commit b790c8ea55
1 changed files with 8 additions and 7 deletions

View File

@ -496,28 +496,29 @@ struct reset_control *__of_reset_control_get(struct device_node *node,
break; break;
} }
} }
of_node_put(args.np);
if (!rcdev) { if (!rcdev) {
mutex_unlock(&reset_list_mutex); rstc = ERR_PTR(-EPROBE_DEFER);
return ERR_PTR(-EPROBE_DEFER); goto out;
} }
if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) { if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) {
mutex_unlock(&reset_list_mutex); rstc = ERR_PTR(-EINVAL);
return ERR_PTR(-EINVAL); goto out;
} }
rstc_id = rcdev->of_xlate(rcdev, &args); rstc_id = rcdev->of_xlate(rcdev, &args);
if (rstc_id < 0) { if (rstc_id < 0) {
mutex_unlock(&reset_list_mutex); rstc = ERR_PTR(rstc_id);
return ERR_PTR(rstc_id); goto out;
} }
/* reset_list_mutex also protects the rcdev's reset_control list */ /* reset_list_mutex also protects the rcdev's reset_control list */
rstc = __reset_control_get_internal(rcdev, rstc_id, shared); rstc = __reset_control_get_internal(rcdev, rstc_id, shared);
out:
mutex_unlock(&reset_list_mutex); mutex_unlock(&reset_list_mutex);
of_node_put(args.np);
return rstc; return rstc;
} }