Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2900282pxb; Tue, 24 Aug 2021 10:10:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpLPVXmaXULKFmmGuI96nSHZo2ID2fkOG0/igq4NgvoxEubqmjs3hsLXWwT2i7UECj11sl X-Received: by 2002:a05:6e02:1074:: with SMTP id q20mr7329762ilj.204.1629825040922; Tue, 24 Aug 2021 10:10:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825040; cv=none; d=google.com; s=arc-20160816; b=P8/L7h5P2PENf8UFqNYHW6EXbBOQnf0XEcEct9VJwmvv2Gs6QWcvI2EbsSH23fO3QR L9MuLBPb0wiorHcE9OELOMZ4E3TaK2oub6Sq/97MNrFcK1QHIovo3W852LxPTUxOWM0M /ttkn04dYq2bdDOFqYvXBRLRoEo7P9jaLVivK4/Wat0f23PgRK3FCQH4UUhJ9VspfdnM vRRf5Gic+Vrhzo5P9kn+88koc0iTIoge5UjYgOfEEE3sGcOXbPIa2YRmMYXVmSy3a49L KGHKkEmf1dzJzn5uBueURoIQkuaC7rA6AKN7AxT/QyD8XtSUDbV9wRx/pTEQ4FDG3uDO +6JQ== 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=cKeSa7wVweFx75s5uGyKaG1orVaCFLv3mzmeVSp66Ug=; b=WN2om9GMZS2Q6cGw67JGOa8v80sLViKlMPeRBPu5O8iwQTKDUFOdUyhnDcE1WdYl33 k9FEL4M4KnN9BvqQ7KfiedPldYnIh+lEsWvQt+uXiL+7DtcaeziluODHfNns2TNM2Ljp 5RuZbUMiZ2aDuGsfOKlNjSbt/i91t8rMRk8Nq7p7ljZhLrCUp1CMZjRr2teHtCx+6ZVp W7hnvefprXEZlvg2WXelzEvnStTPlSh1fVz3cuZG117m7qEbSyM0nUDSdsE9oYckCA3n 6jwQgZeyZyCDngldQp+WQuzT4+2LR1c6Rp1IsoQ6b9VKHWsVJ7JUrMZWl0pXWK16p4YR 2JlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jdYYN94f; 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 l8si18433735ilt.110.2021.08.24.10.10.28; Tue, 24 Aug 2021 10:10:40 -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=jdYYN94f; 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 S239941AbhHXRJq (ORCPT + 99 others); Tue, 24 Aug 2021 13:09:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:46474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239424AbhHXRHC (ORCPT ); Tue, 24 Aug 2021 13:07:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4545D61A03; Tue, 24 Aug 2021 16:59:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824393; bh=F2FT0g7L52h8sL+T7edZCGy0lh3Ffzr5XO4mXu3JFg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jdYYN94f35r8gpSOXy1Ngs56jBUBMOUNP8oZVv54tBv52xm34o71Y0u/PTe+Qs1Z2 KSZZt47tjqhw6JQGduk5J3bV7w+rE4b28BnEDzpEzBn+KRLLMHOjxhnAHWzJI9LXUv qfJHH8u1U4kapMbWHDhixech1cAxihQGZI6SYp1mfufhKLxEJLrkiuRIROAyMqnq5k 3C5u5ZM1qhA/gtFWou6vo9e5b5A1oc2DApLFxDGXuKDjZJWxiiDtOOSk6z0mVuCTW7 inliokg6rVDxAOfcWyiLQIGcisyuy6jvtTut9gUa61D6Bl28uAP5kSR4dYu08GrLaI 6Bo6WN0IY5BJw== 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.10 43/98] vhost: Fix the calculation in vhost_overflow() Date: Tue, 24 Aug 2021 12:58:13 -0400 Message-Id: <20210824165908.709932-44-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165908.709932-1-sashal@kernel.org> References: <20210824165908.709932-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.61-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.10.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.10.61-rc1 X-KernelTest-Deadline: 2021-08-26T16:58+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 5ccb0705beae..f41463ab4031 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -735,10 +735,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