public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/repaper: fix integer overflows in repeat functions
@ 2025-01-16 13:48 Nikita Zhandarovich
  2025-02-13 16:57 ` Nikita Zhandarovich
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Nikita Zhandarovich @ 2025-01-16 13:48 UTC (permalink / raw)
  To: Noralf Trønnes, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann
  Cc: Nikita Zhandarovich, David Airlie, Simona Vetter, dri-devel,
	linux-kernel, lvc-project

There are conditions, albeit somewhat unlikely, under which right hand
expressions, calculating the end of time period in functions like
repaper_frame_fixed_repeat(), may overflow.

For instance, if 'factor10x' in repaper_get_temperature() is high
enough (170), as is 'epd->stage_time' in repaper_probe(), then the
resulting value of 'end' will not fit in unsigned int expression.

Mitigate this by casting 'epd->factored_stage_time' to wider type before
any multiplication is done.

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: 3589211e9b03 ("drm/tinydrm: Add RePaper e-ink driver")
Cc: stable@vger.kernel.org
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
 drivers/gpu/drm/tiny/repaper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/repaper.c
index 77944eb17b3c..d76c0e8e05f5 100644
--- a/drivers/gpu/drm/tiny/repaper.c
+++ b/drivers/gpu/drm/tiny/repaper.c
@@ -456,7 +456,7 @@ static void repaper_frame_fixed_repeat(struct repaper_epd *epd, u8 fixed_value,
 				       enum repaper_stage stage)
 {
 	u64 start = local_clock();
-	u64 end = start + (epd->factored_stage_time * 1000 * 1000);
+	u64 end = start + ((u64)epd->factored_stage_time * 1000 * 1000);
 
 	do {
 		repaper_frame_fixed(epd, fixed_value, stage);
@@ -467,7 +467,7 @@ static void repaper_frame_data_repeat(struct repaper_epd *epd, const u8 *image,
 				      const u8 *mask, enum repaper_stage stage)
 {
 	u64 start = local_clock();
-	u64 end = start + (epd->factored_stage_time * 1000 * 1000);
+	u64 end = start + ((u64)epd->factored_stage_time * 1000 * 1000);
 
 	do {
 		repaper_frame_data(epd, image, mask, stage);

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-02-25  0:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-16 13:48 [PATCH] drm/repaper: fix integer overflows in repeat functions Nikita Zhandarovich
2025-02-13 16:57 ` Nikita Zhandarovich
2025-02-13 17:08   ` Noralf Trønnes
2025-02-14  1:54 ` Alex Lanzano
2025-02-14 13:29   ` David Laight
2025-02-15  1:02     ` Alex Lanzano
2025-02-15 11:48       ` David Laight
2025-02-15 16:35         ` Alex Lanzano
2025-02-15 18:09 ` Alex Lanzano
2025-02-25  0:47 ` Alex Lanzano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox