All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	Ferry Toth <ftoth@exalondelft.nl>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] pinctrl: avoid unsafe code pattern in find_pinctrl()
Date: Tue, 17 Oct 2023 17:14:36 +0300	[thread overview]
Message-ID: <ZS6WzGauyQmdANec@smile.fi.intel.com> (raw)
In-Reply-To: <ZS6VReT2Md9UNjFu@smile.fi.intel.com>

On Tue, Oct 17, 2023 at 05:08:05PM +0300, Andy Shevchenko wrote:
> On Mon, Sep 25, 2023 at 03:30:53PM +0200, Linus Walleij wrote:
> > On Wed, Sep 20, 2023 at 8:09 PM Dmitry Torokhov
> > <dmitry.torokhov@gmail.com> 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@gmail.com>
> > 
> > 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.
> 
> Follow the strange and weird bisection [1] this one at least confirmed to be
> the culprit by reverting the only one from the v6.6-rc6 based branch.
> 
> Long story short, after this commit my user space setup (minimal Buildroot + Busybox)
> has become broken in a sense of MMC enumeration. My all scripts were pointed to
> mmcblk0 which becomes out of a sudden mmcblk1!

`dmesg` after revert:

[   36.439057] mmc0: SDHCI controller on PCI [0000:00:01.0] using ADMA
[   36.450924] mmc2: SDHCI controller on PCI [0000:00:01.3] using ADMA
[   36.459355] mmc1: SDHCI controller on PCI [0000:00:01.2] using ADMA
[   36.706399] mmc0: new DDR MMC card at address 0001
[   37.058972] mmc2: new ultra high speed DDR50 SDIO card at address 0001
[   37.278977] mmcblk0: mmc0:0001 H4G1d 3.64 GiB
[   37.297300]  mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10

and before:

[   36.436704] mmc2: SDHCI controller on PCI [0000:00:01.3] using ADMA
[   36.436720] mmc1: SDHCI controller on PCI [0000:00:01.0] using ADMA
[   36.463685] mmc0: SDHCI controller on PCI [0000:00:01.2] using ADMA
[   36.720627] mmc1: new DDR MMC card at address 0001
[   37.068181] mmc2: new ultra high speed DDR50 SDIO card at address 0001
[   37.279998] mmcblk1: mmc1:0001 H4G1d 3.64 GiB
[   37.302670]  mmcblk1: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10

Reproducibility 100%.

> git bisect start
> # status: waiting for both good and bad commits
> # bad: [58720809f52779dc0f08e53e54b014209d13eebb] Linux 6.6-rc6
> git bisect bad 58720809f52779dc0f08e53e54b014209d13eebb
> # status: waiting for good commit(s), bad commit known
> # good: [2dde18cd1d8fac735875f2e4987f11817cc0bc2c] Linux 6.5
> git bisect good 2dde18cd1d8fac735875f2e4987f11817cc0bc2c
> # good: [47ca50600efcf994adb62a9a4e75c77d91bd0781] Merge tag 'soc-defconfig-6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
> git bisect good 47ca50600efcf994adb62a9a4e75c77d91bd0781
> # good: [b89b029377c8c441649c7a6be908386e74ea9420] Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
> git bisect good b89b029377c8c441649c7a6be908386e74ea9420
> # good: [2a5a4326e58339a26cd1510259e7310b8c0980ff] Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
> git bisect good 2a5a4326e58339a26cd1510259e7310b8c0980ff
> # good: [85eba5f1759f9eb89273225027254ced57bd18a2] Merge tag 'mm-hotfixes-stable-2023-09-23-10-31' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> git bisect good 85eba5f1759f9eb89273225027254ced57bd18a2
> # good: [b78b18fb8ee19f7a05f20c3abc865b3bfe182884] Merge tag 'erofs-for-6.6-rc5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs
> git bisect good b78b18fb8ee19f7a05f20c3abc865b3bfe182884
> # bad: [9a5a14948574ee09f339990cab69b4ab997d2f7d] Merge tag 'soc-fixes-6.6-2' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
> git bisect bad 9a5a14948574ee09f339990cab69b4ab997d2f7d
> # good: [b9ddbb0cde2adcedda26045cc58f31316a492215] Merge tag 'parisc-for-6.6-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux
> git bisect good b9ddbb0cde2adcedda26045cc58f31316a492215
> # good: [b711538a40b794ccc83838fb66990a091c56c101] Merge tag 'hyperv-fixes-signed-20231009' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux
> git bisect good b711538a40b794ccc83838fb66990a091c56c101
> # good: [bab19d1b21547046b0a38dde948086f6cbcaefaa] Merge tag 'for-linus-2023101101' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
> git bisect good bab19d1b21547046b0a38dde948086f6cbcaefaa
> # bad: [82a040a8fa9b4f3845eff73a69a9931a59335902] Merge tag 'pinctrl-v6.6-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl
> git bisect bad 82a040a8fa9b4f3845eff73a69a9931a59335902
> # good: [759d1b653f3c7c2249b7fe5f6b218f87a5842822] Merge tag 'for-6.6-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
> git bisect good 759d1b653f3c7c2249b7fe5f6b218f87a5842822
> # bad: [c153a4edff6ab01370fcac8e46f9c89cca1060c2] pinctrl: avoid unsafe code pattern in find_pinctrl()
> git bisect bad c153a4edff6ab01370fcac8e46f9c89cca1060c2
> # good: [87d315a34133edcb29c4cadbf196ec6c30dfd47b] pinctrl: nuvoton: wpcm450: fix out of bounds write
> git bisect good 87d315a34133edcb29c4cadbf196ec6c30dfd47b
> # good: [64061b67335e958e6328bcb5bb2b5490d57f3f59] pinctrl: starfive: jh7110: Add system pm ops to save and restore context
> git bisect good 64061b67335e958e6328bcb5bb2b5490d57f3f59
> # first bad commit: [c153a4edff6ab01370fcac8e46f9c89cca1060c2] pinctrl: avoid unsafe code pattern in find_pinctrl()
> 
> [1]: https://lore.kernel.org/r/20230830102434.xnlh66omhs6ninet@quack3

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2023-10-17 14:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 18:09 [PATCH] pinctrl: avoid unsafe code pattern in find_pinctrl() Dmitry Torokhov
2023-09-25 13:30 ` Linus Walleij
2023-10-17 14:08   ` Andy Shevchenko
2023-10-17 14:14     ` Andy Shevchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZS6WzGauyQmdANec@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=ftoth@exalondelft.nl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.