clk: check for invalid parent index of orphans in __clk_init()
PATCH 1/1 clk: check for invalid parent index of orphans in __clk_init()
If a mux clock is initialised (by hardware or firmware) with an invalid parent, its ->get_parent() can return an out of range index. For example, the generic mux clock attempts to return -EINVAL, which due to the u8 return type ends up a rather large number. Using this index with the parent_names[] array results in an invalid pointer and (usually) a crash in the following strcmp().
This patch adds a check for the parent index being in range, ignoring clocks reporting invalid values.
--- drivers/clk/clk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/clk.c +2 -1
@@ -1950,7 +1950,8 @@ int __clk_init(struct device *dev, struct clk *clk)hlist_for_each_entry_safe (orphan, tmp2, &clk_orphan_list, child_node) {if (orphan->num_parents && orphan->ops->get_parent) { i = orphan->ops->get_parent (orphan->hw); -if (!strcmp (clk->name, orphan->parent_names[i])) +if (i >=0 && i < orphan->num_parents && + !strcmp (clk->name, orphan->parent_names[i]))__clk_reparent (orphan, clk);continue ; }
Signature · 1 line
2.3.0
Quoted 23 lines · Mans Rullgard
If a mux clock is initialised (by hardware or firmware) with an invalid parent, its ->get_parent() can return an out of range index. For example, the generic mux clock attempts to return
-EINVAL, which due to the u8 return type ends up a rather large number. Using this index with the parent_names[] array results in an invalid pointer and (usually) a crash in the followingstrcmp().This patch adds a check for the parent index being in range, ignoring clocks reporting invalid values.
Signed-off-by Mans Rullgard <[email protected]>Cc Rhyland Klein <[email protected]>--- drivers/clk/clk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/clk/clk.c +0
-0
drivers/clk/clk.c int __clk_init(struct device *dev, struct clk *clk) · line 1957
Quoted 9 lines
drivers/clk/clk.c +2
-1@@ -1950,7 +1950,8 @@ int __clk_init(struct device *dev, struct clk *clk)hlist_for_each_entry_safe (orphan, tmp2, &clk_orphan_list, child_node) {if (orphan->num_parents && orphan->ops->get_parent) { i = orphan->ops->get_parent (orphan->hw); -if (!strcmp (clk->name, orphan->parent_names[i])) +if (i >=0 && i < orphan->num_parents && + !strcmp (clk->name, orphan->parent_names[i]))__clk_reparent (orphan, clk);continue ; }
This works for me and is less invasive than the original patch series.
-rhyland
Signature · 1 line
nvpublic
Michael Turquette
AppliedQuoting Rhyland Klein (2015-02-17 08:58:29)
Quoted 36 lines · Mans Rullgard
Quoted 23 lines
If a mux clock is initialised (by hardware or firmware) with an invalid parent, its ->get_parent() can return an out of range index. For example, the generic mux clock attempts to return
-EINVAL, which due to the u8 return type ends up a rather large number. Using this index with the parent_names[] array results in an invalid pointer and (usually) a crash in the followingstrcmp().This patch adds a check for the parent index being in range, ignoring clocks reporting invalid values.
Signed-off-by Mans Rullgard <[email protected]>Cc Rhyland Klein <[email protected]>--- drivers/clk/clk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/clk/clk.c +0
-0drivers/clk/clk.c int __clk_init(struct device *dev, struct clk *clk) · line 1957
Quoted 9 lines
drivers/clk/clk.c +2
-1@@ -1950,7 +1950,8 @@ int __clk_init(struct device *dev, struct clk *clk)hlist_for_each_entry_safe (orphan, tmp2, &clk_orphan_list, child_node) {if (orphan->num_parents && orphan->ops->get_parent) { i = orphan->ops->get_parent (orphan->hw); -if (!strcmp (clk->name, orphan->parent_names[i])) +if (i >=0 && i < orphan->num_parents && + !strcmp (clk->name, orphan->parent_names[i]))__clk_reparent (orphan, clk);continue ; }This works for me and is less invasive than the original patch series.
Quoted 1 line
Tested-by Rhyland Klein <[email protected]>
Applied.
Thanks,
Mike
Quoted 5 lines
-rhyland
Signature · 1 line
nvpublic
Quoted 37 lines · Michael Turquette
Quoting Rhyland Klein (2015-02-17 08:58:29)
Quoted 36 lines · Mans Rullgard
Quoted 23 lines
If a mux clock is initialised (by hardware or firmware) with an invalid parent, its ->get_parent() can return an out of range index. For example, the generic mux clock attempts to return
-EINVAL, which due to the u8 return type ends up a rather large number. Using this index with the parent_names[] array results in an invalid pointer and (usually) a crash in the followingstrcmp().This patch adds a check for the parent index being in range, ignoring clocks reporting invalid values.
Signed-off-by Mans Rullgard <[email protected]>Cc Rhyland Klein <[email protected]>--- drivers/clk/clk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/clk/clk.c +0
-0drivers/clk/clk.c int __clk_init(struct device *dev, struct clk *clk) · line 1957
Quoted 9 lines
drivers/clk/clk.c +2
-1@@ -1950,7 +1950,8 @@ int __clk_init(struct device *dev, struct clk *clk)hlist_for_each_entry_safe (orphan, tmp2, &clk_orphan_list, child_node) {if (orphan->num_parents && orphan->ops->get_parent) { i = orphan->ops->get_parent (orphan->hw); -if (!strcmp (clk->name, orphan->parent_names[i])) +if (i >=0 && i < orphan->num_parents && + !strcmp (clk->name, orphan->parent_names[i]))__clk_reparent (orphan, clk);continue ; }This works for me and is less invasive than the original patch series.
Quoted 3 lines
Quoted 1 line
Tested-by Rhyland Klein <[email protected]>Applied.
Did this get lost somewhere? It's not in mainline, and I can't find it in the clk tree on kernel.org either.
Signature · 2 lines
Måns Rullgård [email protected]
Quoted 39 lines · Måns Rullgård
Quoted 37 lines · Michael Turquette
Quoting Rhyland Klein (2015-02-17 08:58:29)
Quoted 36 lines · Mans Rullgard
Quoted 23 lines
If a mux clock is initialised (by hardware or firmware) with an invalid parent, its ->get_parent() can return an out of range index. For example, the generic mux clock attempts to return
-EINVAL, which due to the u8 return type ends up a rather large number. Using this index with the parent_names[] array results in an invalid pointer and (usually) a crash in the followingstrcmp().This patch adds a check for the parent index being in range, ignoring clocks reporting invalid values.
Signed-off-by Mans Rullgard <[email protected]>Cc Rhyland Klein <[email protected]>--- drivers/clk/clk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/clk/clk.c +0
-0drivers/clk/clk.c int __clk_init(struct device *dev, struct clk *clk) · line 1957
Quoted 9 lines
drivers/clk/clk.c +2
-1@@ -1950,7 +1950,8 @@ int __clk_init(struct device *dev, struct clk *clk)hlist_for_each_entry_safe (orphan, tmp2, &clk_orphan_list, child_node) {if (orphan->num_parents && orphan->ops->get_parent) { i = orphan->ops->get_parent (orphan->hw); -if (!strcmp (clk->name, orphan->parent_names[i])) +if (i >=0 && i < orphan->num_parents && + !strcmp (clk->name, orphan->parent_names[i]))__clk_reparent (orphan, clk);continue ; }This works for me and is less invasive than the original patch series.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Tested-by Rhyland Klein <[email protected]>Applied.
Did this get lost somewhere? It's not in mainline, and I can't find it in the clk tree on kernel.org either.
I think it got lost. I've applied this to clk-fixes.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project