Skip to contentSkip to conversation

drm: zynqmp_dp: Fix integer overflow in zynqmp_dp_rate_get()

PATCH Superseded Karol Przybylski 2 participants 3 messages Dec 11, 2024 – Dec 12, 2024

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: zynqmp_dp: Fix integer overflow in zynqmp_dp_rate_get()

This patch fixes a potential integer overflow in the zynqmp_dp_rate_get() function.

The issue comes up when the expression drm_dp_bw_code_to_link_rate(dp->test.bw_code) * 10000 is evaluated using 32-bit arithmetic.

Now the constant is casted to compatible u64 type.

Resolves CID 1636340 and CID 1635811

---
 drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +1 -1
index 25c5dc61e..55e92344b 100644
@@ -2190,7 +2190,7 @@ static int zynqmp_dp_rate_get(void *data, u64 *val)
 	struct zynqmp_dp *dp = data;
 
 	mutex_lock(&dp->lock);
-	*val = drm_dp_bw_code_to_link_rate(dp->test.bw_code) * 10000;
+	*val = drm_dp_bw_code_to_link_rate(dp->test.bw_code) * (u64)10000;
 	mutex_unlock(&dp->lock);
 	return 0;
 }
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi Karol,

Thank you for the patch.

Quoted 3 lines · Karol Przybylski

This patch fixes a potential integer overflow in the zynqmp_dp_rate_get() function.

The issue comes up when the expression drm_dp_bw_code_to_link_rate(dp->test.bw_code) * 10000 is evaluated using 32-bit arithmetic.

Please wrap your commit message text to 82 columns.

Quoted 5 lines

Now the constant is casted to compatible u64 type.

Resolves CID 1636340 and CID 1635811

Does this need a Fixes: tag ? How about 'Cc: [email protected]' to get it backported to stable kernels ?

Quoted 10 lines
---
 drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +0 -0
index 25c5dc61e..55e92344b 100644

drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_rate_get(void *data, u64 *val) · line 2193

Quoted 5 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +1 -1
@@ -2190,7 +2190,7 @@ static int zynqmp_dp_rate_get(void *data, u64 *val)
 	struct zynqmp_dp *dp = data;
 
 	mutex_lock(&dp->lock);
-	*val = drm_dp_bw_code_to_link_rate(dp->test.bw_code) * 10000;
+	*val = drm_dp_bw_code_to_link_rate(dp->test.bw_code) * (u64)10000;

You can also make the integer a 64-bit constant with

	*val = drm_dp_bw_code_to_link_rate(dp->test.bw_code) * 10000ULL;
Quoted 3 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +0 -0
 	mutex_unlock(&dp->lock);
 	return 0;
 }
Signature · 3 lines
Regards,

Laurent Pinchart
author
#2 lore raw
Quoted 13 lines · Laurent Pinchart

Hi Karol,

Thank you for the patch.

Quoted 3 lines · Karol Przybylski

This patch fixes a potential integer overflow in the zynqmp_dp_rate_get() function.

The issue comes up when the expression drm_dp_bw_code_to_link_rate(dp->test.bw_code) * 10000 is evaluated using 32-bit arithmetic.

Please wrap your commit message text to 82 columns.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

Now the constant is casted to compatible u64 type.

Resolves CID 1636340 and CID 1635811

Does this need a Fixes: tag ? How about 'Cc: [email protected]' to get it backported to stable kernels ?

Thanks for the feedback, I'll add it.

Quoted 13 lines
Quoted 13 lines
---
 drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +0 -0
index 25c5dc61e..55e92344b 100644
@@ -2190,7 +2190,7 @@ static int zynqmp_dp_rate_get(void *data, u64 *val)
      struct zynqmp_dp *dp = data;
 
Quoted 11 lines

drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_rate_get(void *data, u64 *val) · line 2193

Quoted 3 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +1 -1
      mutex_lock(&dp->lock);
-     *val = drm_dp_bw_code_to_link_rate(dp->test.bw_code) * 10000;
+     *val = drm_dp_bw_code_to_link_rate(dp->test.bw_code) * (u64)10000;

You can also make the integer a 64-bit constant with

        *val = drm_dp_bw_code_to_link_rate(dp->test.bw_code) * 10000ULL;
Quoted 3 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +0 -0
      mutex_unlock(&dp->lock);
      return 0;
 }

It does look better. I will send v2 of this patch.

Quoted 5 lines

--
Regards,

Laurent Pinchart