From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 660701B3934; Thu, 17 Apr 2025 18:48:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744915717; cv=none; b=bh9J0RdP3/32ezmaJmAcqkA7EbP6+tbTQ/TgORM3KpzVGow/vkyBXlXLgU+8mLseeS93MOWh2hL/CJj0PE43Qn/e6cGPS+/zWD3lQUm5V4OXOkzLy+ikBIQEcwzgRMMTJ3fOSuiv4l1CVhjiWrcY/28qvvYQoQvurt2qe17tNtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744915717; c=relaxed/simple; bh=aKx6ziFuTBRBkO9whNTECMyvjtJJl3R2KEsWVQHaEZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sKbV2wg+X4rPL38ido/qFwj6qXzJgOUfcj8Zs2YnjKAE4IefqwkI6ICgtp5MYcq3NNRL59WyCIuGH6SJOtOD6AoKqw6CNx2gkT61d2uZJmb10o1nUlCk/F/xGzf2tUvMtqU9HdkjHFSod//L9eqg8tHnlPGuC/PAgEQc7mPBtbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=L/f2CjHx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="L/f2CjHx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFCBFC4CEE4; Thu, 17 Apr 2025 18:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744915717; bh=aKx6ziFuTBRBkO9whNTECMyvjtJJl3R2KEsWVQHaEZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/f2CjHx/dxNBbyl9qsl7wVRUqXlUWQGty8GoJn83HrEH2qhvI9FMomTYuOE5RGKF 1vdXB8C7vgx2zIKJHVJONl8WRDe+mMVqWmCKWM+FgUROMMa05KLL5vZ6J6IH03jXLA LUol1JJfJ/sr2eX+AoMpIreZklt5Wv5CbNCA5IOI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Karina Yankevich , Sergey Shtylyov , Hans Verkuil Subject: [PATCH 6.12 216/393] media: v4l2-dv-timings: prevent possible overflow in v4l2_detect_gtf() Date: Thu, 17 Apr 2025 19:50:25 +0200 Message-ID: <20250417175116.273493853@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250417175107.546547190@linuxfoundation.org> References: <20250417175107.546547190@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Karina Yankevich commit 3edd1fc48d2c045e8259561797c89fe78f01717e upstream. In v4l2_detect_gtf(), it seems safer to cast the 32-bit image_width variable to the 64-bit type u64 before multiplying to avoid a possible overflow. The resulting object code even seems to look better, at least on x86_64. Found by Linux Verification Center (linuxtesting.org) with Svace. [Sergey: rewrote the patch subject/descripition] Fixes: c9bc9f50753d ("[media] v4l2-dv-timings: fix overflow in gtf timings calculation") Cc: stable@vger.kernel.org Signed-off-by: Karina Yankevich Signed-off-by: Sergey Shtylyov Signed-off-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/media/v4l2-core/v4l2-dv-timings.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/media/v4l2-core/v4l2-dv-timings.c +++ b/drivers/media/v4l2-core/v4l2-dv-timings.c @@ -764,7 +764,7 @@ bool v4l2_detect_gtf(unsigned int frame_ u64 num; u32 den; - num = ((image_width * GTF_D_C_PRIME * (u64)hfreq) - + num = (((u64)image_width * GTF_D_C_PRIME * hfreq) - ((u64)image_width * GTF_D_M_PRIME * 1000)); den = (hfreq * (100 - GTF_D_C_PRIME) + GTF_D_M_PRIME * 1000) * (2 * GTF_CELL_GRAN); @@ -774,7 +774,7 @@ bool v4l2_detect_gtf(unsigned int frame_ u64 num; u32 den; - num = ((image_width * GTF_S_C_PRIME * (u64)hfreq) - + num = (((u64)image_width * GTF_S_C_PRIME * hfreq) - ((u64)image_width * GTF_S_M_PRIME * 1000)); den = (hfreq * (100 - GTF_S_C_PRIME) + GTF_S_M_PRIME * 1000) * (2 * GTF_CELL_GRAN);