Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EB85C5B57D for ; Wed, 3 Jul 2019 00:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 42EAD218B0 for ; Wed, 3 Jul 2019 00:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727272AbfGCAro (ORCPT ); Tue, 2 Jul 2019 20:47:44 -0400 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:62750 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbfGCArn (ORCPT ); Tue, 2 Jul 2019 20:47:43 -0400 X-IronPort-AV: E=Sophos;i="5.62,444,1554768000"; d="scan'208";a="772995231" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-87a10be6.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 02 Jul 2019 21:02:41 +0000 Received: from EX13MTAUWC001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-87a10be6.us-west-2.amazon.com (Postfix) with ESMTPS id 170BEA2239; Tue, 2 Jul 2019 21:02:41 +0000 (UTC) Received: from EX13D28UWC004.ant.amazon.com (10.43.162.24) by EX13MTAUWC001.ant.amazon.com (10.43.162.135) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 2 Jul 2019 21:02:33 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D28UWC004.ant.amazon.com (10.43.162.24) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 2 Jul 2019 21:02:32 +0000 Received: from localhost (172.23.204.141) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 2 Jul 2019 21:02:32 +0000 From: Balbir Singh To: CC: , Jason Wang , Paolo Bonzini , Stefan Hajnoczi , Balbir Singh Subject: [backport to v4.14 CVE-2019-3900 7/7] vhost: scsi: add weight support Date: Tue, 2 Jul 2019 21:02:10 +0000 Message-ID: <20190702210210.2375-8-sblbir@amzn.com> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190702210210.2375-1-sblbir@amzn.com> References: <20190702210210.2375-1-sblbir@amzn.com> MIME-Version: 1.0 Content-Type: text/plain Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jason Wang 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. [upstream c1ea02f15ab5efb3e93fc3144d895410bf79fcf2 Balbir - backport to stable 4.14 ] Cc: Paolo Bonzini Cc: Stefan Hajnoczi Fixes: 057cbf49a1f0 ("tcm_vhost: Initial merge for vhost level target fabric driver") Signed-off-by: Jason Wang Signed-off-by: Balbir Singh --- drivers/vhost/scsi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 0abb7cbf54b7..cb4ab5b955ad 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -846,7 +846,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) 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 *vs, struct vhost_virtqueue *vq) 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 *vs, struct vhost_virtqueue *vq) */ 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); } -- 2.16.5