From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Hannes Reinecke <hare@suse.de>,
Brian Bunker <brian@purestorage.com>,
Jitendra Khasdev <jitendra.khasdev@oracle.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Sasha Levin <sashal@kernel.org>,
linux-scsi@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 13/21] scsi: scsi_dh_alua: Avoid crash during alua_bus_detach()
Date: Mon, 9 Nov 2020 22:55:33 -0500 [thread overview]
Message-ID: <20201110035541.424648-13-sashal@kernel.org> (raw)
In-Reply-To: <20201110035541.424648-1-sashal@kernel.org>
From: Hannes Reinecke <hare@suse.de>
[ Upstream commit 5faf50e9e9fdc2117c61ff7e20da49cd6a29e0ca ]
alua_bus_detach() might be running concurrently with alua_rtpg_work(), so
we might trip over h->sdev == NULL and call BUG_ON(). The correct way of
handling it is to not set h->sdev to NULL in alua_bus_detach(), and call
rcu_synchronize() before the final delete to ensure that all concurrent
threads have left the critical section. Then we can get rid of the
BUG_ON() and replace it with a simple if condition.
Link: https://lore.kernel.org/r/1600167537-12509-1-git-send-email-jitendra.khasdev@oracle.com
Link: https://lore.kernel.org/r/20200924104559.26753-1-hare@suse.de
Cc: Brian Bunker <brian@purestorage.com>
Acked-by: Brian Bunker <brian@purestorage.com>
Tested-by: Jitendra Khasdev <jitendra.khasdev@oracle.com>
Reviewed-by: Jitendra Khasdev <jitendra.khasdev@oracle.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/scsi/device_handler/scsi_dh_alua.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index c95c782b93a53..60c48dc5d9453 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -672,8 +672,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
rcu_read_lock();
list_for_each_entry_rcu(h,
&tmp_pg->dh_list, node) {
- /* h->sdev should always be valid */
- BUG_ON(!h->sdev);
+ if (!h->sdev)
+ continue;
h->sdev->access_state = desc[0];
}
rcu_read_unlock();
@@ -719,7 +719,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
pg->expiry = 0;
rcu_read_lock();
list_for_each_entry_rcu(h, &pg->dh_list, node) {
- BUG_ON(!h->sdev);
+ if (!h->sdev)
+ continue;
h->sdev->access_state =
(pg->state & SCSI_ACCESS_STATE_MASK);
if (pg->pref)
@@ -1160,7 +1161,6 @@ static void alua_bus_detach(struct scsi_device *sdev)
spin_lock(&h->pg_lock);
pg = rcu_dereference_protected(h->pg, lockdep_is_held(&h->pg_lock));
rcu_assign_pointer(h->pg, NULL);
- h->sdev = NULL;
spin_unlock(&h->pg_lock);
if (pg) {
spin_lock_irq(&pg->lock);
@@ -1169,6 +1169,7 @@ static void alua_bus_detach(struct scsi_device *sdev)
kref_put(&pg->kref, release_port_group);
}
sdev->handler_data = NULL;
+ synchronize_rcu();
kfree(h);
}
--
2.27.0
next prev parent reply other threads:[~2020-11-10 4:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-10 3:55 [PATCH AUTOSEL 4.19 01/21] usb: gadget: goku_udc: fix potential crashes in probe Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 02/21] ALSA: hda: Reinstate runtime_allow() for all hda controllers Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 03/21] gfs2: Free rd_bits later in gfs2_clear_rgrpd to fix use-after-free Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 04/21] gfs2: Add missing truncate_inode_pages_final for sd_aspace Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 05/21] gfs2: check for live vs. read-only file system in gfs2_fitrim Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 06/21] scsi: hpsa: Fix memory leak in hpsa_init_one() Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 07/21] drm/amdgpu: perform srbm soft reset always on SDMA resume Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 08/21] drm/amd/pm: perform SMC reset on suspend/hibernation Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 09/21] drm/amd/pm: do not use ixFEATURE_STATUS for checking smc running Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 10/21] mac80211: fix use of skb payload instead of header Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 11/21] mac80211: always wind down STA state Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 12/21] cfg80211: regulatory: Fix inconsistent format argument Sasha Levin
2020-11-10 3:55 ` Sasha Levin [this message]
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 14/21] iommu/amd: Increase interrupt remapping table limit to 512 entries Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 15/21] s390/smp: move rcu_cpu_starting() earlier Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 16/21] vfio: platform: fix reference leak in vfio_platform_open Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 17/21] net: usb: qmi_wwan: add Telit LE910Cx 0x1230 composition Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 18/21] kprobes: Tell lockdep about kprobe nesting Sasha Levin
2020-11-10 6:44 ` Masami Hiramatsu
2020-11-14 22:58 ` Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 19/21] selftests: proc: fix warning: _GNU_SOURCE redefined Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 20/21] tpm_tis: Disable interrupts on ThinkPad T490s Sasha Levin
2020-11-10 3:55 ` [PATCH AUTOSEL 4.19 21/21] vt: Disable KD_FONT_OP_COPY 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=20201110035541.424648-13-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=brian@purestorage.com \
--cc=hare@suse.de \
--cc=jitendra.khasdev@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stable@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).