stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Yufen Yu <yuyufen@huawei.com>,
	Bart Van Assche <bvanassche@acm.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: [PATCH 4.19 51/93] scsi: core: try to get module before removing device
Date: Sun, 27 Oct 2019 22:01:03 +0100	[thread overview]
Message-ID: <20191027203301.071664796@linuxfoundation.org> (raw)
In-Reply-To: <20191027203251.029297948@linuxfoundation.org>

From: Yufen Yu <yuyufen@huawei.com>

commit 77c301287ebae86cc71d03eb3806f271cb14da79 upstream.

We have a test case like block/001 in blktests, which will create a scsi
device by loading scsi_debug module and then try to delete the device by
sysfs interface. At the same time, it may remove the scsi_debug module.

And getting a invalid paging request BUG_ON as following:

[   34.625854] BUG: unable to handle page fault for address: ffffffffa0016bb8
[   34.629189] Oops: 0000 [#1] SMP PTI
[   34.629618] CPU: 1 PID: 450 Comm: bash Tainted: G        W         5.4.0-rc3+ #473
[   34.632524] RIP: 0010:scsi_proc_hostdir_rm+0x5/0xa0
[   34.643555] CR2: ffffffffa0016bb8 CR3: 000000012cd88000 CR4: 00000000000006e0
[   34.644545] Call Trace:
[   34.644907]  scsi_host_dev_release+0x6b/0x1f0
[   34.645511]  device_release+0x74/0x110
[   34.646046]  kobject_put+0x116/0x390
[   34.646559]  put_device+0x17/0x30
[   34.647041]  scsi_target_dev_release+0x2b/0x40
[   34.647652]  device_release+0x74/0x110
[   34.648186]  kobject_put+0x116/0x390
[   34.648691]  put_device+0x17/0x30
[   34.649157]  scsi_device_dev_release_usercontext+0x2e8/0x360
[   34.649953]  execute_in_process_context+0x29/0x80
[   34.650603]  scsi_device_dev_release+0x20/0x30
[   34.651221]  device_release+0x74/0x110
[   34.651732]  kobject_put+0x116/0x390
[   34.652230]  sysfs_unbreak_active_protection+0x3f/0x50
[   34.652935]  sdev_store_delete.cold.4+0x71/0x8f
[   34.653579]  dev_attr_store+0x1b/0x40
[   34.654103]  sysfs_kf_write+0x3d/0x60
[   34.654603]  kernfs_fop_write+0x174/0x250
[   34.655165]  __vfs_write+0x1f/0x60
[   34.655639]  vfs_write+0xc7/0x280
[   34.656117]  ksys_write+0x6d/0x140
[   34.656591]  __x64_sys_write+0x1e/0x30
[   34.657114]  do_syscall_64+0xb1/0x400
[   34.657627]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[   34.658335] RIP: 0033:0x7f156f337130

During deleting scsi target, the scsi_debug module have been removed. Then,
sdebug_driver_template belonged to the module cannot be accessd, resulting
in scsi_proc_hostdir_rm() BUG_ON.

To fix the bug, we add scsi_device_get() in sdev_store_delete() to try to
increase refcount of module, avoiding the module been removed.

Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20191015130556.18061-1-yuyufen@huawei.com
Signed-off-by: Yufen Yu <yuyufen@huawei.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/scsi/scsi_sysfs.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -723,6 +723,14 @@ sdev_store_delete(struct device *dev, st
 		  const char *buf, size_t count)
 {
 	struct kernfs_node *kn;
+	struct scsi_device *sdev = to_scsi_device(dev);
+
+	/*
+	 * We need to try to get module, avoiding the module been removed
+	 * during delete.
+	 */
+	if (scsi_device_get(sdev))
+		return -ENODEV;
 
 	kn = sysfs_break_active_protection(&dev->kobj, &attr->attr);
 	WARN_ON_ONCE(!kn);
@@ -737,9 +745,10 @@ sdev_store_delete(struct device *dev, st
 	 * state into SDEV_DEL.
 	 */
 	device_remove_file(dev, attr);
-	scsi_remove_device(to_scsi_device(dev));
+	scsi_remove_device(sdev);
 	if (kn)
 		sysfs_unbreak_active_protection(kn);
+	scsi_device_put(sdev);
 	return count;
 };
 static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);



  parent reply	other threads:[~2019-10-27 21:32 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-27 21:00 [PATCH 4.19 00/93] 4.19.81-stable review Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 01/93] nvme-pci: Fix a race in controller removal Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 02/93] scsi: ufs: skip shutdown if hba is not powered Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 03/93] scsi: megaraid: disable device when probe failed after enabled device Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 04/93] scsi: qla2xxx: Fix unbound sleep in fcport delete path Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 05/93] ARM: OMAP2+: Fix missing reset done flag for am3 and am43 Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 06/93] ARM: OMAP2+: Fix warnings with broken omap2_set_init_voltage() Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 07/93] ieee802154: ca8210: prevent memory leak Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 08/93] ARM: dts: am4372: Set memory bandwidth limit for DISPC Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 09/93] net: dsa: qca8k: Use up to 7 ports for all operations Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 10/93] MIPS: dts: ar9331: fix interrupt-controller size Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 11/93] xen/efi: Set nonblocking callbacks Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 12/93] nl80211: fix null pointer dereference Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 13/93] mac80211: fix txq " Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 14/93] netfilter: nft_connlimit: disable bh on garbage collection Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 15/93] net: dsa: rtl8366rb: add missing of_node_put after calling of_get_child_by_name Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 16/93] mips: Loongson: Fix the link time qualifier of serial_exit() Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 17/93] net: hisilicon: Fix usage of uninitialized variable in function mdio_sc_cfg_reg_write() Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 18/93] lib: textsearch: fix escapes in example code Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 19/93] r8152: Set macpassthru in reset_resume callback Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 20/93] namespace: fix namespace.pl script to support relative paths Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 21/93] libata/ahci: Fix PCS quirk application Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 22/93] md/raid0: fix warning message for parameter default_layout Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 23/93] Revert "drm/radeon: Fix EEH during kexec" Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 24/93] ocfs2: fix panic due to ocfs2_wq is null Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 25/93] ipv4: fix race condition between route lookup and invalidation Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 26/93] ipv4: Return -ENETUNREACH if we cant create route but saddr is valid Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 27/93] net: avoid potential infinite loop in tc_ctl_action() Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 28/93] net: bcmgenet: Fix RGMII_MODE_EN value for GENET v1/2/3 Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 29/93] net: bcmgenet: Set phydev->dev_flags only for internal PHYs Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 30/93] net: i82596: fix dma_alloc_attr for sni_82596 Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 31/93] net/ibmvnic: Fix EOI when running in XIVE mode Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 32/93] net: ipv6: fix listify ip6_rcv_finish in case of forwarding Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 33/93] net: stmmac: disable/enable ptp_ref_clk in suspend/resume flow Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 34/93] sctp: change sctp_prot .no_autobind with true Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 35/93] memfd: Fix locking when tagging pins Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 36/93] USB: legousbtower: fix memleak on disconnect Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 37/93] ALSA: hda/realtek - Add support for ALC711 Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 38/93] ALSA: hda/realtek - Enable headset mic on Asus MJ401TA Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 39/93] ALSA: usb-audio: Disable quirks for BOSS Katana amplifiers Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 40/93] ALSA: hda - Force runtime PM on Nvidia HDMI codecs Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 41/93] usb: udc: lpc32xx: fix bad bit shift operation Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 42/93] USB: serial: ti_usb_3410_5052: fix port-close races Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 43/93] USB: ldusb: fix memleak on disconnect Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 44/93] USB: usblp: fix use-after-free " Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 45/93] USB: ldusb: fix read info leaks Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 46/93] MIPS: tlbex: Fix build_restore_pagemask KScratch restore Greg Kroah-Hartman
