* [PATCH] clk: check for invalid parent index of orphans in __clk_init()
@ 2015-02-15 12:33 Mans Rullgard
2015-02-17 16:58 ` Rhyland Klein
0 siblings, 1 reply; 5+ messages in thread
From: Mans Rullgard @ 2015-02-15 12:33 UTC (permalink / raw)
To: Mike Turquette, Stephen Boyd, linux-kernel; +Cc: Rhyland Klein
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.
Signed-off-by: Mans Rullgard <mans@mansr.com>
Cc: Rhyland Klein <rklein@nvidia.com>
---
drivers/clk/clk.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index d48ac71..bc0662b 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -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;
}
--
2.3.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init()
2015-02-15 12:33 [PATCH] clk: check for invalid parent index of orphans in __clk_init() Mans Rullgard
@ 2015-02-17 16:58 ` Rhyland Klein
2015-04-13 19:12 ` Michael Turquette
0 siblings, 1 reply; 5+ messages in thread
From: Rhyland Klein @ 2015-02-17 16:58 UTC (permalink / raw)
To: Mans Rullgard, Mike Turquette, Stephen Boyd, linux-kernel
On 2/15/2015 7:33 AM, Mans Rullgard wrote:
> 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.
>
> Signed-off-by: Mans Rullgard <mans@mansr.com>
> Cc: Rhyland Klein <rklein@nvidia.com>
> ---
> drivers/clk/clk.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index d48ac71..bc0662b 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -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.
Tested-by: Rhyland Klein <rklein@nvidia.com>
-rhyland
--
nvpublic
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init()
2015-02-17 16:58 ` Rhyland Klein
@ 2015-04-13 19:12 ` Michael Turquette
2015-09-15 14:37 ` Måns Rullgård
0 siblings, 1 reply; 5+ messages in thread
From: Michael Turquette @ 2015-04-13 19:12 UTC (permalink / raw)
To: Rhyland Klein, Mans Rullgard, Stephen Boyd, linux-kernel
Quoting Rhyland Klein (2015-02-17 08:58:29)
> On 2/15/2015 7:33 AM, Mans Rullgard wrote:
> > 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.
> >
> > Signed-off-by: Mans Rullgard <mans@mansr.com>
> > Cc: Rhyland Klein <rklein@nvidia.com>
> > ---
> > drivers/clk/clk.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> > index d48ac71..bc0662b 100644
> > --- a/drivers/clk/clk.c
> > +++ b/drivers/clk/clk.c
> > @@ -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.
>
> Tested-by: Rhyland Klein <rklein@nvidia.com>
Applied.
Thanks,
Mike
>
> -rhyland
>
> --
> nvpublic
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init()
2015-04-13 19:12 ` Michael Turquette
@ 2015-09-15 14:37 ` Måns Rullgård
2015-09-17 22:25 ` Stephen Boyd
0 siblings, 1 reply; 5+ messages in thread
From: Måns Rullgård @ 2015-09-15 14:37 UTC (permalink / raw)
To: Michael Turquette; +Cc: Rhyland Klein, Stephen Boyd, linux-kernel
Michael Turquette <mturquette@linaro.org> writes:
> Quoting Rhyland Klein (2015-02-17 08:58:29)
>> On 2/15/2015 7:33 AM, Mans Rullgard wrote:
>> > 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.
>> >
>> > Signed-off-by: Mans Rullgard <mans@mansr.com>
>> > Cc: Rhyland Klein <rklein@nvidia.com>
>> > ---
>> > drivers/clk/clk.c | 3 ++-
>> > 1 file changed, 2 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
>> > index d48ac71..bc0662b 100644
>> > --- a/drivers/clk/clk.c
>> > +++ b/drivers/clk/clk.c
>> > @@ -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.
>>
>> Tested-by: Rhyland Klein <rklein@nvidia.com>
>
> 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.
--
Måns Rullgård
mans@mansr.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init()
2015-09-15 14:37 ` Måns Rullgård
@ 2015-09-17 22:25 ` Stephen Boyd
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2015-09-17 22:25 UTC (permalink / raw)
To: Måns Rullgård; +Cc: Michael Turquette, Rhyland Klein, linux-kernel
On 09/15, Måns Rullgård wrote:
> Michael Turquette <mturquette@linaro.org> writes:
>
> > Quoting Rhyland Klein (2015-02-17 08:58:29)
> >> On 2/15/2015 7:33 AM, Mans Rullgard wrote:
> >> > 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.
> >> >
> >> > Signed-off-by: Mans Rullgard <mans@mansr.com>
> >> > Cc: Rhyland Klein <rklein@nvidia.com>
> >> > ---
> >> > drivers/clk/clk.c | 3 ++-
> >> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >> >
> >> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> >> > index d48ac71..bc0662b 100644
> >> > --- a/drivers/clk/clk.c
> >> > +++ b/drivers/clk/clk.c
> >> > @@ -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.
> >>
> >> Tested-by: Rhyland Klein <rklein@nvidia.com>
> >
> > 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.
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-09-17 22:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-15 12:33 [PATCH] clk: check for invalid parent index of orphans in __clk_init() Mans Rullgard
2015-02-17 16:58 ` Rhyland Klein
2015-04-13 19:12 ` Michael Turquette
2015-09-15 14:37 ` Måns Rullgård
2015-09-17 22:25 ` Stephen Boyd
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.