Commit
8bb1858db453cd4250e3b633f5d2d09206024ca6
drm/i915/dmc: Harden DMC firmware payload parsing
Validate the conversion of the DMC firmware size from dwords to bytes
using check_mul_overflow() before calculating the firmware payload size.
Reject zero-length payloads and zero MMIO counts in the DMC firmware
header so malformed firmware is caught early. Also set dmc_fw_size only
after the payload allocation succeeds.
Fixes: eb805623d8b1 ("drm/i915/skl: Add support to load SKL CSR firmware.")
Cc: stable@vger.kernel.org
Assisted-by: Claude-Code:Sonnet-5
Signed-off-by: Dibin Moolakadan Subrahmanian <dibin.moolakadan.subrahmanian@intel.com>
Reviewed-by: Mitul Golani<mitulkumar.ajitkumar.golani@intel.com>
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
Link: https://patch.msgid.link/20260922133535.3180973-5-dibin.moolakadan.subrahmanian@intel.com
(cherry picked from commit efde6601a1f1daedfe3dcc2816c934ddb44e3eef)
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Dibin Moolakadan Subrahmanian <dibin.moolakadan.subrahmanian@intel.com> · 2026-09-22 13:35 UTC · committed by Joonas Lahtinen
1 file changed,
+16
−5
modified drivers/gpu/drm/i915/display/intel_dmc.c
| @@ -1120,7 +1120,7 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc, | |||
| 1120 | 1120 | } | |
| 1121 | 1121 | ||
| 1122 | 1122 | /* Cache the dmc header info. */ | |
| 1123 | - | if (mmio_count > mmio_count_max) { | |
| 1123 | + | if (!mmio_count || mmio_count > mmio_count_max) { | |
| 1124 | 1124 | drm_err(display->drm, "DMC firmware has wrong mmio count %u\n", mmio_count); | |
| 1125 | 1125 | return 0; | |
| 1126 | 1126 | } | |
| @@ -1166,13 +1166,21 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc, | |||
| 1166 | 1166 | disable_dmc_evt(display, dmc_id, dmc_info->mmioaddr[i], | |
| 1167 | 1167 | dmc_info->mmiodata[i]) ? " (disabling)" : ""); | |
| 1168 | 1168 | } | |
| 1169 | - | dmc_info->mmio_count = mmio_count; | |
| 1170 | - | dmc_info->start_mmioaddr = start_mmioaddr; | |
| 1171 | 1169 | ||
| 1172 | 1170 | rem_size -= header_len_bytes; | |
| 1173 | 1171 | ||
| 1174 | 1172 | /* fw_size is in dwords, so multiplied by 4 to convert into bytes. */ | |
| 1175 | - | payload_size = dmc_header->fw_size * 4; | |
| 1173 | + | if (check_mul_overflow(dmc_header->fw_size, 4u, &payload_size)) { | |
| 1174 | + | drm_err(display->drm, "DMC fw_size too large (%u dwords)\n", | |
| 1175 | + | dmc_header->fw_size); | |
| 1176 | + | return 0; | |
| 1177 | + | } | |
| 1178 | + | ||
| 1179 | + | if (!payload_size) { | |
| 1180 | + | drm_err(display->drm, "DMC firmware has empty payload\n"); | |
| 1181 | + | return 0; | |
| 1182 | + | } | |
| 1183 | + | ||
| 1176 | 1184 | if (rem_size < payload_size) | |
| 1177 | 1185 | goto error_truncated; | |
| 1178 | 1186 | ||
| @@ -1180,12 +1188,15 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc, | |||
| 1180 | 1188 | drm_err(display->drm, "DMC FW too big (%u bytes)\n", payload_size); | |
| 1181 | 1189 | return 0; | |
| 1182 | 1190 | } | |
| 1183 | - | dmc_info->dmc_fw_size = dmc_header->fw_size; | |
| 1184 | 1191 | ||
| 1185 | 1192 | dmc_info->payload = kmalloc(payload_size, GFP_KERNEL); | |
| 1186 | 1193 | if (!dmc_info->payload) | |
| 1187 | 1194 | return 0; | |
| 1188 | 1195 | ||
| 1196 | + | dmc_info->mmio_count = mmio_count; | |
| 1197 | + | dmc_info->start_mmioaddr = start_mmioaddr; | |
| 1198 | + | dmc_info->dmc_fw_size = dmc_header->fw_size; | |
| 1199 | + | ||
| 1189 | 1200 | payload = (u8 *)(dmc_header) + header_len_bytes; | |
| 1190 | 1201 | memcpy(dmc_info->payload, payload, payload_size); | |
| 1191 | 1202 | ||