Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7148675ybi; Mon, 8 Jul 2019 15:37:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxiTqsHeDxdq1opLHdH3FMPRDsNtP1aCR1h8/QAdMsLFgeoUrlcryWnoxPjLdwqT/7noWIr X-Received: by 2002:a17:902:ea:: with SMTP id a97mr27521056pla.182.1562625436050; Mon, 08 Jul 2019 15:37:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625436; cv=none; d=google.com; s=arc-20160816; b=UqRU9YVTyZJxewMp6KxloZBkdd47EXvq10pdvIt1g5yAORd6c7Fo8bmNW2RqwsFBK9 N2ftucLAQH0Ixtd2ls5a+hRgtQzP/b/JWAxOlXnyxX/P2buqrllNenqGGrj7VkfbMWbJ Cfl+qaw3BJnHdBHRwn5E8v5UwJHdq7TeJoFvC3qau+ISa9anUNKt5niw5hoYEzjeogmg Q1T0KHBsY3v32a/pYhF2xa7XSUQqnDVp8h9Nbadtt+FDOEZEpJxd+9BubED2+mcayaNU MipDwXrsHrPBJ+WZE9afE6rKI/xWs9hYUr2dBVk/gJzukm/PiBaAtoNyZwvFB+UbOl7u G4ow== 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=UA6YuzB8d7MbGk22zBSjpe5ZXlikSdRdTvyd9hwaC6s=; b=Wfjyrnsekp9rp9CtJsQaJRp0G5qeFq/DN1+6cGC8XwAyJ1KX4J8eDNsSaXS/joXKj1 CXFGOUnFeI0ajwTiNstYYFz8Ypn4zky6Sl9KmN7IJeVZpwQwXiiKhXIwTOBqTGleA0xe q/ULewNPZSBTIqfw2X64YqBkQaTO9x0/HvSNEMnznrIYSkDnKWaLTOr5ROm3RAcmw/en A24XnqOzpvvV2PH8Fl8ND2vHa7wRX3m1py3qQJD4dX/31gtOT5/bLEdJw0duzmYvKXuG NFq5qgjO762D6t2RQCSpKBbLrjxhBeZG7xi5hx+RFoXMOIRIozzouz50vO6weG/QbFIp 9DwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vykdINJl; 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 m99si692498pjb.107.2019.07.08.15.37.01; Mon, 08 Jul 2019 15:37:16 -0700 (PDT) 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=vykdINJl; 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 S2388652AbfGHPZm (ORCPT + 99 others); Mon, 8 Jul 2019 11:25:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:53126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388633AbfGHPZi (ORCPT ); Mon, 8 Jul 2019 11:25:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 F1FC921537; Mon, 8 Jul 2019 15:25:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599537; bh=RQlXnzawyAM0Ymk4SmrNvx0u3Rgqb3w5rE3zGbGCebo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vykdINJlQahSquoOspvoQHvwveJbibTxcYyXp2EUQAmSkpeTmuoiyXz3nzuONDpvY JmkNzjPu2rcvoLuOC5TsTywJu2MxIl1rVfmtfaUVjpSlrivrzTk5cgOktVNdyvLOu9 uCrw0lOQ9oqUqe9oFL3VIPechcKGjynPxpi9gSUg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Bonzini , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Balbir Singh Subject: [PATCH 4.14 47/56] vhost: scsi: add weight support Date: Mon, 8 Jul 2019 17:13:39 +0200 Message-Id: <20190708150523.895837718@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150514.376317156@linuxfoundation.org> References: <20190708150514.376317156@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Jason Wang commit c1ea02f15ab5efb3e93fc3144d895410bf79fcf2 upstream. This patch will check the weight and exit the loop if we exceeds the weight. This is useful for preventing scsi kthread from hogging cpu which is guest triggerable. This addresses CVE-2019-3900. Cc: Paolo Bonzini Cc: Stefan Hajnoczi Fixes: 057cbf49a1f0 ("tcm_vhost: Initial merge for vhost level target fabric driver") Signed-off-by: Jason Wang Reviewed-by: Stefan Hajnoczi Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Signed-off-by: Balbir Singh Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/scsi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -846,7 +846,7 @@ vhost_scsi_handle_vq(struct vhost_scsi * u64 tag; u32 exp_data_len, data_direction; unsigned int out = 0, in = 0; - int head, ret, prot_bytes; + int head, ret, prot_bytes, c = 0; size_t req_size, rsp_size = sizeof(struct virtio_scsi_cmd_resp); size_t out_size, in_size; u16 lun; @@ -865,7 +865,7 @@ vhost_scsi_handle_vq(struct vhost_scsi * vhost_disable_notify(&vs->dev, vq); - for (;;) { + do { head = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov), &out, &in, NULL, NULL); @@ -1080,7 +1080,7 @@ vhost_scsi_handle_vq(struct vhost_scsi * */ INIT_WORK(&cmd->work, vhost_scsi_submission_work); queue_work(vhost_scsi_workqueue, &cmd->work); - } + } while (likely(!vhost_exceeds_weight(vq, ++c, 0))); out: mutex_unlock(&vq->mutex); }