Compare
b26edc925c1cfa0184cd270ed81d4833db045ce0..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
4 files changed,
+19
−8
- drivers/gpu/drm/i915/display/intel_dmc.c
- sound/soc/codecs/cs42l52.c
- sound/soc/codecs/cs42l56.c
- sound/soc/codecs/pcm3168a.c
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 | ||
modified sound/soc/codecs/cs42l52.c
| @@ -290,7 +290,7 @@ static const char * const cs42l52_ng_type_text[] = { | |||
| 290 | 290 | }; | |
| 291 | 291 | ||
| 292 | 292 | static SOC_ENUM_SINGLE_DECL(ng_type_enum, | |
| 293 | - | CS42L52_NOISE_GATE_CTL, 7, | |
| 293 | + | CS42L52_NOISE_GATE_CTL, 6, | |
| 294 | 294 | cs42l52_ng_type_text); | |
| 295 | 295 | ||
| 296 | 296 | static const char * const left_swap_text[] = { | |
modified sound/soc/codecs/cs42l56.c
| @@ -481,7 +481,7 @@ static const struct snd_kcontrol_new cs42l56_snd_controls[] = { | |||
| 481 | 481 | 0, 0x3f, 0, 0), | |
| 482 | 482 | SOC_SINGLE_TLV("Limiter MAX", CS42L56_LIM_THRESHOLD_CTL, | |
| 483 | 483 | 5, 0x07, 1, alc_tlv), | |
| 484 | - | SOC_SINGLE_TLV("Limiter Cushion", CS42L56_LIM_THRESHOLD_CTL, | |
| 484 | + | SOC_SINGLE_TLV("Limiter Cushion", CS42L56_ALC_THRESHOLD, | |
| 485 | 485 | 2, 0x07, 1, alc_tlv), | |
| 486 | 486 | ||
| 487 | 487 | SOC_SINGLE("NG Switch", CS42L56_NOISE_GATE_CTL, 6, 1, 1), | |
modified sound/soc/codecs/pcm3168a.c
| @@ -103,7 +103,7 @@ static SOC_ENUM_SINGLE_DECL(pcm3168a_dac_zf_func, PCM3168A_DAC_ATT_DEMP_ZF, | |||
| 103 | 103 | static const char *const pcm3168a_pol[] = { "Active High", "Active Low" }; | |
| 104 | 104 | ||
| 105 | 105 | static SOC_ENUM_SINGLE_DECL(pcm3168a_dac_zf_pol, PCM3168A_DAC_ATT_DEMP_ZF, | |
| 106 | - | PCM3168A_DAC_ZREV_SHIFT, pcm3168a_pol); | |
| 106 | + | PCM3168A_DAC_ATSPDA_SHIFT, pcm3168a_pol); | |
| 107 | 107 | ||
| 108 | 108 | static const char *const pcm3168a_con[] = { "Differential", "Single-Ended" }; | |
| 109 | 109 | ||