Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2919831pxb; Tue, 24 Aug 2021 10:36:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsZoIJ5ie8a2MJAhCF2X66ss8N7TFp97K4F0xnAUqn0nZ8VyckiWhCvsSWJc7+hyv7w06A X-Received: by 2002:a5e:c00a:: with SMTP id u10mr31796551iol.60.1629826597424; Tue, 24 Aug 2021 10:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629826597; cv=none; d=google.com; s=arc-20160816; b=nQFjshVX4V+aqxUeC3ELCAn3sLI5KKsGnd1CRnEs/8nHMVBeiivjotyutssVSDU/Tv HZ+l0k5j9Tgt35tDR+rva0T3NwDslW5r20HiGO5TKqfUYshseKfmUFukrVms7pqXU4Nw hIi5qfjqEDTSTlnPC+/J9F3aQ9VC+EggEMUvwVcc/TBkBx/3Imij0ZDzAbfJXNrb+Iyr gJm8LENIzMj7TzIDudEvJf+RnkFKumLqO2PA7TnUPriYuxNaTO3+Sv32oGfX8iCniTr4 Z0ZsG+4k5kNfNUllxu+6mUrD+puBl2jcAmNGrLi+AH2ZRYqvKJ5cmQpNUl00/cOE2kik lGNw== 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=JkUOSEQz8WIVtXzy/HyItD/wjLBK48EaPSNngwi4d7I=; b=o3bWI2Dp6gagd22QyMIWWXMUA5LvfAn2MXq75TSeZL4uohUbc3sj9m9wZguUf8KH+/ 8XA2lV+KEsepDOoQNpyOqE5UxpMO4hdLohEV+0caV7b7/a/R4rkpG1DbEheHkb/E9tCB cp3oxix52nDVZYwoy4gpmqZr1syWNsUO/HBcUJwivYV8Yk00AEiVEKerIWbay6Cbtoml 13WSjsYEYTHpPckoOlentqKxeRnk8IKKhI1Cax/g0E3jwH73xk65Iqe97cInokRnNXJp cSJsffR+F7MjCoEg23R8zvpY3OvTQFBHZMl/NEttBfj7GxoudL4pwTKN3v5rkYVlprXn Rbfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="kdB/s0at"; 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 w12si19146583ilo.99.2021.08.24.10.36.24; Tue, 24 Aug 2021 10:36:37 -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="kdB/s0at"; 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 S241425AbhHXReG (ORCPT + 99 others); Tue, 24 Aug 2021 13:34:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:35846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239844AbhHXRbF (ORCPT ); Tue, 24 Aug 2021 13:31:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 067A361B97; Tue, 24 Aug 2021 17:05:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824745; bh=A+l5VQCID7FBlNVa+iZcndmd3sH6Usn2Xj+ECSADz6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kdB/s0atWlVxweUULBKawYw2lykUJrIQPnK5aLGgt0tSnvDx0KgWSpEP87TYuEhwG rtD2WibEjK+SXwRQeOunC54+PULdIyoD4zlNn8llhM+II9+C0kgKyE5bt5KIDB3noo iVd0CbqW9Ay06FmjX6ozym0U6CAETe5oLi8906pqYzF2KrUvU2Yi/OEpIQrQtN28cP AFcNFpnoaOmr5mmWXZhiUOxKGEDJRTb7GsYxoh9zagbf9O68y+SkyODxu0pRhnT5tZ MzqSiaX5CKfxFjBKoTDn+AhtfCFkXk/TPVlqDGw26OtDFpnA4nxCpziDkZSHobBFRi m/nwRZmzPK71A== 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.14 49/64] vhost: Fix the calculation in vhost_overflow() Date: Tue, 24 Aug 2021 13:04:42 -0400 Message-Id: <20210824170457.710623-50-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170457.710623-1-sashal@kernel.org> References: <20210824170457.710623-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.245-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.245-rc1 X-KernelTest-Deadline: 2021-08-26T17:04+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 4b5590f4e98b..93cdeb516594 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -685,10 +685,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