From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 0C359C49ED7 for ; Fri, 13 Sep 2019 13:34:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6F2D205ED for ; Fri, 13 Sep 2019 13:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568381640; bh=hdZ1chB3WzXr0Y4hQLXkjIe8ePHY8MGeUnpJmhc0/3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=jYPZqh0COjI6ly1qh53mFJVprvi/1+ZlxEl6GTrQiSTAsfy57pLZf1be7gSVqyoJ+ F0Imvf4NEPAFfS9aXsrsy9mz8LFlQpYk5GalVX82Bp9drJIz0GljFcTPizZLuoauzN JL6oeVjiG3BiVanoKsdoGgn0cKb6B41/xKmmwP4Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388419AbfIMNJE (ORCPT ); Fri, 13 Sep 2019 09:09:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:33536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388393AbfIMNJD (ORCPT ); Fri, 13 Sep 2019 09:09:03 -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 B8A1A214D8; Fri, 13 Sep 2019 13:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380142; bh=hdZ1chB3WzXr0Y4hQLXkjIe8ePHY8MGeUnpJmhc0/3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aB4DUq8TGJllvpmWDx9kddnjsas89Yyt8cZLoTsABAkX/+aOk14bmcbpVRhxlXoat evrNrs/w4g8CXsHXXK/3l8GC66+K18jYJgsk2I90EYXL4eLAlg8IN49PNcS81Xpd/T V5LDUKfmyXsMXDZjVXOZR3OZgm41W2kl6Ldd75fQ= 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.4 9/9] vhost: make sure log_num < in_num Date: Fri, 13 Sep 2019 14:06:59 +0100 Message-Id: <20190913130432.563420115@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130424.160808669@linuxfoundation.org> References: <20190913130424.160808669@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 @@ -1324,7 +1324,7 @@ static int get_indirect(struct vhost_vir /* If this is an input descriptor, increment that count. */ if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_WRITE)) { *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; @@ -1453,7 +1453,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;