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 F1AFC1465AA; Thu, 11 Apr 2024 10:44:10 +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=1712832251; cv=none; b=k7KjQIvz9Z6JDybBbciGGytYOlDOvxHFCAsOd9Ghqok4D5XK12cbzI8qO4Hpe71Rr4LPcRjyvVqs6cE0qI8YVc2h4nbLKKDUKkj1ILcWD4bBSUsuM850ORPj4x2qyyE8ZCA/POF3Jsa9jVwu2ko/jnS/cWqjAs2djKzXpP7gvxA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712832251; c=relaxed/simple; bh=BK/+KHmssIe8u4pQk21GehITA6wrbjD0khuEfZw+hHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H3saAay0ehyS7MJMtlviwdmsIZNH8GRB2mhE6AfbQyJwb0r9+cQUNvfrIK7tVjjvuzG5l+A2N/r4cWjiS8VY/+n10jOAhu/3Mo8wIRV1oAnDcWFL08nquwhPXekSIzODDGcOA8tYQ7jVnJAM94ZbHVwSqRBQlH/d8gL6S2/h4n0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HYWvC0hM; 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="HYWvC0hM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 713C2C433F1; Thu, 11 Apr 2024 10:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712832250; bh=BK/+KHmssIe8u4pQk21GehITA6wrbjD0khuEfZw+hHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HYWvC0hMXBBRj81dWuUhaZadC1d5rsX+MY1/ZDlBryHOzZbZFWDkwDZNw/nySsiM8 6nhASJf8z8w6RJdm/AKbf4bDP0Ze7OVqhZzx+9gvFK3CLBTaFAyFRQQrn4KsO29vzi lbkDqxAXNp6SfBXw8zxLbu3E8n/anhJ+VsVqU+ik= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Roman Smirnov , Sergey Shtylyov , Helge Deller , Sasha Levin Subject: [PATCH 5.10 281/294] fbmon: prevent division by zero in fb_videomode_from_videomode() Date: Thu, 11 Apr 2024 11:57:24 +0200 Message-ID: <20240411095443.998522770@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411095435.633465671@linuxfoundation.org> References: <20240411095435.633465671@linuxfoundation.org> User-Agent: quilt/0.67 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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Roman Smirnov [ Upstream commit c2d953276b8b27459baed1277a4fdd5dd9bd4126 ] The expression htotal * vtotal can have a zero value on overflow. It is necessary to prevent division by zero like in fb_var_to_videomode(). Found by Linux Verification Center (linuxtesting.org) with Svace. Signed-off-by: Roman Smirnov Reviewed-by: Sergey Shtylyov Signed-off-by: Helge Deller Signed-off-by: Sasha Levin --- drivers/video/fbdev/core/fbmon.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/video/fbdev/core/fbmon.c b/drivers/video/fbdev/core/fbmon.c index 1bf82dbc9e3cf..3c29a5eb43805 100644 --- a/drivers/video/fbdev/core/fbmon.c +++ b/drivers/video/fbdev/core/fbmon.c @@ -1311,7 +1311,7 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_inf int fb_videomode_from_videomode(const struct videomode *vm, struct fb_videomode *fbmode) { - unsigned int htotal, vtotal; + unsigned int htotal, vtotal, total; fbmode->xres = vm->hactive; fbmode->left_margin = vm->hback_porch; @@ -1344,8 +1344,9 @@ int fb_videomode_from_videomode(const struct videomode *vm, vtotal = vm->vactive + vm->vfront_porch + vm->vback_porch + vm->vsync_len; /* prevent division by zero */ - if (htotal && vtotal) { - fbmode->refresh = vm->pixelclock / (htotal * vtotal); + total = htotal * vtotal; + if (total) { + fbmode->refresh = vm->pixelclock / total; /* a mode must have htotal and vtotal != 0 or it is invalid */ } else { fbmode->refresh = 0; -- 2.43.0