* [PATCH] drm: zynqmp_dp: Fix integer overflow in zynqmp_dp_rate_get()
@ 2024-12-11 12:20 Karol Przybylski
2024-12-11 12:59 ` Laurent Pinchart
0 siblings, 1 reply; 3+ messages in thread
From: Karol Przybylski @ 2024-12-11 12:20 UTC (permalink / raw)
To: karprzy7, laurent.pinchart, tomi.valkeinen, maarten.lankhorst,
mripard, tzimmermann, airlied, simona, michal.simek
Cc: dri-devel, linux-arm-kernel, linux-kernel
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
Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
---
drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c b/drivers/gpu/drm/xlnx/zynqmp_dp.c
index 25c5dc61e..55e92344b 100644
--- a/drivers/gpu/drm/xlnx/zynqmp_dp.c
+++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c
@@ -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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm: zynqmp_dp: Fix integer overflow in zynqmp_dp_rate_get()
2024-12-11 12:20 [PATCH] drm: zynqmp_dp: Fix integer overflow in zynqmp_dp_rate_get() Karol Przybylski
@ 2024-12-11 12:59 ` Laurent Pinchart
2024-12-12 9:34 ` Karol P
0 siblings, 1 reply; 3+ messages in thread
From: Laurent Pinchart @ 2024-12-11 12:59 UTC (permalink / raw)
To: Karol Przybylski
Cc: tomi.valkeinen, maarten.lankhorst, mripard, tzimmermann, airlied,
simona, michal.simek, dri-devel, linux-arm-kernel, linux-kernel
Hi Karol,
Thank you for the patch.
On Wed, Dec 11, 2024 at 01:20:26PM +0100, Karol Przybylski wrote:
> 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.
>
> Now the constant is casted to compatible u64 type.
>
> Resolves CID 1636340 and CID 1635811
>
Does this need a Fixes: tag ? How about 'Cc: stable@vger.kernel.org' to
get it backported to stable kernels ?
> Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
> ---
> drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> index 25c5dc61e..55e92344b 100644
> --- a/drivers/gpu/drm/xlnx/zynqmp_dp.c
> +++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> @@ -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;
> mutex_unlock(&dp->lock);
> return 0;
> }
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm: zynqmp_dp: Fix integer overflow in zynqmp_dp_rate_get()
2024-12-11 12:59 ` Laurent Pinchart
@ 2024-12-12 9:34 ` Karol P
0 siblings, 0 replies; 3+ messages in thread
From: Karol P @ 2024-12-12 9:34 UTC (permalink / raw)
To: Laurent Pinchart
Cc: tomi.valkeinen, maarten.lankhorst, mripard, tzimmermann, airlied,
simona, michal.simek, dri-devel, linux-arm-kernel, linux-kernel
On Wed, 11 Dec 2024 at 13:59, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Karol,
>
> Thank you for the patch.
>
> On Wed, Dec 11, 2024 at 01:20:26PM +0100, Karol Przybylski wrote:
> > 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.
>
> >
> > Now the constant is casted to compatible u64 type.
> >
> > Resolves CID 1636340 and CID 1635811
> >
>
> Does this need a Fixes: tag ? How about 'Cc: stable@vger.kernel.org' to
> get it backported to stable kernels ?
Thanks for the feedback, I'll add it.
>
> > Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
> > ---
> > drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> > index 25c5dc61e..55e92344b 100644
> > --- a/drivers/gpu/drm/xlnx/zynqmp_dp.c
> > +++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> > @@ -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;
>
> > mutex_unlock(&dp->lock);
> > return 0;
> > }
It does look better. I will send v2 of this patch.
>
> --
> Regards,
>
> Laurent Pinchart
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-12 9:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-11 12:20 [PATCH] drm: zynqmp_dp: Fix integer overflow in zynqmp_dp_rate_get() Karol Przybylski
2024-12-11 12:59 ` Laurent Pinchart
2024-12-12 9:34 ` Karol P
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).