Skip to contentSkip to conversation

drm/vesadrm: Avoid NULL-ptr deref in vesadrm_pmi_cmap_write()

PATCH In review Thomas Zimmermann 2 participants 2 messages Jun 17, 2025 – Jun 27, 2025

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

PATCH 1/1 drm/vesadrm: Avoid NULL-ptr deref in vesadrm_pmi_cmap_write()

Only set PMI fields if the screen_info's Vesa PM segment has been set. Vesa PMI is the power-management interface. It also provides means to set the color palette. The interface is optional, so not all VESA graphics cards support it. Print vesafb's warning [1] if the hardware palette cannot be set at all.

If unsupported the field PrimaryPalette in struct vesadrm.pmi is NULL, which results in a segmentation fault. Happens with qemu's Cirrus emulation.

Fixes 814d270b31d2 ("drm/sysfb: vesadrm: Add gamma correction")
Cc Thomas Zimmermann <[email protected]>
Cc Javier Martinez Canillas <[email protected]>
---
 drivers/gpu/drm/sysfb/vesadrm.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/sysfb/vesadrm.c +9 -4
index c5216dbe21ec..074d2bae9db3 100644
@@ -334,14 +334,19 @@ static struct vesadrm_device *vesadrm_device_create(struct drm_driver *drv,
 
 	if (!__screen_info_vbe_mode_nonvga(si)) {
 		vesa->cmap_write = vesadrm_vga_cmap_write;
-#if defined(CONFIG_X86_32)
 	} else {
+#if defined(CONFIG_X86_32)
 		phys_addr_t pmi_base = __screen_info_vesapm_info_base(si);
-		const u16 *pmi_addr = phys_to_virt(pmi_base);
 
-		vesa->pmi.PrimaryPalette = (u8 *)pmi_addr + pmi_addr[2];
-		vesa->cmap_write = vesadrm_pmi_cmap_write;
+		if (pmi_base) {
+			const u16 *pmi_addr = phys_to_virt(pmi_base);
+
+			vesa->pmi.PrimaryPalette = (u8 *)pmi_addr + pmi_addr[2];
+			vesa->cmap_write = vesadrm_pmi_cmap_write;
+		} else
 #endif
+		if (format->is_color_indexed)
+			drm_warn(dev, "hardware palette is unchangeable, colors may be incorrect\n");
 	}
 
 #if defined(CONFIG_FIRMWARE_EDID)
Signature · 1 line
2.49.0
maintainer Acked-by on v1 1/1
#1 lore raw

Thomas Zimmermann <[email protected]> writes:

Hello Thomas,

Quoted 10 lines

Only set PMI fields if the screen_info's Vesa PM segment has been set. Vesa PMI is the power-management interface. It also provides means to set the color palette. The interface is optional, so not all VESA graphics cards support it. Print vesafb's warning [1] if the hardware palette cannot be set at all.

If unsupported the field PrimaryPalette in struct vesadrm.pmi is NULL, which results in a segmentation fault. Happens with qemu's Cirrus emulation.

Quoted 7 lines
Fixes 814d270b31d2 ("drm/sysfb: vesadrm: Add gamma correction")
Cc Thomas Zimmermann <[email protected]>
Cc Javier Martinez Canillas <[email protected]>

---

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat