Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1401372ybe; Fri, 13 Sep 2019 16:20:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/4kAw8NqC4ipbDgq7TVCY4I52AJut9sayCiMOLNuGPRH+DSm7adn466BBAnrWCPHj9Fuk X-Received: by 2002:a50:fa99:: with SMTP id w25mr50193874edr.259.1568416842653; Fri, 13 Sep 2019 16:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568416842; cv=none; d=google.com; s=arc-20160816; b=Y+Hah4X7r2cgt2PwY83+fFzRXYUrm7qPLeyZh1tpjTuGflS8CBDzNEWa7QxoiKsuDe dHuvm5dyKiPikT7M921xrjeNDWJcODy+gFUjkrrR+riiI7EI59ymHBsFk4g0XLBFW0O1 /Ri2gpMPYvXzN01C8AeXm/r8VH4eQeIMAp6kFxPziS4LXXGNgNlpaHo/XSEDnva1ynnn tqBegvMfHPmvOQxgtdTK3sRBIciB9K6djWLEWIPKxKHNZt7SSmDIKY9EvFzjb/FxGXk+ ToqQZH6so8rE0l0mAchkHxPROj2CqQ1Gbb4WVKOaLCKKmW8rUc/Y3547wmdEOrjevrqH Zq+Q== 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=eMOtZSPVeXG0TRtevk9f7Rc8isbQfv8rQOzDGeWuJoU=; b=CS2uTJY9IU9Sc8fHJFPFfPouVxqOV6BphtV2b8d5MW9MRajfgaTb9BLrhcA/klKMiP d1DHi/KP9BzNmU1oCldRk2JS+ACB9rJVSByhyf4GZ1PQEx98pI5DM3QLFvY5NYmrS45i 3KHoThC/6BjuCEkWgW/04T+QzEMRxQmYpE9c6BPCRO3woKfjC6DxyE1+1aTeUIdlJsOM HPgmlcxAEU0mK6yWgQ9GebsXpXTCPlUmhZE5awCxEhNfsq9/0sW4VBKdmzkY2jHbY68d PIOFm1EthQ/UquO9kWEB4DYADlKsN6HBLOw20qlrxDk88oSs9tXflamhPvh7ou0VYyzw IgxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DeCbafoA; 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 lu11si15095396ejb.215.2019.09.13.16.20.06; Fri, 13 Sep 2019 16:20:42 -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=DeCbafoA; 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 S2390269AbfIMNXu (ORCPT + 99 others); Fri, 13 Sep 2019 09:23:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:49954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389729AbfIMNUq (ORCPT ); Fri, 13 Sep 2019 09:20:46 -0400 Received: from localhost (unknown [104.132.45.99]) (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 9F9DB206BB; Fri, 13 Sep 2019 13:20:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380846; bh=RBHFNmoq0KwigmFolI7aqoLzBVjy9tx5BTawnJLct2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DeCbafoAabDdpgN0fmsaqN1EW6sVl4Uo8bqBrWqlkwzKJsF7+W8BvbCqgcyzoVD1H wYNbQ9Pfx9EkkYEh7eRvqvdazmZAYu3CdyAdadUtedKQcNfcqjWpWLJr/qDnrCWmZ0 7sJsAkHu7TviEuVKUbaF+Jy70t4/6bBrFZMpSAcs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lidong Chen , ruippan , yongduan , "Michael S. Tsirkin" , Tyler Hicks Subject: [PATCH 4.19 190/190] vhost: make sure log_num < in_num Date: Fri, 13 Sep 2019 14:07:25 +0100 Message-Id: <20190913130615.118340191@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130559.669563815@linuxfoundation.org> References: <20190913130559.669563815@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: yongduan commit 060423bfdee3f8bc6e2c1bac97de24d5415e2bc4 upstream. The code assumes log_num < in_num everywhere, and that is true as long as in_num is incremented by descriptor iov count, and log_num by 1. However this breaks if there's a zero sized descriptor. As a result, if a malicious guest creates a vring desc with desc.len = 0, it may cause the host kernel to crash by overflowing the log array. This bug can be triggered during the VM migration. There's no need to log when desc.len = 0, so just don't increment log_num in this case. Fixes: 3a4d5c94e959 ("vhost_net: a kernel-level virtio server") Cc: stable@vger.kernel.org Reviewed-by: Lidong Chen Signed-off-by: ruippan Signed-off-by: yongduan Acked-by: Michael S. Tsirkin Reviewed-by: Tyler Hicks Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/vhost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2075,7 +2075,7 @@ static int get_indirect(struct vhost_vir /* If this is an input descriptor, increment that count. */ if (access == VHOST_ACCESS_WO) { *in_num += ret; - if (unlikely(log)) { + if (unlikely(log && ret)) { log[*log_num].addr = vhost64_to_cpu(vq, desc.addr); log[*log_num].len = vhost32_to_cpu(vq, desc.len); ++*log_num; @@ -2218,7 +2218,7 @@ int vhost_get_vq_desc(struct vhost_virtq /* If this is an input descriptor, * increment that count. */ *in_num += ret; - if (unlikely(log)) { + if (unlikely(log && ret)) { log[*log_num].addr = vhost64_to_cpu(vq, desc.addr); log[*log_num].len = vhost32_to_cpu(vq, desc.len); ++*log_num;