Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp815803imu; Tue, 11 Dec 2018 08:01:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/XBpgOgw1We4uIfl7mUYF6ealxp8XpfxH0KXwg2iuLUHHlxgkFQsEzHPmVdMZyKygDJ2Vl1 X-Received: by 2002:a17:902:9a41:: with SMTP id x1mr16396503plv.126.1544544116622; Tue, 11 Dec 2018 08:01:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544544116; cv=none; d=google.com; s=arc-20160816; b=l9e2k0F7fQohRVH1titSo5V/oAwAAY+p+VIulFg9/KXv/3kAAXkV26cue4pu9DycmS 29xc05K7T2Kus5li27gFk5VWjfiqZ3b4bjDHxUMAO8vq0/cuF3aSr3dQsWgxAYMs8Vqv AvcgTmegYQKMqHsjlb37ILSVFnAKU+Q4R3uXt1cK92/TLsoRyj3IPfhXgAlfGMsVYPHT 3WHBZdnHiFGnYpgIxrczAQh/uNXPEkmDFtK6r++QZKPorFUQPb/y1qQ+qBsqabv7oWdN 3sCk1TcTxbb4L8B4r2GkQecbB9PUAehbirZ2PGXo0FeOfeDrzI8pua6cd4JpnjESvNsr z9AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=af4M8m2UHnwFoeyhYvOBMZKd3ucnzItThpfITObRqQo=; b=IsUbybtwOA3u1VwiPgpjN2FYdja8Q/TOJHtKCG/zpBHn7cL6KM/UKmFp2jgdUaux/P h7pjnKPObCG7UlH/QMjEgpwxo1wpXJZHHvgz2By5uYtwU9hVuPxCAOjg16wiZhJe3zMK PovxZgdXQD/nhAdTNT6iRNtLmhCRkGgpSxUm0xCCmU12dV7fQVieXcJGQdScRtnWo6MS kJHY+p0eOz9GJSkZmrIZcYcRhmRJE403y9xNyuon5LhZOnT/E1zCVN7yoDkG4Zz+sxYS NxQpga4P3O34z2kSSEKHGoo+4xhPcrWo/HB6+CcCWgNRr3UWiXSF8Ez4tWlaUwqYteOy zWfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LtgDA+mF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m76si12969036pfj.48.2018.12.11.08.01.41; Tue, 11 Dec 2018 08:01:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LtgDA+mF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730729AbeLKQAB (ORCPT + 99 others); Tue, 11 Dec 2018 11:00:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:48116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730381AbeLKP6g (ORCPT ); Tue, 11 Dec 2018 10:58:36 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C320E20855; Tue, 11 Dec 2018 15:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543915; bh=3Z0DO6kWqrWlEhMdNbbaK7Jvsbp9eqZMqcbj5GhHxPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LtgDA+mFP/KcxOT8Lj9bq0Te1A950XtRYfL8JimmCLZGVCSIB1kPh0ib/2h3ykxbl HwaIBqbCnwui7nUmnywE0sOGzfG+0uaW8VAw79l7AUE399iA7od3HOOJtcoD0MuRg8 IiBEV+uN2EMgDB6CqsYbX1lmlbFp3gv6dmmo9/2U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Halil Pasic , Colin Ian King , Cornelia Huck , "Michael S. Tsirkin" Subject: [PATCH 4.19 078/118] virtio/s390: fix race in ccw_io_helper() Date: Tue, 11 Dec 2018 16:41:37 +0100 Message-Id: <20181211151647.412003042@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151644.216668863@linuxfoundation.org> References: <20181211151644.216668863@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Halil Pasic 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 Reported-by: Colin Ian King Cc: stable@vger.kernel.org Message-Id: <20180925121309.58524-3-pasic@linux.ibm.com> Signed-off-by: Cornelia Huck Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- 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 @@ -56,6 +56,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; @@ -296,6 +297,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); @@ -308,7 +310,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, @@ -1253,6 +1257,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);