Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp791320ybe; Fri, 13 Sep 2019 06:27:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqy3VTO9zE8m6S3R3FG+i6iMiW9gc6Ihgn2Yq1MwYf05iMLnadJTK4H6mefeKsK1DUvvCS0P X-Received: by 2002:aa7:c355:: with SMTP id j21mr46980045edr.210.1568381232997; Fri, 13 Sep 2019 06:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568381232; cv=none; d=google.com; s=arc-20160816; b=s7WMvHh3w1eKnBwo9X7As0l9c28Hx+WOilopBbLoCN6AnBAKewQGuPIIeNDzT7SkYC saBZIpGcLnjZOFXt1FLmgMIBiXAmBSuHBVTginK2EC5/+oxuVsZljOj/31dxE86tWK/f y8MvN3Q7MjkJeveysJTp8Gkf7ZNjviEcwiVjzNUqku4OyDlFsVxWgn5MzSotUbClYe5T F2zRRoJp3xxz30lG9mZTrXuW0CVHKS60fAiiDRy3VoFkgi7ar2xinf0/ZN4nMQvJMeba EHsEL7Du93a1CfeouG8rRqE/e5aORwyXCrLCYPvC3eBTEnYVEcMFbX+XJ5tg6qXuxHNy AmAA== 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=lpDLLxdDVIy2i+mjeIVCk1FU9ImFlVjpaaVyJ0SJgPg=; b=SERontHIzUed3EfeVKpvboyQCxXk1VAEK0Sp9e+wrUu5UaTPK1Zh7eTEIhmeRUl0e1 LrEpiDtsPw5yPx195d/yHSn/jDxE5UdyBJB/glX0IBXl5NfZcfKPDoQ77mHTWvBr2OEn PrNU2Z/omvlInz4ndDEjD0bp0ViJZBe6kyMjCOeGQ7bNXQhDYvSjorxLeDQI6DgS4oSx OeCxJUTjSrp5uWUBeYwSC2R5J+Ov+RfI5XB5lm6IOFsJFuKBxhsjuhp/nq/PnaxGafsZ 0q1sWLYW8aQmh+Sj35p0bY7eukmmAZyDlPQLGVjx94CFVOY+6Mdc783awOQ4J4H9dedi uQeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uLX2PsRl; 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 h5si6389032ejp.154.2019.09.13.06.26.50; Fri, 13 Sep 2019 06:27:12 -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=uLX2PsRl; 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 S2390943AbfIMNV7 (ORCPT + 99 others); Fri, 13 Sep 2019 09:21:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:51928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390935AbfIMNV5 (ORCPT ); Fri, 13 Sep 2019 09:21:57 -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 ACFDA206BB; Fri, 13 Sep 2019 13:21:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380916; bh=W91+UdTzEWWfVfME9CPqZRP/B4xux4w9QJ+y6UvKR9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uLX2PsRlqLT7AUn3lrzqX82MwAWTU96XE/aHXzDw9KEwgbvlN9IPmmNnNS3sY2dJF JCd6KOnHIhla2weeHmfsa1qpAMmnKGPv0ODMu+xLnHqHVqOL13NGnWhl5Fn9prtjCr SmzfyNwoUvKc2dMeuBJsnw2y30JpK3K91bS1BruY= 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 5.2 37/37] vhost: make sure log_num < in_num Date: Fri, 13 Sep 2019 14:07:42 +0100 Message-Id: <20190913130522.220388907@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130510.727515099@linuxfoundation.org> References: <20190913130510.727515099@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 @@ -2074,7 +2074,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; @@ -2217,7 +2217,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;