From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Zhenzhong Duan <zhenzhong.duan@gmail.com>,
Mark Brown <broonie@kernel.org>, Sasha Levin <sashal@kernel.org>,
linux-spi@vger.kernel.org
Subject: [PATCH AUTOSEL 4.14 05/17] spi: spidev: fix a race between spidev_release and spidev_remove
Date: Wed, 1 Jul 2020 21:26:37 -0400 [thread overview]
Message-ID: <20200702012649.2701799-5-sashal@kernel.org> (raw)
In-Reply-To: <20200702012649.2701799-1-sashal@kernel.org>
From: Zhenzhong Duan <zhenzhong.duan@gmail.com>
[ Upstream commit abd42781c3d2155868821f1b947ae45bbc33330d ]
Imagine below scene, spidev is referenced after it's freed.
spidev_release() spidev_remove()
...
spin_lock_irq(&spidev->spi_lock);
spidev->spi = NULL;
spin_unlock_irq(&spidev->spi_lock);
mutex_lock(&device_list_lock);
dofree = (spidev->spi == NULL);
if (dofree)
kfree(spidev);
mutex_unlock(&device_list_lock);
mutex_lock(&device_list_lock);
list_del(&spidev->device_entry);
device_destroy(spidev_class, spidev->devt);
clear_bit(MINOR(spidev->devt), minors);
if (spidev->users == 0)
kfree(spidev);
mutex_unlock(&device_list_lock);
Fix it by resetting spidev->spi in device_list_lock's protection.
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@gmail.com>
Link: https://lore.kernel.org/r/20200618032125.4650-1-zhenzhong.duan@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/spi/spidev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 028725573e632..5edf4029a3486 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -782,13 +782,13 @@ static int spidev_remove(struct spi_device *spi)
{
struct spidev_data *spidev = spi_get_drvdata(spi);
+ /* prevent new opens */
+ mutex_lock(&device_list_lock);
/* make sure ops on existing fds can abort cleanly */
spin_lock_irq(&spidev->spi_lock);
spidev->spi = NULL;
spin_unlock_irq(&spidev->spi_lock);
- /* prevent new opens */
- mutex_lock(&device_list_lock);
list_del(&spidev->device_entry);
device_destroy(spidev_class, spidev->devt);
clear_bit(MINOR(spidev->devt), minors);
--
2.25.1
next prev parent reply other threads:[~2020-07-02 1:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-02 1:26 [PATCH AUTOSEL 4.14 01/17] ARM: dts: omap4-droid4: Fix spi configuration and increase rate Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 02/17] gpu: host1x: Detach driver on unregister Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 03/17] net: usb: ax88179_178a: fix packet alignment padding Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 04/17] usb: usbtest: fix missing kfree(dev->buf) in usbtest_disconnect Sasha Levin
2020-07-02 1:26 ` Sasha Levin [this message]
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 06/17] spi: spidev: fix a potential use-after-free in spidev_release() Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 07/17] tg3: driver sleeps indefinitely when EEH errors exceed eeh_max_freezes Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 08/17] ixgbe: protect ring accesses with READ- and WRITE_ONCE Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 09/17] usbnet: smsc95xx: Fix use-after-free after removal Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 10/17] s390/kasan: fix early pgm check handler execution Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 11/17] cifs: Fix double add page to memcg when cifs_readpages Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 12/17] cifs: update ctime and mtime during truncate Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 13/17] ARM: imx6: add missing put_device() call in imx6q_suspend_init() Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 14/17] scsi: mptscsih: Fix read sense data size Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 15/17] nvme-rdma: assign completion vector correctly Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 16/17] x86/entry: Increase entry_stack size to a full page Sasha Levin
2020-07-02 1:26 ` [PATCH AUTOSEL 4.14 17/17] kgdb: Avoid suspicious RCU usage warning Sasha Levin
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=20200702012649.2701799-5-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=zhenzhong.duan@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox