From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6185C4399F8; Mon, 17 Aug 2026 13:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786974046; cv=none; b=BvsG8kH9b5KUmTJbizGe2nrjZYBNw6cFixWFsHpsMWEyBgA0NaL4JVcwNP9rtKzB2K7AvV2694u9UskZWlY3FA4Jvpdi05Wkc4dCC8VQ5sGgZG1lEYDUjMgk6Q3Hd5gNVCPExHW9ym7PGg1U9EI/ILK6f3uiFjz7K4ZQb7s72nI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786974046; c=relaxed/simple; bh=160cfhS3oopcRR1+ovI3ICIZXO5igstJT+dsdV5Bci4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ouZR656UT5WJbzvEBUG4+LRPW0n8d6lAgsLaUS09xBqdjxqPwtXXM5CUYgseEjHuVlz/NqB3xeQrSf7OwM7r8y/GuQgW/XPBRN9guYLq86CnC285Amm893wlwjv8iLTj5DjoXEOL7fBKkAzkWWuk+GCAzj38r0SM77WqL16ebvk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xEJDoolH; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xEJDoolH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3AD01F00A3D; Mon, 17 Aug 2026 13:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786974037; bh=NTftY8EudVSyUCpLhzJijkSBp7z5TEC+xv9K39w4feI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xEJDoolHAM2yCofknVV4kle1OB3sclQo0++5NLLaepQd+KppTBB3SVU6oNNoLjDzY orgmi9x/MD0rAZUAdyx3UCvG9erAYYwWlvQB8rVjQvlWA41VnRTehDbkzM6BT81BfU xAxkgeuWI+bDh1ptO1PUhHY62llCdPZTnE/mUr14= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Michael S. Tsirkin" , Yousef Alhouseen , Sasha Levin Subject: [PATCH 7.1 066/271] vhost/vdpa: reject overflowing PA map page counts on 32-bit Date: Mon, 17 Aug 2026 15:29:51 +0200 Message-ID: <20260817132539.453853164@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132536.752504388@linuxfoundation.org> References: <20260817132536.752504388@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yousef Alhouseen [ Upstream commit 0619aaa34c0c2a2dcb07f0e9c8a34e7efb8c4cdf ] vhost_vdpa_pa_map() adds the IOVA page offset to the user-controlled map size before computing the number of pages to pin. On 32-bit systems, where unsigned long is narrower than u64, that addition can overflow and the code can pin and map fewer pages than the requested IOTLB range. Reject sizes that overflow the unsigned long page-count calculation. Fixes: 22af48cf91aa ("vdpa: factor out vhost_vdpa_pa_map() and vhost_vdpa_pa_unmap()") Acked-by: Michael S. Tsirkin Signed-off-by: Yousef Alhouseen Signed-off-by: Michael S. Tsirkin Message-ID: Signed-off-by: Sasha Levin --- drivers/vhost/vdpa.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index ef642bc9f97e1..c3d913bd7cac7 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -1109,6 +1109,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, unsigned int gup_flags = FOLL_LONGTERM; unsigned long npages, cur_base, map_pfn, last_pfn = 0; unsigned long lock_limit, sz2pin, nchunks, i; + unsigned long page_offset; u64 start = iova; long pinned; int ret = 0; @@ -1121,7 +1122,13 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, if (perm & VHOST_ACCESS_WO) gup_flags |= FOLL_WRITE; - npages = PFN_UP(size + (iova & ~PAGE_MASK)); + page_offset = iova & ~PAGE_MASK; + if (size > ULONG_MAX - page_offset) { + ret = -EINVAL; + goto free; + } + + npages = PFN_UP(size + page_offset); if (!npages) { ret = -EINVAL; goto free; -- 2.53.0