Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2921320pxb; Tue, 24 Aug 2021 10:38:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAADviV1qSuoQFNE2k/UqdgoUrOmnP2lj4Y8ll2JQu2EG+Qeh2cc0mPLfgo8Lm9VCxdJmr X-Received: by 2002:a05:6e02:1b81:: with SMTP id h1mr27844113ili.240.1629826723158; Tue, 24 Aug 2021 10:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629826723; cv=none; d=google.com; s=arc-20160816; b=hRgKoNi9JCI9NOVY7XF3tXw9J1V9n8cVkRIUo8wd4H2fqOXSp5Cb4BHQeTFo7INZIw SyTIx6U4bg5PEGf4i/bBliMCR3VWWIAEr5yWloKwPEmy8aZcH3RHjGeGqaa4/PAIcgOc Ne0ilKh6+Jmdj2I0aL5LGX+UjEeJaZvtbrE/X3gEWxBzQXN55QWW3IBRLIAH2u6IxomA 2wdbWqao+0PvuAAwHHwThS+FVEh2fLdKFxoU8rLTWpwjpEYoeQcsIzQzlje6vymMhd2n j1eREqwkqkXkVvAORfFCOxXKAjmpVT4gi2jp7/yGJHIjOmxIawo2/HWisrx1U0bUI3M1 pSwQ== 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=n8y2hnGsMfw8uKH+bL00H3ZVkkmOrlY8+EPfrDCHg0Q=; b=QUJ7thChP6+VW1nNTKUNux4i3BzwY3Tfeqd2aJCXt9M3CFzqj5+UBKPRqDHCeYK8Gz TSGcdlI+qwBZ7dhXxS+JjRdxrcotq2AAkywnd+S/MUAvXXYtLWoLsYfuAzRq2jv7tehZ senJX0Ew65rPHq0eqcWWDVL6Rddv5KdCCO58qVEHpBUyNPLipZKjVfNv/9RkFlu+Q7ts SwWtur7MAgIZRquONOCDAhZ1CZC0no7dWoB9lHGXm7c4uAYODqzinuYPpMSvBLXLwOAL PJfSMs4KWawEXh5NWVGBiXRvBS+2DmUAF2hzGXFeW3CkNRbdD0Ru8P46ByIEMvvquHIN G4bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=junMbsQp; 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 x5si17002001ior.24.2021.08.24.10.38.31; Tue, 24 Aug 2021 10:38:43 -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=junMbsQp; 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 S239592AbhHXRid (ORCPT + 99 others); Tue, 24 Aug 2021 13:38:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:41186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242355AbhHXRfJ (ORCPT ); Tue, 24 Aug 2021 13:35:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3742761BC1; Tue, 24 Aug 2021 17:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824807; bh=Astv9Y1lGkmZ6IPwhybz40DQskpH+ZmQ1aj00HYuO5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=junMbsQpNWrWz4ygv7W/eW5nhvt3cZPFT0BsON/A32Ds7qslxVQhegG2u/fBhxqWi UjormD08dBKbfobqvomvFnSOMAVT+VBXMu/vgaD58SM9PvFjUXCW9rp5eh2CcJXr3e hD1iAMOb9W1BEUDWjGBRDeXqCVR12Qsymm9KqzgdinyRm85qK/4nfAsRQ8TkR5H+L8 ngP3MFMIw5urLfCMSFlsSILGtfifBi4z976JpywYOIxFH0FTeDUjtYJdABRrG1exXm V0s0D48tcwnj20Y4JAtQ4AuV8HYqh1oN5SHAVUkARfelV4pwY4aqHeMa8wPv2QkvzP AwZah3xdcqsSQ== 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 4.9 32/43] vhost: Fix the calculation in vhost_overflow() Date: Tue, 24 Aug 2021 13:06:03 -0400 Message-Id: <20210824170614.710813-33-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170614.710813-1-sashal@kernel.org> References: <20210824170614.710813-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.281-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.281-rc1 X-KernelTest-Deadline: 2021-08-26T17:06+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 d2431afeda84..62c61a283b35 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -675,10 +675,16 @@ static int 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