[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAD++jL=Ejfjvj7n19jpCHfB6U1QkOAZZRKqx0ToFSLS91JtNHw@mail.gmail.com>
Date: Mon, 22 Dec 2025 23:35:59 +0100
From: Linus Walleij <linusw@...nel.org>
To: Waqar Hameed <waqar.hameed@...s.com>
Cc: Sebastian Reichel <sre@...nel.org>, kernel@...s.com, linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 01/11] power: supply: ab8500: Fix use-after-free in power_supply_changed()
Hi Waqar,
thanks a lot for looking into this!
On Sat, Dec 20, 2025 at 11:36 PM Waqar Hameed <waqar.hameed@...s.com> wrote:
> Using the `devm_` variant for requesting IRQ _before_ the `devm_`
> variant for allocating/registering the `power_supply` handle, means that
> the `power_supply` handle will be deallocated/unregistered _before_ the
> interrupt handler (since `devm_` naturally deallocates in reverse
> allocation order). This means that during removal, there is a race
> condition where an interrupt can fire just _after_ the `power_supply`
> handle has been freed, *but* just _before_ the corresponding
> unregistration of the IRQ handler has run.
>
> This will lead to the IRQ handler calling `power_supply_changed()` with
> a freed `power_supply` handle. Which usually crashes the system or
> otherwise silently corrupts the memory...
>
> Note that there is a similar situation which can also happen during
> `probe()`; the possibility of an interrupt firing _before_ registering
> the `power_supply` handle. This would then lead to the nasty situation
> of using the `power_supply` handle *uninitialized* in
> `power_supply_changed()`.
>
> Commit 1c1f13a006ed ("power: supply: ab8500: Move to componentized
> binding") introduced this issue during a refactorization. Fix this racy
> use-after-free by making sure the IRQ is requested _after_ the
> registration of the `power_supply` handle.
>
> Fixes: 1c1f13a006ed ("power: supply: ab8500: Move to componentized binding")
> Signed-off-by: Waqar Hameed <waqar.hameed@...s.com>
Hats off, it's a clean and precise fix.
Reviewed-by: Linus Walleij <linusw@...nel.org>
Yours,
Linus Walleij
Powered by blists - more mailing lists