Re: [PATCH] pinctrl: avoid unsafe code pattern in find_pinctrl()

From: Linus Walleij
Date: Mon Sep 25 2023 - 09:31:12 EST


On Wed, Sep 20, 2023 at 8:09 PM Dmitry Torokhov
<dmitry.torokhov@xxxxxxxxx> wrote:

> The code in find_pinctrl() takes a mutex and traverses a list of pinctrl
> structures. Later the caller bumps up reference count on the found
> structure. Such pattern is not safe as pinctrl that was found may get
> deleted before the caller gets around to increasing the reference count.
>
> Fix this by taking the reference count in find_pinctrl(), while it still
> holds the mutex.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>

After some thinking, applied for fixes and tagged for stable as
it is a very real problem that can cause random crashes under
the right circumstances.

Thanks for finding this Dmitry!!

Yours,
Linus Walleij