drm/i915/dmc: protect against reading random memory
Subsystems (3)
PATCH 1/1 drm/i915/dmc: protect against reading random memory
commit bc7b488b1d1c71dc4c5182206911127bc6c410d6 upstream.
While loading the DMC firmware we were double checking the headers made sense, but in no place we checked that we were actually reading memory we were supposed to. This could be wrong in case the firmware file is truncated or malformed.
Before this patch:
# ls -l /lib/firmware/i915/icl_dmc_ver1_07.bin -rw-r--r-- 1 root root 25716 Feb 1 12:26 icl_dmc_ver1_07.bin # truncate -s 25700 /lib/firmware/i915/icl_dmc_ver1_07.bin # modprobe i915 # dmesg| grep -i dmc [drm:intel_csr_ucode_init [i915]] Loading i915/icl_dmc_ver1_07.bin [drm] Finished loading DMC firmware i915/icl_dmc_ver1_07.bin (v1.7)
i.e. it loads random data. Now it fails like below:
[drm:intel_csr_ucode_init [i915]] Loading i915/icl_dmc_ver1_07.bin [drm:csr_load_work_fn [i915]] *ERROR* Truncated DMC firmware, rejecting. i915 0000:00:02.0: Failed to load DMC firmware i915/icl_dmc_ver1_07.bin. Disabling runtime power management. i915 0000:00:02.0: DMC firmware homepage: https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915
Before reading any part of the firmware file, validate the input first.
--- drivers/gpu/drm/i915/intel_csr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/gpu/drm/i915/intel_csr.c +18 -0
@@ -280,10 +280,17 @@ static uint32_t *parse_csr_fw(struct drm_i915_private *dev_priv,uint32_t i;uint32_t *dmc_payload;uint32_t required_version; +size_t fsize;if (!fw)return NULL ; + fsize =sizeof (struct intel_css_header ) + +sizeof (struct intel_package_header ) + +sizeof (struct intel_dmc_header ); +if (fsize > fw->size) + goto error_truncated; +/* Extract CSS Header information*/ css_header = (struct intel_css_header *)fw->data; if (sizeof(struct intel_css_header) !=
@@ -349,6 +356,9 @@ static uint32_t *parse_csr_fw(struct drm_i915_private *dev_priv,return NULL ; } readcount += dmc_offset; + fsize += dmc_offset; +if (fsize > fw->size) + goto error_truncated;/* Extract dmc_header information. */ dmc_header = (struct intel_dmc_header *)&fw->data[readcount];
@@ -379,6 +389,10 @@ static uint32_t *parse_csr_fw(struct drm_i915_private *dev_priv,/* fw_size is in dwords, so multiplied by 4 to convert into bytes. */ nbytes = dmc_header->fw_size *4 ; + fsize += nbytes; +if (fsize > fw->size) + goto error_truncated; +if (nbytes >CSR_MAX_FW_SIZE ) {DRM_ERROR ("CSR firmware too big (%u) bytes\n" , nbytes);return NULL ;
@@ -392,6 +406,10 @@ static uint32_t *parse_csr_fw(struct drm_i915_private *dev_priv, }return memcpy (dmc_payload, &fw->data[readcount], nbytes); + +error_truncated: +DRM_ERROR ("Truncated DMC firmware, rejecting.\n" ); +return NULL ; }static void csr_load_work_fn (struct work_struct *work)
Signature · 1 line
2.21.0
Patchwork
CI✗ Fi.CI.BAT: failure for drm/i915/dmc: protect against reading random memory (rev2)
== Series Details ==
== Series Details ==
Series: drm/i915/dmc: protect against reading random memory (rev2)
URL : https://patchwork.freedesktop.org/series/61695/
State : failure
== Summary ==
Applying: drm/i915/dmc: protect against reading random memory Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/intel_csr.c
Falling back to patching base and 3-way merge... Auto-merging drivers/gpu/drm/i915/intel_csr.c
CONFLICT (content): Merge conflict in drivers/gpu/drm/i915/intel_csr.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch' to see the failed patch Patch failed at 0001 drm/i915/dmc: protect against reading random memory When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 24 lines · Lucas De Marchi
commit
bc7b488b1d1c71dc4c5182206911127bc6c410d6upstream.While loading the DMC firmware we were double checking the headers made sense, but in no place we checked that we were actually reading memory we were supposed to. This could be wrong in case the firmware file is truncated or malformed.
Before this patch:
# ls -l /lib/firmware/i915/icl_dmc_ver1_07.bin -rw-r--r-- 1 root root 25716 Feb 1 12:26 icl_dmc_ver1_07.bin # truncate -s 25700 /lib/firmware/i915/icl_dmc_ver1_07.bin # modprobe i915 # dmesg| grep -i dmc [drm:intel_csr_ucode_init [i915]] Loading i915/icl_dmc_ver1_07.bin [drm] Finished loading DMC firmware i915/icl_dmc_ver1_07.bin (v1.7)i.e. it loads random data. Now it fails like below:
[drm:intel_csr_ucode_init [i915]] Loading i915/icl_dmc_ver1_07.bin [drm:csr_load_work_fn [i915]] *ERROR* Truncated DMC firmware, rejecting. i915 0000:00:02.0: Failed to load DMC firmware i915/icl_dmc_ver1_07.bin. Disabling runtime power management. i915 0000:00:02.0: DMC firmware homepage: https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915Before reading any part of the firmware file, validate the input first.
Quoted 8 lines
Fixes eb805623d8b1 ("drm/i915/skl: Add support to load SKL CSR firmware.")Signed-off-by Lucas De Marchi <[email protected]>Reviewed-by Rodrigo Vivi <[email protected]>(cherry picked from commit bc7b488b1d1c71dc4c5182206911127bc6c410d6)Signed-off-by Jani Nikula <[email protected]>[ Lucas: backported to 4.9+ adjusting the context ]Cc [email protected] # v4.9+
What about a 4.14.y and 4.19.y backport as well? I can't take this
without those as we do not want people to upgrade and have a regression.
thanks,
greg k-h
Quoted 34 lines · Greg KH
Quoted 24 lines · Lucas De Marchi
commit
bc7b488b1d1c71dc4c5182206911127bc6c410d6upstream.While loading the DMC firmware we were double checking the headers made sense, but in no place we checked that we were actually reading memory we were supposed to. This could be wrong in case the firmware file is truncated or malformed.
Before this patch:
# ls -l /lib/firmware/i915/icl_dmc_ver1_07.bin -rw-r--r-- 1 root root 25716 Feb 1 12:26 icl_dmc_ver1_07.bin # truncate -s 25700 /lib/firmware/i915/icl_dmc_ver1_07.bin # modprobe i915 # dmesg| grep -i dmc [drm:intel_csr_ucode_init [i915]] Loading i915/icl_dmc_ver1_07.bin [drm] Finished loading DMC firmware i915/icl_dmc_ver1_07.bin (v1.7)i.e. it loads random data. Now it fails like below:
[drm:intel_csr_ucode_init [i915]] Loading i915/icl_dmc_ver1_07.bin [drm:csr_load_work_fn [i915]] *ERROR* Truncated DMC firmware, rejecting. i915 0000:00:02.0: Failed to load DMC firmware i915/icl_dmc_ver1_07.bin. Disabling runtime power management. i915 0000:00:02.0: DMC firmware homepage: https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915Before reading any part of the firmware file, validate the input first.
Quoted 8 lines
Fixes eb805623d8b1 ("drm/i915/skl: Add support to load SKL CSR firmware.")Signed-off-by Lucas De Marchi <[email protected]>Reviewed-by Rodrigo Vivi <[email protected]>(cherry picked from commit bc7b488b1d1c71dc4c5182206911127bc6c410d6)Signed-off-by Jani Nikula <[email protected]>[ Lucas: backported to 4.9+ adjusting the context ]Cc [email protected] # v4.9+
Quoted 2 lines
What about a 4.14.y and 4.19.y backport as well? I can't take this
without those as we do not want people to upgrade and have a regression.
The documentation about stable process explicitely says the meaning of the tag is 'For each "-stable" tree starting with the specified version.'. I tried to make it clear by using the '+' suffix as I saw in other commits in stable tree.
This patch applies cleanly to 4.9, 4.14 and 4.19. This commit is already applied in 5.1 as it didn't need any backport. That was the intention, let me know if that is not the proper way.
The only missing stable is 4.4, but that needs more changes to the patch.
Lucas De Marchi
Sasha Levin
maintainerQuoted 43 lines · Lucas De Marchi
Quoted 34 lines · Greg KH
Quoted 24 lines · Lucas De Marchi
commit
bc7b488b1d1c71dc4c5182206911127bc6c410d6upstream.While loading the DMC firmware we were double checking the headers made sense, but in no place we checked that we were actually reading memory we were supposed to. This could be wrong in case the firmware file is truncated or malformed.
Before this patch:
# ls -l /lib/firmware/i915/icl_dmc_ver1_07.bin -rw-r--r-- 1 root root 25716 Feb 1 12:26 icl_dmc_ver1_07.bin # truncate -s 25700 /lib/firmware/i915/icl_dmc_ver1_07.bin # modprobe i915 # dmesg| grep -i dmc [drm:intel_csr_ucode_init [i915]] Loading i915/icl_dmc_ver1_07.bin [drm] Finished loading DMC firmware i915/icl_dmc_ver1_07.bin (v1.7)i.e. it loads random data. Now it fails like below:
[drm:intel_csr_ucode_init [i915]] Loading i915/icl_dmc_ver1_07.bin [drm:csr_load_work_fn [i915]] *ERROR* Truncated DMC firmware, rejecting. i915 0000:00:02.0: Failed to load DMC firmware i915/icl_dmc_ver1_07.bin. Disabling runtime power management. i915 0000:00:02.0: DMC firmware homepage: https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915Before reading any part of the firmware file, validate the input first.
Quoted 8 lines
Fixes eb805623d8b1 ("drm/i915/skl: Add support to load SKL CSR firmware.")Signed-off-by Lucas De Marchi <[email protected]>Reviewed-by Rodrigo Vivi <[email protected]>(cherry picked from commit bc7b488b1d1c71dc4c5182206911127bc6c410d6)Signed-off-by Jani Nikula <[email protected]>[ Lucas: backported to 4.9+ adjusting the context ]Cc [email protected] # v4.9+Quoted 2 lines
What about a 4.14.y and 4.19.y backport as well? I can't take this
without those as we do not want people to upgrade and have a regression.The documentation about stable process explicitely says the meaning of the tag is 'For each "-stable" tree starting with the specified version.'. I tried to make it clear by using the '+' suffix as I saw in other commits in stable tree.
Quoted 6 lines
This patch applies cleanly to 4.9, 4.14 and 4.19. This commit is already applied in 5.1 as it didn't need any backport. That was the intention, let me know if that is not the proper way.
The only missing stable is 4.4, but that needs more changes to the patch.
This works, I've queued it up for 4.9-4.19, thank you!
--
Thanks,
Sasha
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx