Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1225246 > unrolled thread

Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init()

Started byMåns Rullgård <mans@mansr.com>
First post2015-09-15 16:50 +0200
Last post2015-09-18 00:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init() Måns Rullgård <mans@mansr.com> - 2015-09-15 16:50 +0200
    Re: [PATCH] clk: check for invalid parent index of orphans in  __clk_init() Stephen Boyd <sboyd@codeaurora.org> - 2015-09-18 00:30 +0200

#1225246 — Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init()

FromMåns Rullgård <mans@mansr.com>
Date2015-09-15 16:50 +0200
SubjectRe: [PATCH] clk: check for invalid parent index of orphans in __clk_init()
Message-ID<q8ZIv-7Nu-29@gated-at.bofh.it>
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1227459 — Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init()

FromStephen Boyd <sboyd@codeaurora.org>
Date2015-09-18 00:30 +0200
SubjectRe: [PATCH] clk: check for invalid parent index of orphans in __clk_init()
Message-ID<q9PQJ-rH-11@gated-at.bofh.it>
In reply to#1225246
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web