drm/i915/dmc: protect against reading random memory
Subsystems (2)
PATCH 1/1 drm/i915/dmc: protect against reading random memory
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.
---
This has been extracted from the bigger series
https://patchwork.freedesktop.org/series/61016/ in a way that can be propagated to stable.
drivers/gpu/drm/i915/intel_csr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/gpu/drm/i915/intel_csr.c +18 -0
@@ -303,10 +303,17 @@ static u32 *parse_csr_fw(struct drm_i915_private *dev_priv,u32 dmc_offset =CSR_DEFAULT_FW_OFFSET , readcount =0 , nbytes;u32 i;u32 *dmc_payload; +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) !=
@@ -366,6 +373,9 @@ static u32 *parse_csr_fw(struct drm_i915_private *dev_priv,/* Convert dmc_offset into number of bytes. By default it is in dwords*/ dmc_offset *=4 ; 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];
@@ -397,6 +407,10 @@ static u32 *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 ("DMC FW too big (%u bytes)\n" , nbytes);return NULL ;
@@ -410,6 +424,10 @@ static u32 *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 intel_csr_runtime_pm_get (struct drm_i915_private *dev_priv)
Signature · 6 lines
2.21.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.CHECKPATCH: warning for drm/i915/dmc: protect against reading random memory
== Series Details ==
== Series Details ==
Series: drm/i915/dmc: protect against reading random memory
URL : https://patchwork.freedesktop.org/series/61695/
State : warning
== Summary ==
$ dim checkpatch origin/drm-tip 8417b00f5296 drm/i915/dmc: protect against reading random memory -:23: WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line) #23: i915 0000:00:02.0: Failed to load DMC firmware i915/icl_dmc_ver1_07.bin. Disabling runtime power management.
total: 0 errors, 1 warnings, 0 checks, 46 lines checked
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.BAT: success for drm/i915/dmc: protect against reading random memory
In reply to Lucas De Marchi== Series Details ==
== Series Details ==
Series: drm/i915/dmc: protect against reading random memory
URL : https://patchwork.freedesktop.org/series/61695/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_6199 -> Patchwork_13187
====================================================
Summary
-------
**SUCCESS**
No regressions found.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_13187/
Known issues
------------
Here are the changes found in Patchwork_13187 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@gem_ctx_create@basic-files:
- fi-icl-u2: [PASS][1] -> [INCOMPLETE][2] ([fdo#107713] / [fdo#109100])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6199/fi-icl-u2/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_13187/fi-icl-u2/igt@[email protected]
* igt@i915_pm_rpm@module-reload:
- fi-icl-dsi: [PASS][3] -> [INCOMPLETE][4] ([fdo#107713] / [fdo#108840])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6199/fi-icl-dsi/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_13187/fi-icl-dsi/igt@[email protected]
#### Possible fixes ####
* igt@debugfs_test@read_all_entries:
- fi-ilk-650: [DMESG-WARN][5] ([fdo#106387]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6199/fi-ilk-650/igt@debugfs_test@read_all_entries.html
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_13187/fi-ilk-650/igt@debugfs_test@read_all_entries.html
* igt@gem_exec_basic@basic-all:
- fi-icl-y: [INCOMPLETE][7] ([fdo#107713]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6199/fi-icl-y/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_13187/fi-icl-y/igt@[email protected]
* igt@gem_exec_reloc@basic-gtt-read-noreloc:
- fi-icl-u3: [DMESG-WARN][9] ([fdo#107724]) -> [PASS][10] +1 similar issue
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6199/fi-icl-u3/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_13187/fi-icl-u3/igt@[email protected]
#### Warnings ####
* igt@i915_pm_rpm@module-reload:
- fi-snb-2600: [SKIP][11] ([fdo#109271]) -> [INCOMPLETE][12] ([fdo#105411])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6199/fi-snb-2600/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_13187/fi-snb-2600/igt@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#105411]: https://bugs.freedesktop.org/show_bug.cgi?id=105411
[fdo#106387]: https://bugs.freedesktop.org/show_bug.cgi?id=106387
[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#107724]: https://bugs.freedesktop.org/show_bug.cgi?id=107724
[fdo#108602]: https://bugs.freedesktop.org/show_bug.cgi?id=108602
[fdo#108840]: https://bugs.freedesktop.org/show_bug.cgi?id=108840
[fdo#109100]: https://bugs.freedesktop.org/show_bug.cgi?id=109100
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
Participating hosts (51 -> 45)
------------------------------
Additional (2): fi-kbl-7500u fi-cml-u
Missing (8): fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-kbl-7560u fi-byt-clapper fi-bdw-samus fi-kbl-r
Build changes
-------------
* Linux: CI_DRM_6199 -> Patchwork_13187
CI_DRM_6199: 3c7e356549a2286539d91f191196acd734b40729 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5041: 4f2b9f5930fa33d091cf89637dc6e7f76f632a88 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_13187: 8417b00f5296d653ef19eebd87960b269ee801b8 @ git://anongit.freedesktop.org/gfx-ci/linux
== Linux commits ==
8417b00f5296 drm/i915/dmc: protect against reading random memory
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_13187/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 20 lines · Lucas De Marchi
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
Quoted 5 lines
Before reading any part of the firmware file, validate the input first.
Fixes eb805623d8b1 ("drm/i915/skl: Add support to load SKL CSR firmware.")Signed-off-by Lucas De Marchi <[email protected]>
Quoted 5 lines
---
This has been extracted from the bigger series
https://patchwork.freedesktop.org/series/61016/ in a way that can be propagated to stable.
Thanks!
Quoted 61 lines
drivers/gpu/drm/i915/intel_csr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/gpu/drm/i915/intel_csr.c +18
-0@@ -303,10 +303,17 @@ static u32 *parse_csr_fw(struct drm_i915_private *dev_priv,u32 dmc_offset =CSR_DEFAULT_FW_OFFSET , readcount =0 , nbytes;u32 i;u32 *dmc_payload; +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) !=@@ -366,6 +373,9 @@ static u32 *parse_csr_fw(struct drm_i915_private *dev_priv,/* Convert dmc_offset into number of bytes. By default it is in dwords*/ dmc_offset *=4 ; 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];@@ -397,6 +407,10 @@ static u32 *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 ("DMC FW too big (%u bytes)\n" , nbytes);return NULL ;@@ -410,6 +424,10 @@ static u32 *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 intel_csr_runtime_pm_get (struct drm_i915_private *dev_priv)Signature · 1 line
2.21.0
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 4 lines · Lucas De Marchi
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.
Random idea: Should we hash the file and store the hash in the driver? If the file gets corrupted in other ways this would prevent us feeding garbage to the dmc. Although it would then make testing firmware modifications a bit more tedious as you'd have to adjust the hash or bypass the check somehow.
Quoted 91 lines
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.
Fixes eb805623d8b1 ("drm/i915/skl: Add support to load SKL CSR firmware.")Signed-off-by Lucas De Marchi <[email protected]>---
This has been extracted from the bigger series
https://patchwork.freedesktop.org/series/61016/ in a way that can be propagated to stable.drivers/gpu/drm/i915/intel_csr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/gpu/drm/i915/intel_csr.c +18
-0@@ -303,10 +303,17 @@ static u32 *parse_csr_fw(struct drm_i915_private *dev_priv,u32 dmc_offset =CSR_DEFAULT_FW_OFFSET , readcount =0 , nbytes;u32 i;u32 *dmc_payload; +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) !=@@ -366,6 +373,9 @@ static u32 *parse_csr_fw(struct drm_i915_private *dev_priv,/* Convert dmc_offset into number of bytes. By default it is in dwords*/ dmc_offset *=4 ; 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];@@ -397,6 +407,10 @@ static u32 *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 ("DMC FW too big (%u bytes)\n" , nbytes);return NULL ;@@ -410,6 +424,10 @@ static u32 *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 intel_csr_runtime_pm_get (struct drm_i915_private *dev_priv)Signature · 6 lines
2.21.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä Intel _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx