From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5D98B8BF8; Sun, 12 Nov 2023 13:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Fuh2Nr59" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08AADC43391; Sun, 12 Nov 2023 13:23:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699795436; bh=O8b5Mv2kgEGjlHcHU81A4qAHsu0M6DVJuc5PbVs4Wlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fuh2Nr59ERbToE6mZa7exnP5smA6uW/x7lzMFP5q2MPjobMJbW64EC1PKKG+TkjZx zJtJiEwfbNesTUkLp+gWSeVVc1P1CyKWrWlm/7aOnMzJ+vBnh9BpDlo/uDS5iaCPuf A5RT7HrHs5tMO2puW5uHRoIPXJWzecyxlrWG3etXi/jhQiLwga3g3+TfNNcW45gdZQ uBP1sSmlPVoIiYaGdBDG0p/UzcfdJ3qs4JsHfn120YyaaOUm6NAU2o4QU6I4hWIK6I Tl2oeJdR4V8hEBa4DLnd5wG+GOOZ4Gks1WZkWloQWf+pKToHuMH6O9QXZmi44F8LJa 6yPWtRbVkFmKA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: zhenwei pi , "Michael S . Tsirkin" , Sasha Levin , jasowang@redhat.com, axboe@kernel.dk, virtualization@lists.linux.dev, linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 6.5 5/7] virtio-blk: fix implicit overflow on virtio_max_dma_size Date: Sun, 12 Nov 2023 08:23:37 -0500 Message-ID: <20231112132347.174334-5-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231112132347.174334-1-sashal@kernel.org> References: <20231112132347.174334-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.5.11 Content-Transfer-Encoding: 8bit From: zhenwei pi [ Upstream commit fafb51a67fb883eb2dde352539df939a251851be ] The following codes have an implicit conversion from size_t to u32: (u32)max_size = (size_t)virtio_max_dma_size(vdev); This may lead overflow, Ex (size_t)4G -> (u32)0. Once virtio_max_dma_size() has a larger size than U32_MAX, use U32_MAX instead. Signed-off-by: zhenwei pi Message-Id: <20230904061045.510460-1-pizhenwei@bytedance.com> Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/block/virtio_blk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 1fe011676d070..4a4b9bad551e8 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -1313,6 +1313,7 @@ static int virtblk_probe(struct virtio_device *vdev) u16 min_io_size; u8 physical_block_exp, alignment_offset; unsigned int queue_depth; + size_t max_dma_size; if (!vdev->config->get) { dev_err(&vdev->dev, "%s failure: config access disabled\n", @@ -1411,7 +1412,8 @@ static int virtblk_probe(struct virtio_device *vdev) /* No real sector limit. */ blk_queue_max_hw_sectors(q, UINT_MAX); - max_size = virtio_max_dma_size(vdev); + max_dma_size = virtio_max_dma_size(vdev); + max_size = max_dma_size > U32_MAX ? U32_MAX : max_dma_size; /* Host can optionally specify maximum segment size and number of * segments. */ -- 2.42.0