summaryrefslogtreecommitdiff
path: root/drivers/accel
diff options
context:
space:
mode:
authorJeffrey Hugo <quic_jhugo@quicinc.com>2025-03-06 10:19:59 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-03-28 21:59:53 +0100
commit3d123ec74d81a646de4faf4b3b9a0a1a061f21bd (patch)
tree092bcb94746f632780106edcfc5e344355cf3eb4 /drivers/accel
parent59b683594ff39b75ee2bcaec1519567e4e0a6ce0 (diff)
downloadlinux-3d123ec74d81a646de4faf4b3b9a0a1a061f21bd.tar.gz
linux-3d123ec74d81a646de4faf4b3b9a0a1a061f21bd.tar.bz2
linux-3d123ec74d81a646de4faf4b3b9a0a1a061f21bd.zip
accel/qaic: Fix possible data corruption in BOs > 2G
[ Upstream commit 84a833d90635e4b846333e2df0ae72f9cbecac39 ] When slicing a BO, we need to iterate through the BO's sgt to find the right pieces to construct the slice. Some of the data types chosen for this process are incorrectly too small, and can overflow. This can result in the incorrect slice construction, which can lead to data corruption in workload execution. The device can only handle 32-bit sized transfers, and the scatterlist struct only supports 32-bit buffer sizes, so our upper limit for an individual transfer is an unsigned int. Using an int is incorrect due to the reservation of the sign bit. Upgrade the length of a scatterlist entry and the offsets into a scatterlist entry to unsigned int for a correct representation. While each transfer may be limited to 32-bits, the overall BO may exceed that size. For counting the total length of the BO, we need a type that can represent the largest allocation possible on the system. That is the definition of size_t, so use it. Fixes: ff13be830333 ("accel/qaic: Add datapath") Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Signed-off-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com> Reviewed-by: Lizhi Hou <lizhi.hou@amd.com> Reviewed-by: Troy Hanson <quic_thanson@quicinc.com> Reviewed-by: Youssef Samir <quic_yabdulra@quicinc.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250306171959.853466-1-jeff.hugo@oss.qualcomm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/accel')
-rw-r--r--drivers/accel/qaic/qaic_data.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index d2f8c70a77a5..e8e6eb85f5f1 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -165,9 +165,10 @@ static void free_slice(struct kref *kref)
static int clone_range_of_sgt_for_slice(struct qaic_device *qdev, struct sg_table **sgt_out,
struct sg_table *sgt_in, u64 size, u64 offset)
{
- int total_len, len, nents, offf = 0, offl = 0;
struct scatterlist *sg, *sgn, *sgf, *sgl;
+ unsigned int len, nents, offf, offl;
struct sg_table *sgt;
+ size_t total_len;
int ret, j;
/* find out number of relevant nents needed for this mem */
@@ -175,6 +176,8 @@ static int clone_range_of_sgt_for_slice(struct qaic_device *qdev, struct sg_tabl
sgf = NULL;
sgl = NULL;
nents = 0;
+ offf = 0;
+ offl = 0;
size = size ? size : PAGE_SIZE;
for_each_sgtable_dma_sg(sgt_in, sg, j) {