linux-kernel.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, Halil Pasic <pasic@linux.ibm.com>,
	Colin Ian King <colin.king@canonical.com>,
	Cornelia Huck <cohuck@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [PATCH 4.14 41/67] virtio/s390: fix race in ccw_io_helper()
Date: Tue, 11 Dec 2018 16:41:41 +0100	[thread overview]
Message-ID: <20181211151632.469737628@linuxfoundation.org> (raw)
In-Reply-To: <20181211151630.378216233@linuxfoundation.org>

4.14-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Halil Pasic <pasic@linux.ibm.com>

commit 78b1a52e05c9db11d293342e8d6d8a230a04b4e7 upstream.

While ccw_io_helper() seems like intended to be exclusive in a sense that
it is supposed to facilitate I/O for at most one thread at any given
time, there is actually nothing ensuring that threads won't pile up at
vcdev->wait_q. If they do, all threads get woken up and see the status
that belongs to some other request than their own. This can lead to bugs.
For an example see:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1788432

This race normally does not cause any problems. The operations provided
by struct virtio_config_ops are usually invoked in a well defined
sequence, normally don't fail, and are normally used quite infrequent
too.

Yet, if some of the these operations are directly triggered via sysfs
attributes, like in the case described by the referenced bug, userspace
is given an opportunity to force races by increasing the frequency of the
given operations.

Let us fix the problem by ensuring, that for each device, we finish
processing the previous request before starting with a new one.

Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
Reported-by: Colin Ian King <colin.king@canonical.com>
Cc: stable@vger.kernel.org
Message-Id: <20180925121309.58524-3-pasic@linux.ibm.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/s390/virtio/virtio_ccw.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

--- a/drivers/s390/virtio/virtio_ccw.c
+++ b/drivers/s390/virtio/virtio_ccw.c
@@ -59,6 +59,7 @@ struct virtio_ccw_device {
 	unsigned int revision; /* Transport revision */
 	wait_queue_head_t wait_q;
 	spinlock_t lock;
+	struct mutex io_lock; /* Serializes I/O requests */
 	struct list_head virtqueues;
 	unsigned long indicators;
 	unsigned long indicators2;
@@ -299,6 +300,7 @@ static int ccw_io_helper(struct virtio_c
 	unsigned long flags;
 	int flag = intparm & VIRTIO_CCW_INTPARM_MASK;
 
+	mutex_lock(&vcdev->io_lock);
 	do {
 		spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
 		ret = ccw_device_start(vcdev->cdev, ccw, intparm, 0, 0);
@@ -311,7 +313,9 @@ static int ccw_io_helper(struct virtio_c
 		cpu_relax();
 	} while (ret == -EBUSY);
 	wait_event(vcdev->wait_q, doing_io(vcdev, flag) == 0);
-	return ret ? ret : vcdev->err;
+	ret = ret ? ret : vcdev->err;
+	mutex_unlock(&vcdev->io_lock);
+	return ret;
 }
 
 static void virtio_ccw_drop_indicator(struct virtio_ccw_device *vcdev,
@@ -1256,6 +1260,7 @@ static int virtio_ccw_online(struct ccw_
 	init_waitqueue_head(&vcdev->wait_q);
 	INIT_LIST_HEAD(&vcdev->virtqueues);
 	spin_lock_init(&vcdev->lock);
+	mutex_init(&vcdev->io_lock);
 
 	spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
 	dev_set_drvdata(&cdev->dev, vcdev);



  parent reply	other threads:[~2018-12-11 15:53 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-11 15:41 [PATCH 4.14 00/67] 4.14.88-stable review Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 01/67] media: omap3isp: Unregister media device as first Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 02/67] iommu/vt-d: Fix NULL pointer dereference in prq_event_thread() Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 03/67] brcmutil: really fix decoding channel info for 160 MHz bandwidth Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 04/67] iommu/ipmmu-vmsa: Fix crash on early domain free Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 05/67] can: rcar_can: Fix erroneous registration Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 06/67] test_firmware: fix error return getting clobbered Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 07/67] HID: input: Ignore battery reported by Symbol DS4308 Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 08/67] batman-adv: Use explicit tvlv padding for ELP packets Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 09/67] batman-adv: Expand merged fragment buffer for full packet Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 10/67] amd/iommu: Fix Guest Virtual APIC Log Tail Address Register Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 11/67] bnx2x: Assign unique DMAE channel number for FW DMAE transactions Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 12/67] qed: Fix PTT leak in qed_drain() Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 13/67] qed: Fix reading wrong value in loop condition Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 14/67] Revert "usb: gadget: ffs: Fix BUG when userland exits with submitted AIO transfers" Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 15/67] net/mlx4_core: Zero out lkey field in SW2HW_MPT fw command Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 16/67] net/mlx4_core: Fix uninitialized variable compilation warning Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 17/67] net/mlx4: Fix UBSAN warning of signed integer overflow Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 18/67] gpio: mockup: fix indicated direction Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 19/67] mtd: rawnand: qcom: Namespace prefix some commands Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 20/67] HID: multitouch: Add pointstick support for Cirque Touchpad Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 21/67] mtd: spi-nor: Fix Cadence QSPI page fault kernel panic Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 22/67] qed: Fix bitmap_weight() check Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 23/67] qed: Fix QM getters to always return a valid pq Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 24/67] net: faraday: ftmac100: remove netif_running(netdev) check before disabling interrupts Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 25/67] iommu/vt-d: Use memunmap to free memremap Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 26/67] flexfiles: use per-mirror specified stateid for IO Greg Kroah-Hartman
