Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2892465pxb; Tue, 24 Aug 2021 10:01:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDbG1kBIxB9XADXaq8kQAe866t/uCoNSRMQ9xNtZs2slD8RU+5+ZKaJdGAAe7dmDxZE7qF X-Received: by 2002:a05:6638:2b1:: with SMTP id d17mr33957335jaq.63.1629824467193; Tue, 24 Aug 2021 10:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629824467; cv=none; d=google.com; s=arc-20160816; b=wQ2ueBDKZD0zfe17uWaugGVGORsUVJvimPwH/0ECZzn9oXFSySsJL9IpyvDgpgVFFe +7TJzp3O69cJBtmix9F5Uhy2fM62jolD0Fhm1PvhV4GPb2ePkX9DRQ/BNQUjWjKPIKzU YZ0v9531xrakEKJS5mZZUOaXfRyW2JQIkTYJiauBIclL7qREIFUBJcFiWH/yZwzvHpAi pp8h5XDSNI1CvBQFEBwK6aYECeJnlkzvjHUgVcv31ITsED0GmNZASuLYelkUGPThm44Q Mg42ue5NmUSdQ4jIlvJ7Ir+HrRzWIp11z63rJHNuEB2W2wudzGzlL6vMwfYOt4jh5+2O 2OXw== 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=mq/rjYtskwr/Cny+GIcqbdgXZgqTDh+uNlaLc1RX2ojCp24bCZ54M/76Yrc44PcWKq iHe5h6VELvdkhr1xjisfyxy2ftqUL9uDgglbsvCRhBw4YM5RzBKmAjzKm40SeLWM66o0 s3Nv681AtTtxpGWbs2+TGxS88GO2OphI4RV8tb6BunhTlMpy4vT1YgYaEm+Lejtdo6Kg f6XLQ6EbwGKFlVb1ClwZYpg1oyhg5d/sGi2mXqPiKeL3HW2/C/L0GvbfDAjKAfOKN0M1 +1tuaVextnjtRqgsHep3yshEgcQndAwggB4sewIuj2mVr9eR9Xw47w7/4sG2eTPkf1Se h4fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=po5rgzSW; 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 w13si13376157ilu.26.2021.08.24.10.00.54; Tue, 24 Aug 2021 10:01:07 -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=po5rgzSW; 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 S237051AbhHXQ7D (ORCPT + 99 others); Tue, 24 Aug 2021 12:59:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:39258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234226AbhHXQ5e (ORCPT ); Tue, 24 Aug 2021 12:57:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 26A0A613A7; Tue, 24 Aug 2021 16:56:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824209; bh=F2FT0g7L52h8sL+T7edZCGy0lh3Ffzr5XO4mXu3JFg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=po5rgzSWqu6gHsPm4EsbsztSlQ4WnZbR5ny91Dhk7SXvsJ94ZGpEmpxrcTJQK97qi JwOHBkUFz18Lmdrf9Z3b8zZkZbPPKkIHpuOyaEPLU/R/78F00MQvZirWR//YwwE6yS GEqpglXgIA5MGrLZHbQumcF27EOFlIvo97BVXY2wtlamPfgob75Q1yhwPckGl/mhKM haoX45yuLSAp3xCJwgnI1+Lu7+I7LbpGp+j9SWiKpIRAKhxAlz+ZO7Biq+mCOERGmR wenWYfh6/n25Q67eVsqL5f88Khc9zT6br804DzyxYXXzD/uBEgvEyIkkNLg4Eb5nW0 frPOG77LiweGQ== 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.13 042/127] vhost: Fix the calculation in vhost_overflow() Date: Tue, 24 Aug 2021 12:54:42 -0400 Message-Id: <20210824165607.709387-43-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165607.709387-1-sashal@kernel.org> References: <20210824165607.709387-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.13.13-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.13.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.13.13-rc1 X-KernelTest-Deadline: 2021-08-26T16:55+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