From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Greg KH <gregkh@linuxfoundation.org>,
torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk, Junichi Nomura <j-nomura@ce.jp.nec.com>,
Bart Van Assche <bvanassche@acm.org>,
Mike Christie <michaelc@cs.wisc.edu>, Tejun Heo <tj@kernel.org>,
James Bottomley <JBottomley@Parallels.com>
Subject: [ 013/109] SCSI: Fix device removal NULL pointer dereference
Date: Tue, 7 Aug 2012 15:34:32 -0700 [thread overview]
Message-ID: <20120807222044.245484147@linuxfoundation.org> (raw)
In-Reply-To: <20120807222043.089735600@linuxfoundation.org>
From: Greg KH <gregkh@linuxfoundation.org>
3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <bvanassche@acm.org>
commit 67bd94130015c507011af37858989b199c52e1de upstream.
Use blk_queue_dead() to test whether the queue is dead instead
of !sdev. Since scsi_prep_fn() may be invoked concurrently with
__scsi_remove_device(), keep the queuedata (sdev) pointer in
__scsi_remove_device(). This patch fixes a kernel oops that
can be triggered by USB device removal. See also
http://www.spinics.net/lists/linux-scsi/msg56254.html.
Other changes included in this patch:
- Swap the blk_cleanup_queue() and kfree() calls in
scsi_host_dev_release() to make that code easier to grasp.
- Remove the queue dead check from scsi_run_queue() since the
queue state can change anyway at any point in that function
where the queue lock is not held.
- Remove the queue dead check from the start of scsi_request_fn()
since it is redundant with the scsi_device_online() check.
Reported-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Mike Christie <michaelc@cs.wisc.edu>
Reviewed-by: Tejun Heo <tj@kernel.org>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/scsi/hosts.c | 7 ++++---
drivers/scsi/scsi_lib.c | 32 ++++----------------------------
drivers/scsi/scsi_priv.h | 1 -
drivers/scsi/scsi_sysfs.c | 5 +----
4 files changed, 9 insertions(+), 36 deletions(-)
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -290,6 +290,7 @@ static void scsi_host_dev_release(struct
struct Scsi_Host *shost = dev_to_shost(dev);
struct device *parent = dev->parent;
struct request_queue *q;
+ void *queuedata;
scsi_proc_hostdir_rm(shost->hostt);
@@ -299,9 +300,9 @@ static void scsi_host_dev_release(struct
destroy_workqueue(shost->work_q);
q = shost->uspace_req_q;
if (q) {
- kfree(q->queuedata);
- q->queuedata = NULL;
- scsi_free_queue(q);
+ queuedata = q->queuedata;
+ blk_cleanup_queue(q);
+ kfree(queuedata);
}
scsi_destroy_command_freelist(shost);
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -406,10 +406,6 @@ static void scsi_run_queue(struct reques
LIST_HEAD(starved_list);
unsigned long flags;
- /* if the device is dead, sdev will be NULL, so no queue to run */
- if (!sdev)
- return;
-
shost = sdev->host;
if (scsi_target(sdev)->single_lun)
scsi_single_lun_run(sdev);
@@ -1370,16 +1366,16 @@ static inline int scsi_host_queue_ready(
* may be changed after request stacking drivers call the function,
* regardless of taking lock or not.
*
- * When scsi can't dispatch I/Os anymore and needs to kill I/Os
- * (e.g. !sdev), scsi needs to return 'not busy'.
- * Otherwise, request stacking drivers may hold requests forever.
+ * When scsi can't dispatch I/Os anymore and needs to kill I/Os scsi
+ * needs to return 'not busy'. Otherwise, request stacking drivers
+ * may hold requests forever.
*/
static int scsi_lld_busy(struct request_queue *q)
{
struct scsi_device *sdev = q->queuedata;
struct Scsi_Host *shost;
- if (!sdev)
+ if (blk_queue_dead(q))
return 0;
shost = sdev->host;
@@ -1490,12 +1486,6 @@ static void scsi_request_fn(struct reque
struct scsi_cmnd *cmd;
struct request *req;
- if (!sdev) {
- while ((req = blk_peek_request(q)) != NULL)
- scsi_kill_request(req, q);
- return;
- }
-
if(!get_device(&sdev->sdev_gendev))
/* We must be tearing the block queue down already */
return;
@@ -1697,20 +1687,6 @@ struct request_queue *scsi_alloc_queue(s
return q;
}
-void scsi_free_queue(struct request_queue *q)
-{
- unsigned long flags;
-
- WARN_ON(q->queuedata);
-
- /* cause scsi_request_fn() to kill all non-finished requests */
- spin_lock_irqsave(q->queue_lock, flags);
- q->request_fn(q);
- spin_unlock_irqrestore(q->queue_lock, flags);
-
- blk_cleanup_queue(q);
-}
-
/*
* Function: scsi_block_requests()
*
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -84,7 +84,6 @@ extern void scsi_next_command(struct scs
extern void scsi_io_completion(struct scsi_cmnd *, unsigned int);
extern void scsi_run_host_queues(struct Scsi_Host *shost);
extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev);
-extern void scsi_free_queue(struct request_queue *q);
extern int scsi_init_queue(void);
extern void scsi_exit_queue(void);
struct request_queue;
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -971,11 +971,8 @@ void __scsi_remove_device(struct scsi_de
sdev->host->hostt->slave_destroy(sdev);
transport_destroy_device(dev);
- /* cause the request function to reject all I/O requests */
- sdev->request_queue->queuedata = NULL;
-
/* Freeing the queue signals to block that we're done */
- scsi_free_queue(sdev->request_queue);
+ blk_cleanup_queue(sdev->request_queue);
put_device(dev);
}
next prev parent reply other threads:[~2012-08-07 22:37 UTC|newest]
Thread overview: 116+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-07 22:34 [ 000/109] 3.4.8-stable review Greg Kroah-Hartman
2012-08-07 22:34 ` [ 001/109] target: Add generation of LOGICAL BLOCK ADDRESS OUT OF RANGE Greg Kroah-Hartman
2012-08-07 22:34 ` [ 002/109] iscsi-target: Drop bogus struct file usage for iSCSI/SCTP Greg Kroah-Hartman
2012-08-07 22:34 ` [ 003/109] mmc: sdhci-pci: CaFe has broken card detection Greg Kroah-Hartman
2012-08-07 22:34 ` [ 004/109] mmc: sdhci: fix incorrect command used in tuning Greg Kroah-Hartman
2012-08-07 22:34 ` [ 005/109] powerpc/ftrace: Fix assembly trampoline register usage Greg Kroah-Hartman
2012-08-07 22:34 ` [ 006/109] powerpc: Add "memory" attribute for mfmsr() Greg Kroah-Hartman
2012-08-07 22:34 ` [ 007/109] powerpc/eeh: Check handle_eeh_events() return value Greg Kroah-Hartman
2012-08-07 22:34 ` [ 008/109] powerpc/85xx: use the BRx registers to enable indirect mode on the P1022DS Greg Kroah-Hartman
2012-08-07 22:34 ` [ 009/109] SCSI: libsas: continue revalidation Greg Kroah-Hartman
2012-08-07 22:34 ` [ 010/109] SCSI: libsas: fix sas_discover_devices return code handling Greg Kroah-Hartman
2012-08-07 22:34 ` [ 011/109] SCSI: fix eh wakeup (scsi_schedule_eh vs scsi_restart_operations) Greg Kroah-Hartman
2012-08-07 22:34 ` [ 012/109] SCSI: fix hot unplug vs async scan race Greg Kroah-Hartman
2012-08-07 22:34 ` Greg Kroah-Hartman [this message]
2012-08-07 22:34 ` [ 014/109] SCSI: Avoid dangling pointer in scsi_requeue_command() Greg Kroah-Hartman
2012-08-07 22:34 ` [ 015/109] rt2800usb: 2001:3c17 is an RT3370 device Greg Kroah-Hartman
2012-08-07 22:34 ` [ 016/109] ARM: OMAP2+: OPP: Fix to ensure check of right oppdef after bad one Greg Kroah-Hartman
2012-08-07 22:34 ` [ 017/109] ASoC: dapm: Fix locking during codec shutdown Greg Kroah-Hartman
2012-08-08 21:13 ` Herton Ronaldo Krzesinski
2012-08-09 10:08 ` Mark Brown
2012-08-09 15:18 ` Greg Kroah-Hartman
2012-08-07 22:34 ` [ 018/109] ASoC: dapm: Fix _PRE and _POST events for DAPM performance improvements Greg Kroah-Hartman
2012-08-07 22:34 ` [ 019/109] ASoC: wm8962: Redo early init of the part on resume Greg Kroah-Hartman
2012-08-07 22:34 ` [ 020/109] ALSA: hda - Add support for Realtek ALC282 Greg Kroah-Hartman
2012-08-07 22:34 ` [ 021/109] ALSA: hda - Turn on PIN_OUT from hdmi playback prepare Greg Kroah-Hartman
2012-08-07 22:34 ` [ 022/109] usbdevfs: Correct amount of data copied to user in processcompl_compat Greg Kroah-Hartman
2012-08-07 22:34 ` [ 023/109] usb: gadget: Fix g_ether interface link status Greg Kroah-Hartman
2012-08-07 22:34 ` [ 024/109] USB: option: add ZTE MF821D Greg Kroah-Hartman
2012-08-07 22:34 ` [ 025/109] Revert "usb/uas: make sure data urb is gone if we receive status before that" Greg Kroah-Hartman
2012-08-07 22:34 ` [ 026/109] ALSA: hda - add dock support for Thinkpad X230 Tablet Greg Kroah-Hartman
2012-08-07 22:34 ` [ 027/109] x86/mce: Fix siginfo_t->si_addr value for non-recoverable memory faults Greg Kroah-Hartman
2012-08-07 22:34 ` [ 028/109] locks: fix checking of fcntl_setlease argument Greg Kroah-Hartman
2012-08-07 22:34 ` [ 029/109] batman-adv: fix skb->data assignment Greg Kroah-Hartman
2012-08-09 1:53 ` Ben Hutchings
2012-08-09 15:17 ` Greg Kroah-Hartman
2012-08-07 22:34 ` [ 030/109] ftrace: Disable function tracing during suspend/resume and hibernation, again Greg Kroah-Hartman
2012-08-07 22:34 ` [ 031/109] PM / Sleep: call early resume handlers when suspend_noirq fails Greg Kroah-Hartman
2012-08-07 22:34 ` [ 032/109] TPM: chip disabled state erronously being reported as error Greg Kroah-Hartman
2012-08-07 22:34 ` [ 033/109] tun: fix a crash bug and a memory leak Greg Kroah-Hartman
2012-08-07 22:34 ` [ 034/109] mac80211: fail authentication when AP denied authentication Greg Kroah-Hartman
2012-08-07 22:34 ` [ 035/109] iwlwifi: fix debug print in iwl_sta_calc_ht_flags Greg Kroah-Hartman
2012-08-07 22:34 ` [ 036/109] rtlwifi: rtl8192cu: Change buffer allocation for synchronous reads Greg Kroah-Hartman
2012-08-07 22:34 ` [ 037/109] rtlwifi: rtl8192de: Fix phy-based version calculation Greg Kroah-Hartman
2012-08-07 22:34 ` [ 038/109] mwifiex: correction in mcs index check Greg Kroah-Hartman
2012-08-07 22:34 ` [ 039/109] s390/idle: fix sequence handling vs cpu hotplug Greg Kroah-Hartman
2012-08-07 22:34 ` [ 040/109] s390/mm: downgrade page table after fork of a 31 bit process Greg Kroah-Hartman
2012-08-07 22:35 ` [ 041/109] s390/mm: fix fault handling for page table walk case Greg Kroah-Hartman
2012-08-07 22:35 ` [ 042/109] iommu/amd: Add missing spin_lock initialization Greg Kroah-Hartman
2012-08-07 22:35 ` [ 043/109] iommu/amd: Fix hotplug with iommu=pt Greg Kroah-Hartman
2012-08-07 22:35 ` [ 044/109] udf: Improve table length check to avoid possible overflow Greg Kroah-Hartman
2012-08-07 22:35 ` [ 045/109] stable: update references to older 2.6 versions for 3.x Greg Kroah-Hartman
2012-08-07 22:35 ` [ 046/109] staging: zsmalloc: Finish conversion to a separate module Greg Kroah-Hartman
2012-08-07 22:35 ` [ 047/109] workqueue: perform cpu down operations from low priority cpu_notifier() Greg Kroah-Hartman
2012-08-07 22:35 ` [ 048/109] ACPI, APEI: Fixup common access width firmware bug Greg Kroah-Hartman
2012-08-07 22:35 ` [ 049/109] ACPI/AC: prevent OOPS on some boxes due to missing check power_supply_register() return value check Greg Kroah-Hartman
2012-08-07 22:35 ` [ 050/109] Btrfs: call the ordered free operation without any locks held Greg Kroah-Hartman
2012-08-07 22:35 ` [ 051/109] cifs: reinstate sec=ntlmv2 mount option Greg Kroah-Hartman
2012-08-07 22:35 ` [ 052/109] spi/pl022: disable port when unused Greg Kroah-Hartman
2012-08-07 22:35 ` [ 053/109] qeth: repair crash in qeth_l3_vlan_rx_kill_vid() Greg Kroah-Hartman
2012-08-07 22:35 ` [ 054/109] tg3: add device id of Apple Thunderbolt Ethernet device Greg Kroah-Hartman
2012-08-07 22:35 ` [ 055/109] tg3: Fix Read DMA workaround for 5719 A0 Greg Kroah-Hartman
2012-08-10 2:21 ` Ben Hutchings
2012-08-07 22:35 ` [ 056/109] tg3: Fix race condition in tg3_get_stats64() Greg Kroah-Hartman
2012-08-07 22:35 ` [ 057/109] drm/radeon: fix fence related segfault in CS Greg Kroah-Hartman
2012-08-07 22:35 ` [ 058/109] drm/radeon: fix bo creation retry path Greg Kroah-Hartman
2012-08-07 22:35 ` [ 059/109] drm/radeon: Try harder to avoid HW cursor ending on a multiple of 128 columns Greg Kroah-Hartman
2012-08-07 22:35 ` [ 060/109] drm/radeon: fix non revealent error message Greg Kroah-Hartman
2012-08-07 22:35 ` [ 061/109] drm/radeon: fix hotplug of DP to DVI|HDMI passive adapters (v2) Greg Kroah-Hartman
2012-08-07 22:35 ` [ 062/109] drm/radeon: on hotplug force link training to happen (v2) Greg Kroah-Hartman
2012-08-07 22:35 ` [ 063/109] drm/radeon: fix dpms on/off on trinity/aruba v2 Greg Kroah-Hartman
2012-08-07 22:35 ` [ 064/109] posix_types.h: Cleanup stale __NFDBITS and related definitions Greg Kroah-Hartman
2012-08-07 22:35 ` [ 065/109] dm thin: reduce endio_hook pool size Greg Kroah-Hartman
2012-08-07 22:35 ` [ 066/109] dm thin: fix memory leak in process_prepared_mapping error paths Greg Kroah-Hartman
2012-08-07 22:35 ` [ 067/109] pnfs-obj: Fix __r4w_get_page when offset is beyond i_size Greg Kroah-Hartman
2012-08-07 22:35 ` [ 068/109] nfsd4: our filesystems are normally case sensitive Greg Kroah-Hartman
2012-08-07 22:35 ` [ 069/109] nfs: skip commit in releasepage if were freeing memory for fs-related reasons Greg Kroah-Hartman
2012-08-07 22:35 ` [ 070/109] NFS: Fix a number of bugs in the idmapper Greg Kroah-Hartman
2012-08-07 22:35 ` [ 071/109] nouveau: Fix alignment requirements on src and dst addresses Greg Kroah-Hartman
2012-08-07 22:35 ` [ 072/109] ext4: pass a char * to ext4_count_free() instead of a buffer_head ptr Greg Kroah-Hartman
2012-08-07 22:35 ` [ 073/109] ext4: fix overhead calculation used by ext4_statfs() Greg Kroah-Hartman
2012-08-07 22:35 ` [ 074/109] ext4: fix hole punch failure when depth is greater than 0 Greg Kroah-Hartman
2012-08-07 22:35 ` [ 075/109] ext4: dont let i_reserved_meta_blocks go negative Greg Kroah-Hartman
2012-08-07 22:35 ` [ 076/109] ext4: undo ext4_calc_metadata_amount if we fail to claim space Greg Kroah-Hartman
2012-08-07 22:35 ` [ 077/109] atl1c: fix issue of transmit queue 0 timed out Greg Kroah-Hartman
2012-08-07 22:35 ` [ 078/109] netem: add limitation to reordered packets Greg Kroah-Hartman
2012-08-07 22:35 ` [ 079/109] gianfar: fix potential sk_wmem_alloc imbalance Greg Kroah-Hartman
2012-08-07 22:35 ` [ 080/109] net: Fix memory leak - vlan_info struct Greg Kroah-Hartman
2012-08-07 22:35 ` [ 081/109] bnx2: Fix bug in bnx2_free_tx_skbs() Greg Kroah-Hartman
2012-08-07 22:35 ` [ 082/109] sch_sfb: Fix missing NULL check Greg Kroah-Hartman
2012-08-07 22:35 ` [ 083/109] sctp: Fix list corruption resulting from freeing an association on a list Greg Kroah-Hartman
2012-08-07 22:35 ` [ 084/109] caif: Fix access to freed pernet memory Greg Kroah-Hartman
2012-08-07 22:35 ` [ 085/109] cipso: dont follow a NULL pointer when setsockopt() is called Greg Kroah-Hartman
2012-08-07 22:35 ` [ 086/109] net: Fix references to out-of-scope variables in put_cmsg_compat() Greg Kroah-Hartman
2012-08-07 22:35 ` [ 087/109] r8169: revert "add byte queue limit support" Greg Kroah-Hartman
2012-08-07 22:35 ` [ 088/109] caif: fix NULL pointer check Greg Kroah-Hartman
2012-08-07 22:35 ` [ 089/109] wanmain: comparing array with NULL Greg Kroah-Hartman
2012-08-07 22:35 ` [ 090/109] tcp: Add TCP_USER_TIMEOUT negative value check Greg Kroah-Hartman
2012-08-07 22:35 ` [ 091/109] USB: kaweth.c: use GFP_ATOMIC under spin_lock Greg Kroah-Hartman
2012-08-07 22:35 ` [ 092/109] net: fix rtnetlink IFF_PROMISC and IFF_ALLMULTI handling Greg Kroah-Hartman
2012-08-07 22:35 ` [ 093/109] tcp: perform DMA to userspace only if there is a task waiting for it Greg Kroah-Hartman
2012-08-07 22:35 ` [ 094/109] net/tun: fix ioctl() based info leaks Greg Kroah-Hartman
2012-08-07 22:35 ` [ 095/109] USB: echi-dbgp: increase the controller wait time to come out of halt Greg Kroah-Hartman
2012-08-07 22:35 ` [ 096/109] ALSA: snd-usb: fix clock source validity index Greg Kroah-Hartman
2012-08-07 22:35 ` [ 097/109] ALSA: mpu401: Fix missing initialization of irq field Greg Kroah-Hartman
2012-08-07 22:35 ` [ 098/109] ALSA: hda - Fix invalid D3 of headphone DAC on VT202x codecs Greg Kroah-Hartman
2012-08-07 22:35 ` [ 099/109] ALSA: hda - Fix mute-LED GPIO setup for HP Mini 210 Greg Kroah-Hartman
2012-08-07 22:35 ` [ 100/109] ALSA: hda - Fix polarity of mute LED on " Greg Kroah-Hartman
2012-08-07 22:36 ` [ 101/109] ALSA: hda - Fix mute-LED GPIO initialization for IDT codecs Greg Kroah-Hartman
2012-08-07 22:36 ` [ 102/109] ALSA: hda - Support dock on Lenovo Thinkpad T530 with ALC269VC Greg Kroah-Hartman
2012-08-07 22:36 ` [ 103/109] ASoC: wm8962: Allow VMID time to fully ramp Greg Kroah-Hartman
2012-08-07 22:36 ` [ 104/109] ASoC: wm8994: Ensure there are enough BCLKs for four channels Greg Kroah-Hartman
2012-08-07 22:36 ` [ 105/109] m68k: Make sys_atomic_cmpxchg_32 work on classic m68k Greg Kroah-Hartman
2012-08-07 22:36 ` [ 106/109] m68k: Correct the Atari ALLOWINT definition Greg Kroah-Hartman
2012-08-07 22:36 ` [ 107/109] futex: Test for pi_mutex on fault in futex_wait_requeue_pi() Greg Kroah-Hartman
2012-08-07 22:36 ` [ 108/109] futex: Fix bug in WARN_ON for NULL q.pi_state Greg Kroah-Hartman
2012-08-07 22:36 ` [ 109/109] futex: Forbid uaddr == uaddr2 in futex_wait_requeue_pi() Greg Kroah-Hartman
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=20120807222044.245484147@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=JBottomley@Parallels.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=bvanassche@acm.org \
--cc=j-nomura@ce.jp.nec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michaelc@cs.wisc.edu \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.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
Powered by JetHome