Compare
b26edc925c1cfa0184cd270ed81d4833db045ce0..7dedc5bb11f95e96fe80757c924d8d9aa7327759
drm/i915/dmc: Add sanity check for DMC load address
For DMC firmware header version 3, the firmware load address is stored
in dmc_info->start_mmioaddr and later used by dmc_load_program().
Unlike the MMIO address table, the firmware load address is not
validated. Add a sanity check to ensure it is within the valid range.
BSpec: 69671, 68378
Fixes: 3d5928a168a9 ("drm/i915/xelpd: Pipe A DMC plugging")
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-6-dibin.moolakadan.subrahmanian@intel.com
(cherry picked from commit 5e47ee5c76ca9becde8df4ad5202845b7ffcbc4c)
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
5 files changed,
+86
−8
- drivers/gpu/drm/i915/display/intel_dmc.c
- drivers/gpu/drm/i915/display/intel_dmc_regs.h
- sound/soc/codecs/cs42l52.c
- sound/soc/codecs/cs42l56.c
- sound/soc/codecs/pcm3168a.c
modified drivers/gpu/drm/i915/display/intel_dmc.c
| @@ -1023,6 +1023,55 @@ static void dmc_set_fw_offset(struct intel_dmc *dmc, | |||
| 1023 | 1023 | } | |
| 1024 | 1024 | } | |
| 1025 | 1025 | ||
| 1026 | + | /* | |
| 1027 | + | * Check if the load address is within the valid range for the given DMC ID. | |
| 1028 | + | */ | |
| 1029 | + | static bool dmc_load_addr_sanity_check(struct intel_dmc *dmc, | |
| 1030 | + | u32 start_addr, u32 payload_size, | |
| 1031 | + | int header_ver, enum intel_dmc_id dmc_id) | |
| 1032 | + | { | |
| 1033 | + | u32 start_range, end_range, end_addr; | |
| 1034 | + | ||
| 1035 | + | if (header_ver != 3) | |
| 1036 | + | return true; | |
| 1037 | + | ||
| 1038 | + | switch (dmc_id) { | |
| 1039 | + | case DMC_FW_MAIN: | |
| 1040 | + | start_range = DMC_MAIN_PROGRAM_BASE_START; | |
| 1041 | + | end_range = DMC_MAIN_PROGRAM_BASE_END; | |
| 1042 | + | break; | |
| 1043 | + | case DMC_FW_PIPEA: | |
| 1044 | + | start_range = DMC_PIPEA_PROGRAM_BASE_START; | |
| 1045 | + | end_range = DMC_PIPEA_PROGRAM_BASE_END; | |
| 1046 | + | break; | |
| 1047 | + | case DMC_FW_PIPEB: | |
| 1048 | + | start_range = DMC_PIPEB_PROGRAM_BASE_START; | |
| 1049 | + | end_range = DMC_PIPEB_PROGRAM_BASE_END; | |
| 1050 | + | break; | |
| 1051 | + | case DMC_FW_PIPEC: | |
| 1052 | + | start_range = DMC_PIPEC_PROGRAM_BASE_START; | |
| 1053 | + | end_range = DMC_PIPEC_PROGRAM_BASE_END; | |
| 1054 | + | break; | |
| 1055 | + | case DMC_FW_PIPED: | |
| 1056 | + | start_range = DMC_PIPED_PROGRAM_BASE_START; | |
| 1057 | + | end_range = DMC_PIPED_PROGRAM_BASE_END; | |
| 1058 | + | break; | |
| 1059 | + | default: | |
| 1060 | + | MISSING_CASE(dmc_id); | |
| 1061 | + | return false; | |
| 1062 | + | } | |
| 1063 | + | ||
| 1064 | + | if (payload_size == 0) | |
| 1065 | + | end_addr = start_addr; | |
| 1066 | + | else if (check_add_overflow(start_addr, payload_size - 1, &end_addr)) | |
| 1067 | + | return false; | |
| 1068 | + | ||
| 1069 | + | if (start_addr < start_range || end_addr > end_range) | |
| 1070 | + | return false; | |
| 1071 | + | ||
| 1072 | + | return true; | |
| 1073 | + | } | |
| 1074 | + | ||
| 1026 | 1075 | static bool dmc_mmio_addr_sanity_check(struct intel_dmc *dmc, | |
| 1027 | 1076 | const u32 *mmioaddr, u32 mmio_count, | |
| 1028 | 1077 | int header_ver, enum intel_dmc_id dmc_id) | |
| @@ -1120,7 +1169,7 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc, | |||
| 1120 | 1169 | } | |
| 1121 | 1170 | ||
| 1122 | 1171 | /* Cache the dmc header info. */ | |
| 1123 | - | if (mmio_count > mmio_count_max) { | |
| 1172 | + | if (!mmio_count || mmio_count > mmio_count_max) { | |
| 1124 | 1173 | drm_err(display->drm, "DMC firmware has wrong mmio count %u\n", mmio_count); | |
| 1125 | 1174 | return 0; | |
| 1126 | 1175 | } | |
| @@ -1166,13 +1215,21 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc, | |||
| 1166 | 1215 | disable_dmc_evt(display, dmc_id, dmc_info->mmioaddr[i], | |
| 1167 | 1216 | dmc_info->mmiodata[i]) ? " (disabling)" : ""); | |
| 1168 | 1217 | } | |
| 1169 | - | dmc_info->mmio_count = mmio_count; | |
| 1170 | - | dmc_info->start_mmioaddr = start_mmioaddr; | |
| 1171 | 1218 | ||
| 1172 | 1219 | rem_size -= header_len_bytes; | |
| 1173 | 1220 | ||
| 1174 | 1221 | /* fw_size is in dwords, so multiplied by 4 to convert into bytes. */ | |
| 1175 | - | payload_size = dmc_header->fw_size * 4; | |
| 1222 | + | if (check_mul_overflow(dmc_header->fw_size, 4u, &payload_size)) { | |
| 1223 | + | drm_err(display->drm, "DMC fw_size too large (%u dwords)\n", | |
| 1224 | + | dmc_header->fw_size); | |
| 1225 | + | return 0; | |
| 1226 | + | } | |
| 1227 | + | ||
| 1228 | + | if (!payload_size) { | |
| 1229 | + | drm_err(display->drm, "DMC firmware has empty payload\n"); | |
| 1230 | + | return 0; | |
| 1231 | + | } | |
| 1232 | + | ||
| 1176 | 1233 | if (rem_size < payload_size) | |
| 1177 | 1234 | goto error_truncated; | |
| 1178 | 1235 | ||
| @@ -1180,12 +1237,21 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc, | |||
| 1180 | 1237 | drm_err(display->drm, "DMC FW too big (%u bytes)\n", payload_size); | |
| 1181 | 1238 | return 0; | |
| 1182 | 1239 | } | |
| 1183 | - | dmc_info->dmc_fw_size = dmc_header->fw_size; | |
| 1240 | + | ||
| 1241 | + | if (!dmc_load_addr_sanity_check(dmc, start_mmioaddr, payload_size, | |
| 1242 | + | dmc_header->header_ver, dmc_id)) { | |
| 1243 | + | drm_err(display->drm, "DMC %d: firmware has wrong load address\n", dmc_id); | |
| 1244 | + | return 0; | |
| 1245 | + | } | |
| 1184 | 1246 | ||
| 1185 | 1247 | dmc_info->payload = kmalloc(payload_size, GFP_KERNEL); | |
| 1186 | 1248 | if (!dmc_info->payload) | |
| 1187 | 1249 | return 0; | |
| 1188 | 1250 | ||
| 1251 | + | dmc_info->mmio_count = mmio_count; | |
| 1252 | + | dmc_info->start_mmioaddr = start_mmioaddr; | |
| 1253 | + | dmc_info->dmc_fw_size = dmc_header->fw_size; | |
| 1254 | + | ||
| 1189 | 1255 | payload = (u8 *)(dmc_header) + header_len_bytes; | |
| 1190 | 1256 | memcpy(dmc_info->payload, payload, payload_size); | |
| 1191 | 1257 | ||
modified drivers/gpu/drm/i915/display/intel_dmc_regs.h
| @@ -521,6 +521,18 @@ enum pipedmc_event_id { | |||
| 521 | 521 | #define TGL_PIPE_MMIO_END(dmc_id) _PICK_EVEN(((dmc_id) - 1), _TGL_PIPEA_MMIO_END,\ | |
| 522 | 522 | _TGL_PIPEB_MMIO_END) | |
| 523 | 523 | ||
| 524 | + | /* For DMC header version v3*/ | |
| 525 | + | #define DMC_MAIN_PROGRAM_BASE_START 0x80000 | |
| 526 | + | #define DMC_MAIN_PROGRAM_BASE_END 0x86fff | |
| 527 | + | #define DMC_PIPEA_PROGRAM_BASE_START 0x90000 | |
| 528 | + | #define DMC_PIPEA_PROGRAM_BASE_END 0x96fff | |
| 529 | + | #define DMC_PIPEB_PROGRAM_BASE_START 0x98000 | |
| 530 | + | #define DMC_PIPEB_PROGRAM_BASE_END 0x9efff | |
| 531 | + | #define DMC_PIPEC_PROGRAM_BASE_START 0x52000 | |
| 532 | + | #define DMC_PIPEC_PROGRAM_BASE_END 0x53fff | |
| 533 | + | #define DMC_PIPED_PROGRAM_BASE_START 0x59000 | |
| 534 | + | #define DMC_PIPED_PROGRAM_BASE_END 0x5afff | |
| 535 | + | ||
| 524 | 536 | #define SKL_DMC_DC3_DC5_COUNT _MMIO(0x80030) | |
| 525 | 537 | #define SKL_DMC_DC5_DC6_COUNT _MMIO(0x8002C) | |
| 526 | 538 | #define BXT_DMC_DC3_DC5_COUNT _MMIO(0x80038) | |
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 | ||