From mboxrd@z Thu Jan 1 00:00:00 1970 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 4856F3595F for ; Thu, 13 Feb 2025 16:58:34 +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=1739465919; cv=none; b=AFCEKAYHpEa9weBoNRWFpuny3R5b6kE0OfcKCJvUcwL/zfMyq0LGP1PAQZqsLh1ekVKsYb64WqWwcmgT5GJ8Q906rTdMx+0EGN5u5T8VtCbiUqbUMrCNP/eR1Vw7TRFp2GYwV/K/8OpYo+rnYIESoG4OFExpdvaNhiD2QAGovvM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739465919; c=relaxed/simple; bh=8MuJanXHoQ5/HiDbkebvTn1C5PuyRGMYJxOxlfSPJuU=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=qOramduxrodvkCo0ESeN0ltfskq+/SbVh1ZXjiUnCC1nU80LVWYvl1uS3hJNoi55D9qU2kIZ2nQJiO+qvNtDQK/rdugxExZ9E2eLRJUMWRU2QVUD485Sw/VAP0oCmPjb8gNfkySkvLU3Sa8xSuJnEXQcy0ka07fzEJDiT5mfDqI= 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, 13 Feb 2025 19:57:25 +0300 Received: from [192.168.211.132] (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, 13 Feb 2025 19:57:25 +0300 Message-ID: Date: Thu, 13 Feb 2025 19:57:24 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] drm/repaper: fix integer overflows in repeat functions To: =?UTF-8?Q?Noralf_Tr=C3=B8nnes?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann CC: David Airlie , Simona Vetter , , , References: <20250116134801.22067-1-n.zhandarovich@fintech.ru> From: Nikita Zhandarovich Content-Language: en-US In-Reply-To: <20250116134801.22067-1-n.zhandarovich@fintech.ru> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) Gentle ping :) On 1/16/25 16:48, Nikita Zhandarovich wrote: > 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_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);