2018-12-11 18:48   ` Mkrtchyan, Tigran
2018-12-11 15:41 ` [PATCH 4.14 27/67] ibmvnic: Fix RX queue buffer cleanup Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 28/67] team: no need to do team_notify_peers or team_mcast_rejoin when disabling port Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 29/67] net: amd: add missing of_node_put() Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 30/67] mm: dont warn about allocations which stall for too long Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 31/67] usb: quirk: add no-LPM quirk on SanDisk Ultra Flair device Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 32/67] usb: appledisplay: Add 27" Apple Cinema Display Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 33/67] USB: check usb_get_extra_descriptor for proper size Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 34/67] ALSA: usb-audio: Fix UAF decrement if card has no live interfaces in card.c Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 35/67] ALSA: hda: Add support for AMD Stoney Ridge Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 36/67] ALSA: pcm: Fix starvation on down_write_nonblock() Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 37/67] ALSA: pcm: Call snd_pcm_unlink() conditionally at closing Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 38/67] ALSA: pcm: Fix interval evaluation with openmin/max Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 39/67] ALSA: hda/realtek - Fix speaker output regression on Thinkpad T570 Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 40/67] virtio/s390: avoid race on vcdev->config Greg Kroah-Hartman
2018-12-11 15:41 ` Greg Kroah-Hartman [this message]
2018-12-11 15:41 ` [PATCH 4.14 42/67] vhost/vsock: fix use-after-free in network stack callers Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 43/67] SUNRPC: Fix leak of krb5p encode pages Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 44/67] dmaengine: dw: Fix FIFO size for Intel Merrifield Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 45/67] dmaengine: cppi41: delete channel from pending list when stop channel Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 46/67] ARM: 8806/1: kprobes: Fix false positive with FORTIFY_SOURCE Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 47/67] xhci: workaround CSS timeout on AMD SNPS 3.0 xHC Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 48/67] xhci: Prevent U1/U2 link pm states if exit latency is too long Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 49/67] f2fs: fix to do sanity check with block address in main area v2 Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 50/67] swiotlb: clean up reporting Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 51/67] Staging: lustre: remove two build warnings Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 52/67] staging: atomisp: remove "fun" strncpy warning Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 53/67] cifs: Fix separator when building path from dentry Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 54/67] staging: rtl8712: Fix possible buffer overrun Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 55/67] Revert commit ef9209b642f "staging: rtl8723bs: Fix indenting errors and an off-by-one mistake in core/rtw_mlme_ext.c" Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 56/67] drm/amdgpu: update mc firmware image for polaris12 variants Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 57/67] drm/amdgpu/gmc8: update MC firmware for polaris Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 58/67] Drivers: hv: vmbus: Offload the handling of channels to two workqueues Greg Kroah-Hartman
2018-12-11 15:41 ` [PATCH 4.14 59/67] tty: serial: 8250_mtk: always resume the device in probe Greg Kroah-Hartman
2018-12-11 15:42 ` [PATCH 4.14 60/67] tty: do not set TTY_IO_ERROR flag if console port Greg Kroah-Hartman
2018-12-11 15:42 ` [PATCH 4.14 61/67] kgdboc: fix KASAN global-out-of-bounds bug in param_set_kgdboc_var() Greg Kroah-Hartman
2018-12-11 15:42 ` [PATCH 4.14 62/67] libnvdimm, pfn: Pad pfn namespaces relative to other regions Greg Kroah-Hartman
2018-12-11 15:42 ` [PATCH 4.14 63/67] mac80211_hwsim: Timer should be initialized before device registered Greg Kroah-Hartman
2018-12-11 15:42 ` [PATCH 4.14 64/67] mac80211: Clear beacon_int in ieee80211_do_stop Greg Kroah-Hartman
2018-12-11 15:42 ` [PATCH 4.14 65/67] mac80211: ignore tx status for PS stations in ieee80211_tx_status_ext Greg Kroah-Hartman
2018-12-11 15:42 ` [PATCH 4.14 66/67] mac80211: fix reordering of buffered broadcast packets Greg Kroah-Hartman
2018-12-11 15:42 ` [PATCH 4.14 67/67] mac80211: ignore NullFunc frames in the duplicate detection Greg Kroah-Hartman
2018-12-11 21:33 ` [PATCH 4.14 00/67] 4.14.88-stable review kernelci.org bot
2018-12-11 23:59 ` shuah
2018-12-12  6:37 ` Naresh Kamboju
2018-12-12 18:50 ` Guenter Roeck

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=20181211151632.469737628@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=cohuck@redhat.com \
    --cc=colin.king@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pasic@linux.ibm.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).