drm/vesadrm: Avoid NULL-ptr deref in vesadrm_pmi_cmap_write()
Subsystems (3)
Thomas Zimmermann
maintainerPATCH 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.
--- drivers/gpu/drm/sysfb/vesadrm.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/sysfb/vesadrm.c +9 -4
@@ -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
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
Signed-off-by Thomas Zimmermann <[email protected]>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