Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2905502pxb; Tue, 24 Aug 2021 10:17:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf6Gbow6OO5XncJwl6lBXvqhJkQE3P/UPcreNyID1v9BqK4aFMlu65kcHvrqkfOL/0HzoW X-Received: by 2002:a5d:9693:: with SMTP id m19mr20011445ion.72.1629825451443; Tue, 24 Aug 2021 10:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825451; cv=none; d=google.com; s=arc-20160816; b=uuqP2ap4kiGsHO8Wp36nd1m90WYOcxFG4rLitfjufNyexvQDXo890vGIJCuineXlll 07aftELe3HSEdR7UGMp6TeVKb/mK2fovrnJ29iKbfTsZJ0kJizlMOrLE7xbnGxC3ryz2 OKRM2/tfgN0zMuQFvT5pSd3vkWlkVgGAsh3KXECpLd9qHGykSxdDPkaXRTqInKRYnw71 HK+yfHlihp26a7n9AbVxd+k07V1emPEy3f/9DX4teWlAzkZEkXk/Hpv3w438ylRCVEkY txuWT9CeDvcgvUeFErV2dkJM0ElMdEWT07SlO0MZ93hMLciZCc5Tw+NYudMUEqHwvDgb SDkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fLtHliW3JtTbr7sV9ceI/3wxYhZKJBL6jes5cAz9moc=; b=VaEmgI0E8RvdTBrxX/3i878Ik/ljV1Dsdloajcjfk6QHbaNisIzGPZXqE6jz1GO4hu 5ep3CFW6YhLrb7YRmjdioIA23BLEsSsYhto42bacmiMvwdaEEHMxm+P9GwEch4x673I1 qsM8jGM3K2rV26R0jVkAfkYVr5DzmoArcvUAxYSbEmv2GbF4VpMpzTFXg2NlxgXB4mnv Zx7tgwNf6SgjksOU8EKbDmhFMiVPvr/qXxrlguh+HsB1ylLgodLaBnf/o2oPw7HbCemW 4OfRiRN4a53qqbJUmE87hV+BAKyXMjv97ykL7ExfjHmBYNGABcog/0iYOJHdzBDZZl5X ARdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mzZrnhMG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si20311304ilo.83.2021.08.24.10.17.14; Tue, 24 Aug 2021 10:17:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mzZrnhMG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240239AbhHXRRD (ORCPT + 99 others); Tue, 24 Aug 2021 13:17:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:55444 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240020AbhHXROE (ORCPT ); Tue, 24 Aug 2021 13:14:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 16AF061A85; Tue, 24 Aug 2021 17:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824496; bh=/zQUevulHb0NrGk5H2gZ5uZnKv594z6cVqOWzxN7o5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mzZrnhMGWCOagb0gZk1klhkW1OZn+EvPlHUCbOL+MRotwdkJtulS3XiFUXIwCHlqb R9EFgHURT265Ej5xhbc/hXIYqawpYKlBpQFbA945yH/T0PwXiMzHBnm51HaAR7gAZr gMRlTTEPeAj4S01+bDB9HMBBFaneJR4vt3H8tfSe/ZEXIPv8KQwCychyn0I2ra/C1P XdvpKmugy+g1E6iZDXOnknNyBbbPjXMT5Fc5YXEP0iiLCWHNq6omcLpf6LXk4KqCFb VPCW0t8MauDsCR9VEGJV3et4mNgYM/s2EKmeO2Kg53OtGTUywT6UwYAlf7D+JayA19 R9Z6tC8I+3F1g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xie Yongji , Jason Wang , "Michael S . Tsirkin" , Sasha Levin Subject: [PATCH 5.4 29/61] vhost: Fix the calculation in vhost_overflow() Date: Tue, 24 Aug 2021 13:00:34 -0400 Message-Id: <20210824170106.710221-30-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170106.710221-1-sashal@kernel.org> References: <20210824170106.710221-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.143-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.4.143-rc1 X-KernelTest-Deadline: 2021-08-26T17:01+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xie Yongji [ Upstream commit f7ad318ea0ad58ebe0e595e59aed270bb643b29b ] This fixes the incorrect calculation for integer overflow when the last address of iova range is 0xffffffff. Fixes: ec33d031a14b ("vhost: detect 32 bit integer wrap around") Reported-by: Jason Wang Signed-off-by: Xie Yongji Acked-by: Jason Wang Link: https://lore.kernel.org/r/20210728130756.97-2-xieyongji@bytedance.com Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/vhost/vhost.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index a279ecacbf60..97be299f0a8d 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -702,10 +702,16 @@ static bool log_access_ok(void __user *log_base, u64 addr, unsigned long sz) (sz + VHOST_PAGE_SIZE * 8 - 1) / VHOST_PAGE_SIZE / 8); } +/* Make sure 64 bit math will not overflow. */ static bool vhost_overflow(u64 uaddr, u64 size) { - /* Make sure 64 bit math will not overflow. */ - return uaddr > ULONG_MAX || size > ULONG_MAX || uaddr > ULONG_MAX - size; + if (uaddr > ULONG_MAX || size > ULONG_MAX) + return true; + + if (!size) + return false; + + return uaddr > ULONG_MAX - size + 1; } /* Caller should have vq mutex and device mutex. */ -- 2.30.2