From nobody Wed Feb 5 19:04:37 2025 Received: from exchange.fintech.ru (exchange.fintech.ru [195.54.195.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9631D1DE4EC for ; Thu, 16 Jan 2025 13:48:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.54.195.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035299; cv=none; b=e6ln7X9FTAoY+94o8+7PMeK7ZKlMUibcp/gBxKj/pDtkdWY3k4Dp3cqrZs6v6w5vyaC8nXewjaVONHxdr/aVDCQyiMIRaQcpePtXyuTdUfYlhc8JxetUb0HqWmUZQ5J/X1ARniscQj5VdLGOpSa+UB6tUJkWHCbZTjLHvvdY/q0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035299; c=relaxed/simple; bh=kC4b/mDV8Y9d/qB3SW54l5patyhjBOThJmmrIJAwetI=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=nZv2nGEF9tfDbIoHp2AFt8OWDKEsmHgtI6pDQrlvMO2baBoCqWStNAjEZ1siXf79Egw2//dxxOxim8m/WU371R/q6x3Hv2J03Y4dkszMIWCM3zkikr+YUPdW6g/GkuoGGPfB+3j+e+PYswESg2N0Y8NfAUNxha3H/QHEOJGWgIM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fintech.ru; spf=pass smtp.mailfrom=fintech.ru; arc=none smtp.client-ip=195.54.195.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fintech.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fintech.ru Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Thu, 16 Jan 2025 16:48:07 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Thu, 16 Jan 2025 16:48:07 +0300 From: Nikita Zhandarovich To: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann CC: Nikita Zhandarovich , David Airlie , Simona Vetter , , , Subject: [PATCH] drm/repaper: fix integer overflows in repeat functions Date: Thu, 16 Jan 2025 05:48:01 -0800 Message-ID: <20250116134801.22067-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) Content-Type: text/plain; charset="utf-8" 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 --- 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_e= pd *epd, u8 fixed_value, enum repaper_stage stage) { u64 start =3D local_clock(); - u64 end =3D start + (epd->factored_stage_time * 1000 * 1000); + u64 end =3D start + ((u64)epd->factored_stage_time * 1000 * 1000); =20 do { repaper_frame_fixed(epd, fixed_value, stage); @@ -467,7 +467,7 @@ static void repaper_frame_data_repeat(struct repaper_ep= d *epd, const u8 *image, const u8 *mask, enum repaper_stage stage) { u64 start =3D local_clock(); - u64 end =3D start + (epd->factored_stage_time * 1000 * 1000); + u64 end =3D start + ((u64)epd->factored_stage_time * 1000 * 1000); =20 do { repaper_frame_data(epd, image, mask, stage);