Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp236886ybl; Thu, 22 Aug 2019 23:35:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpU1RacPnd0eZsZ0ot/TO0ZV4qGa1YOgUv57BsRQ3Jf24sUYBHh+SuurN4cLfqSgOacvo0 X-Received: by 2002:a62:f208:: with SMTP id m8mr3338760pfh.108.1566542122514; Thu, 22 Aug 2019 23:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566542122; cv=none; d=google.com; s=arc-20160816; b=PVz7cj+vZJvkKN6MoZSQ1rs98a7lm/TiTI0446SozPdFEIxAffR+XXjePEBa6s+NXr 9n2bBgGxXc/+vEPYMaj764Lag/uBmX587ZwGSu4+Fyur4TwpzS0NRlyhvliRvXGUfQBA WsRQoMjLU9NTx/iS+gTb+4pY3Qh/xFWz0ulYIt55BkN6PgICTJSmP7yfu9QxtdvsUpBB vAeDc2WXSybEDhRUd1HIpLMuqfK6Fv3UUGPR12rCOAPoutd65T36CLWxcOIKHlez1Lek Q5OyB/MdjIV+NmMFZBlXE6ECT/FmecpGXyIOlEWkagBowQ1oiovBgS78wVLm2PpCyDUh ii+g== 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=Trtg9xNdfdBU1Hslfv7T/Iki/pP1FHrTYn4bI4T6Xs8=; b=TfovBoAciiMP6qfJOLLw08PfghxDsZ1vtt/tb394PIZj1RTxUgKGB9o4xabzjwn6SW m+X1/J9eM7Si1WwIIiO2mdU96L3TtlQP85SGUGJZ81YZKxCKyQgtW0b59cybUDnUQlxP L5f1Uesyc8fqbiAraB/bqPsDLZ+ZC9oNakGbDd+ikd08wLBdHBigdZDHwsfi1zm3vAqW kGDHEyppVuSLm1zCu7qHrbpzDo+xrT1D3rbxyDC/ls4kpLzZokhTb5jG6u1X+Itq38YK E14OWRI0EqxKS1aWxBB/Yii/RZQ7PNkbJzF/oh3j+W5YL0EacslbQqcVONNidDXVhaqI VNmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w9BeTkOn; 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 g7si1268934pgc.179.2019.08.22.23.35.07; Thu, 22 Aug 2019 23:35:22 -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=w9BeTkOn; 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 S2405447AbfHVRm7 (ORCPT + 99 others); Thu, 22 Aug 2019 13:42:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:44142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404001AbfHVRXn (ORCPT ); Thu, 22 Aug 2019 13:23:43 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (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 0BDA42343C; Thu, 22 Aug 2019 17:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494623; bh=CZjCyvLmTAorm2RAOhXTckTqQlzizeKKtyw2uFgKLXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w9BeTkOni9kJyv0+fjW9YhalT5t98ytj1moM5vJOXnaJyHL4c5UkmufmbYDeFx/66 oRoTAT4tPEvNGkaVtStGypmPWPWhbrbtJ5YcY5Rm0Mc0ugX89gm4RAnsEhA9Gkl5mx CJ7FgFKO9ERf557+retqkG3dfZgzDOjzG1XFWVZU= 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" , Ben Hutchings Subject: [PATCH 4.9 053/103] vhost: scsi: add weight support Date: Thu, 22 Aug 2019 10:18:41 -0700 Message-Id: <20190822171730.946298630@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171728.445189830@linuxfoundation.org> References: <20190822171728.445189830@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 [bwh: Backported to 4.9: - Drop changes in vhost_scsi_ctl_handle_vq() - Adjust context] Signed-off-by: Ben Hutchings 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 @@ -851,7 +851,7 @@ vhost_scsi_handle_vq(struct vhost_scsi * u64 tag; u32 exp_data_len, data_direction; unsigned out, in; - 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; @@ -870,7 +870,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); @@ -1086,7 +1086,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); }