Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp803990imu; Tue, 11 Dec 2018 07:51:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/XP9IxS+eJB+1j2rmv+1HOJkQvMdmZq40rk78kNamwCYAVP+oB9lqrzdotymVQTomRSB/pC X-Received: by 2002:a63:8742:: with SMTP id i63mr14924350pge.298.1544543469252; Tue, 11 Dec 2018 07:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544543469; cv=none; d=google.com; s=arc-20160816; b=ROJAll+pDubw2Qo+dfoWifHcord+L/QoTG+VB+Ix1rsDsYB7qBzBGIYSR7VJStYg2w FKN+lNHuvtTkTAJWPBrVWQBm/HsSF2kHKkPSLlVw1L0GRATqYIBvA1FxLdHpaXEk8gli 18sHDNZUT2RJmPIRqOgzwlRuBURp2I9XCCXSwYI//Ii1R7xay+7Ux+e13LTPKwYVJdsQ gx5mb3o5Qlx3lcdfLajCDGvciOD0eKheUUNW8wqWslFBBeRJDwN/nMSHU2YiacPH/OKo xL9XWfX2B6Yt3oOMDwLOW/fTIO6Qr1uhEJTLjP8U7f16W2ZxMpd/145w4YzZZkYtNw2b i7Xw== 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=TmOwRfD9mokHfsWRVIT1/zgx0paa8/QXc+VkckL3Vfc=; b=phzldSSuJXUgemWnfAZuP5u9KyGHnQp1gqn0T5YsHjG5ApC79cPHxRgjBtSAJuCvvC EYEFIhpdWTOdd8XvghxoQj1IUxBCbsVWawHJ9xrBdqL2AqV+i7ogt2ZyQ+y6k21bMsPx zEJKCJscK2thIBGAmyXcSMrNkDGK87B1ox8Co/XH/9an2jvuGrHWfoKj5KD3E+MV2VPp miUp/mJsptAtWmGJInOpqkpdEhlS5qvnRGwmXo3W09up5Dv2p6yFfku6z+iFAYJQ0a5h 2vHh7GZSoTgJFkBG23cMbFTfRAz3rlWuAw42UeyEs7Fq4Lnn0zVYJ3n1aCXznTMoYNe8 5ZEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="i/dWX/KY"; 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 v184si11869547pgd.295.2018.12.11.07.50.53; Tue, 11 Dec 2018 07:51:09 -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="i/dWX/KY"; 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 S1728686AbeLKPrz (ORCPT + 99 others); Tue, 11 Dec 2018 10:47:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:36296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728667AbeLKPrw (ORCPT ); Tue, 11 Dec 2018 10:47:52 -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 C224F2133F; Tue, 11 Dec 2018 15:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543272; bh=10HNzsinpM/ebLOFLl6kdEI2bgl51pOXS53D7vwxyis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i/dWX/KY04EfZm4eNKTSOrVrxO7J/BQ7WA865ZTIMmTwNAd9qAq+We57CUMWqY7Ir HpFASmpAE+qoAnLlkkee+jXZ5sEN2+v+ujsunaw8SC9enf8hfs1pz52TILluK8QFqN T6DQItO3J/padZBg9v+37ngO/bz/cOH/h15BDQMg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Halil Pasic , Cornelia Huck , "Michael S. Tsirkin" Subject: [PATCH 4.4 78/91] virtio/s390: avoid race on vcdev->config Date: Tue, 11 Dec 2018 16:41:37 +0100 Message-Id: <20181211151612.962127872@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151606.026852373@linuxfoundation.org> References: <20181211151606.026852373@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Halil Pasic commit 2448a299ec416a80f699940a86f4a6d9a4f643b1 upstream. Currently we have a race on vcdev->config in virtio_ccw_get_config() and in virtio_ccw_set_config(). This normally does not cause problems, as these are usually infrequent operations. However, for some devices writing to/reading from the config space can be triggered through sysfs attributes. For these, userspace can force the race by increasing the frequency. Signed-off-by: Halil Pasic Cc: stable@vger.kernel.org Message-Id: <20180925121309.58524-2-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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/s390/virtio/virtio_ccw.c +++ b/drivers/s390/virtio/virtio_ccw.c @@ -833,6 +833,7 @@ static void virtio_ccw_get_config(struct int ret; struct ccw1 *ccw; void *config_area; + unsigned long flags; ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); if (!ccw) @@ -851,11 +852,13 @@ static void virtio_ccw_get_config(struct if (ret) goto out_free; + spin_lock_irqsave(&vcdev->lock, flags); memcpy(vcdev->config, config_area, offset + len); - if (buf) - memcpy(buf, &vcdev->config[offset], len); if (vcdev->config_ready < offset + len) vcdev->config_ready = offset + len; + spin_unlock_irqrestore(&vcdev->lock, flags); + if (buf) + memcpy(buf, config_area + offset, len); out_free: kfree(config_area); @@ -869,6 +872,7 @@ static void virtio_ccw_set_config(struct struct virtio_ccw_device *vcdev = to_vc_device(vdev); struct ccw1 *ccw; void *config_area; + unsigned long flags; ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); if (!ccw) @@ -881,9 +885,11 @@ static void virtio_ccw_set_config(struct /* Make sure we don't overwrite fields. */ if (vcdev->config_ready < offset) virtio_ccw_get_config(vdev, 0, NULL, offset); + spin_lock_irqsave(&vcdev->lock, flags); memcpy(&vcdev->config[offset], buf, len); /* Write the config area to the host. */ memcpy(config_area, vcdev->config, sizeof(vcdev->config)); + spin_unlock_irqrestore(&vcdev->lock, flags); ccw->cmd_code = CCW_CMD_WRITE_CONF; ccw->flags = 0; ccw->count = offset + len;