Re: [PATCH] opp: Fix use-after-free in lazy_opp_tables after probe deferral

From: Stephan Gerhold
Date: Tue May 30 2023 - 12:47:32 EST


On Tue, May 30, 2023 at 02:43:30PM +0530, Viresh Kumar wrote:
> On 30-05-23, 10:31, Stephan Gerhold wrote:
> > Thanks, this seems to fix the crash as well. Are you going to handle it
> > or should I send a v2 with this diff?
>
> Please send a V2 :)
>

Done!

> > During _allocate_opp_table() it's accessed without the opp_table_lock,
> > because of
> >
> > /* Drop the lock to reduce the size of critical section */
> > mutex_unlock(&opp_table_lock);
> >
> > if (opp_table) {
> > /* ... */
> > mutex_lock(&opp_table_lock);
> > } else {
> > opp_table = _allocate_opp_table(dev, index);
> >
> > mutex_lock(&opp_table_lock);
> > /* ... */
> > }
> >
> > This doesn't seem to cause any problems in my case though so it's
> > unrelated to the crash I observed.
>
> Hmm, right. Maybe we need a lock for that list, want to take that up ?
>

Yeah, a lock would probably be good to be safe. I would appreciate if
you or someone else could create a patch for this though, since I'm not
too familiar with the overall OPP implementation. I would be happy to
test that it works properly for my apparently quite special use case
(I have several OPP tables with interconnects and required-opps).

Thanks!
Stephan
--
Kernkonzept GmbH at Dresden, Germany, HRB 31129, CEO Dr.-Ing. Michael Hohmuth