Skip to contentSkip to conversation

drm/bochs: avoid sign extension in video memory size

PATCH New Alexey Simakov 1 participant 1 message Dec 8, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bochs: avoid sign extension in video memory size

When bochs_dispi_read() returns a value in the 0x8000–0xFFFF range, the expression bochs_dispi_read() * 64 * 1024 is computed in signed int and then promoted to unsigned long, which can lead to int -> unsigned long sign extension.

Cast the multipliers to unsigned long so that the multiplication is done in unsigned long and covers the full range of the DISPI video memory register without sign extension.

The QEMU stdvga device using the bochs dispi interface exposes video memory up to 256 MB, so this change is made against malicious or out-of-spec return values from the device.

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

Fixes 0a6659bdc5e8 ("drm/bochs: new driver")
---
 drivers/gpu/drm/tiny/bochs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tiny/bochs.c +1 -1
index d2d5e9f1269f..943bceadd2f4 100644
@@ -258,7 +258,7 @@ static int bochs_hw_init(struct bochs_device *bochs)
 
 	id = bochs_dispi_read(bochs, VBE_DISPI_INDEX_ID);
 	mem = bochs_dispi_read(bochs, VBE_DISPI_INDEX_VIDEO_MEMORY_64K)
-		* 64 * 1024;
+		* 64UL * 1024UL;
 	if ((id & 0xfff0) != VBE_DISPI_ID0) {
 		DRM_ERROR("ID mismatch\n");
 		return -ENODEV;
Signature · 1 line
2.34.1