Skip to contentSkip to conversation

fbdev: kyro: Fix division by zero in SetOverlayViewPort()

PATCH New Danila Chernetsov 1 participant 1 message Nov 27 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fbdev: kyro: Fix division by zero in SetOverlayViewPort()

In SetOverlayViewPort(), the vertical scale factor is calculated as (ulDest << 11) / ulSrc and used as a divisor a few lines later. The quotient truncates to zero if the on-screen viewport is a single line high (ulDest == 0), or if the overlay surface was created with zero height, in which case ulSrc wraps around to U32_MAX. The existing check "if (ulSrc <= 1)" does not prevent either case, and the division by ulFxScale causes a divide error in the kernel.

Return -EINVAL when the scale factor is zero.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/video/fbdev/kyro/STG4000OverlayDevice.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/video/fbdev/kyro/STG4000OverlayDevice.c +3 -0
index cb6fa0991fca..fae1f5d5ec8a 100644
@@ -376,6 +376,9 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg,
 	ulFxScale = (ulDest << 11) / ulSrc;	/* fixed point scale factor */
 	ulFxOffset = (srcDest.lDstY2 - srcDest.ulDstY2) << 11;
 
+	if (!ulFxScale)
+		return -EINVAL;
+
 	ulSrcBottom = ulSrcBottom - (ulFxOffset / ulFxScale);
 	ulSrc = ulSrcBottom - ulSrcTop;
 	ulHeight = ulSrc;
Signature · 1 line
2.25.1