mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/bochs: avoid sign extension in video memory size
@ 2025-12-08 11:16 Alexey Simakov
  0 siblings, 0 replies; only message in thread
From: Alexey Simakov @ 2025-12-08 11:16 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: Alexey Simakov, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Dave Airlie,
	virtualization, dri-devel, linux-kernel, lvc-project

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")
Signed-off-by: Alexey Simakov <bigalex934@gmail.com>
---
 drivers/gpu/drm/tiny/bochs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c
index d2d5e9f1269f..943bceadd2f4 100644
--- a/drivers/gpu/drm/tiny/bochs.c
+++ b/drivers/gpu/drm/tiny/bochs.c
@@ -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;
-- 
2.34.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-12-08 11:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-08 11:16 [PATCH] drm/bochs: avoid sign extension in video memory size Alexey Simakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®