]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/repaper: fix integer overflows in repeat functions
authorNikita Zhandarovich <n.zhandarovich@fintech.ru>
Thu, 16 Jan 2025 13:48:01 +0000 (05:48 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:41:03 +0000 (07:41 +0200)
commit 4d098000ac193f359e6b8ca4801dbdbd6a27b41f upstream.

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>
Signed-off-by: Alex Lanzano <lanzano.alex@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250116134801.22067-1-n.zhandarovich@fintech.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/tiny/repaper.c

index 2e01cf0a9876bc328485d4429c5538a15143ec60..6395b7016f13484ce329a48d3821f67c72ff7aa8 100644 (file)
@@ -454,7 +454,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);
@@ -465,7 +465,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);