2019-10-27 21:00 ` [PATCH 4.19 47/93] staging: wlan-ng: fix exit return when sme->key_idx >= NUM_WEPKEYS Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 48/93] scsi: zfcp: fix reaction on bit error threshold notification Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 49/93] scsi: sd: Ignore a failure to sync cache due to lack of authorization Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 50/93] scsi: core: save/restore command resid for error handling Greg Kroah-Hartman
2019-10-27 21:01 ` Greg Kroah-Hartman [this message]
2019-10-27 21:01 ` [PATCH 4.19 52/93] scsi: ch: Make it possible to open a ch device multiple times again Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 53/93] Input: da9063 - fix capability and drop KEY_SLEEP Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 54/93] Input: synaptics-rmi4 - avoid processing unknown IRQs Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 55/93] ASoC: rsnd: Reinitialize bit clock inversion flag for every format setting Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 56/93] ACPI: CPPC: Set pcc_data[pcc_ss_id] to NULL in acpi_cppc_processor_exit() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 57/93] cfg80211: wext: avoid copying malformed SSIDs Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 58/93] mac80211: Reject malformed SSID elements Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 59/93] drm/edid: Add 6 bpc quirk for SDC panel in Lenovo G50 Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 60/93] drm/ttm: Restore ttm prefaulting Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 61/93] drm/amdgpu: Bail earlier when amdgpu.cik_/si_support is not set to 1 Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 62/93] drivers/base/memory.c: dont access uninitialized memmaps in soft_offline_page_store() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 63/93] fs/proc/page.c: dont access uninitialized memmaps in fs/proc/page.c Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 64/93] mmc: cqhci: Commit descriptors before setting the doorbell Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 65/93] mm/memory-failure.c: dont access uninitialized memmaps in memory_failure() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 66/93] mm/slub: fix a deadlock in show_slab_objects() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 67/93] mm/page_owner: dont access uninitialized memmaps when reading /proc/pagetypeinfo Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 68/93] hugetlbfs: dont access uninitialized memmaps in pfn_range_valid_gigantic() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 69/93] mm/memory-failure: poison read receives SIGKILL instead of SIGBUS if mmaped more than once Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 70/93] xtensa: drop EXPORT_SYMBOL for outs*/ins* Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 71/93] parisc: Fix vmap memory leak in ioremap()/iounmap() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 72/93] EDAC/ghes: Fix Use after free in ghes_edac remove path Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 73/93] arm64: Enable workaround for Cavium TX2 erratum 219 when running SMT Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 74/93] CIFS: avoid using MID 0xFFFF Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 75/93] CIFS: Fix use after free of file info structures Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 76/93] perf/aux: Fix AUX output stopping Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 77/93] tracing: Fix race in perf_trace_buf initialization Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 78/93] dm cache: fix bugs when a GFP_NOWAIT allocation fails Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 79/93] x86/boot/64: Make level2_kernel_pgt pages invalid outside kernel area Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 80/93] x86/apic/x2apic: Fix a NULL pointer deref when handling a dying cpu Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 81/93] pinctrl: cherryview: restore Strago DMI workaround for all versions Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 82/93] pinctrl: armada-37xx: fix control of pins 32 and up Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 83/93] pinctrl: armada-37xx: swap polarity on LED group Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 84/93] btrfs: block-group: Fix a memory leak due to missing btrfs_put_block_group() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 85/93] Btrfs: add missing extents release on file extent cluster relocation error Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 86/93] Btrfs: check for the full sync flag while holding the inode lock during fsync Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 87/93] btrfs: tracepoints: Fix bad entry members of qgroup events Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 88/93] memstick: jmb38x_ms: Fix an error handling path in jmb38x_ms_probe() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 89/93] cpufreq: Avoid cpufreq_suspend() deadlock on system shutdown Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 90/93] xen/netback: fix error path of xenvif_connect_data() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 91/93] PCI: PM: Fix pci_power_up() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 92/93] blk-rq-qos: fix first node deletion of rq_qos_del() Greg Kroah-Hartman
2019-10-27 21:01 ` [PATCH 4.19 93/93] RDMA/cxgb4: Do not dma memory off of the stack Greg Kroah-Hartman
2019-10-28  2:15 ` [PATCH 4.19 00/93] 4.19.81-stable review kernelci.org bot
2019-10-28  9:01 ` Didik Setiawan
2019-10-28 14:52 ` Guenter Roeck
2019-10-28 21:47 ` Jon Hunter
2019-10-29  6:21 ` Naresh Kamboju
2019-10-29  8:20   ` Greg Kroah-Hartman
2019-10-29 16:24 ` Pavel Machek
2019-10-29 18:02   ` Greg Kroah-Hartman
2019-11-06 18:59     ` Pavel Machek
2019-11-06 20:18       ` Greg Kroah-Hartman
2019-11-07 16:43         ` Ben Hutchings
2019-11-08 21:31           ` Pavel Machek
2019-11-09 15:53           ` 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=20191027203301.071664796@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=bvanassche@acm.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stable@vger.kernel.org \
    --cc=yuyufen@huawei.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;
as well as URLs for NNTP newsgroup(s).