]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/i915/bios: Add some size checks to SPI VBT read
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Mon, 23 Sep 2024 15:24:49 +0000 (18:24 +0300)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Tue, 1 Oct 2024 14:30:44 +0000 (17:30 +0300)
Unify the SPI vs. PCI ROM VBT read codepaths a bit by
pulling some size overflow checks from the PCI side
into the SPI side.

v2: s/drm_dbg()/drm_dbg_kms()/

Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240923152453.11230-3-ville.syrjala@linux.intel.com
drivers/gpu/drm/i915/display/intel_bios.c

index b00aad23d6c2fbf02c492a199756d81af1333705..37f30bb76e08120946aa9a323843f114ba19b57e 100644 (file)
@@ -3088,11 +3088,22 @@ static struct vbt_header *spi_oprom_get_vbt(struct intel_display *display,
        if (count >= oprom_size)
                goto err_not_found;
 
+       if (sizeof(struct vbt_header) > oprom_size - count) {
+               drm_dbg_kms(display->drm, "VBT header incomplete\n");
+               goto err_not_found;
+       }
+
        /* Get VBT size and allocate space for the VBT */
        vbt_size = intel_spi_read(&i915->uncore,
                                  found + offsetof(struct vbt_header, vbt_size));
        vbt_size &= 0xffff;
 
+       if (vbt_size > oprom_size - count) {
+               drm_dbg_kms(display->drm,
+                           "VBT incomplete (vbt_size overflows)\n");
+               goto err_not_found;
+       }
+
        vbt = kzalloc(round_up(vbt_size, 4), GFP_KERNEL);
        if (!vbt)
                goto err_not_found;