Skip to contentSkip to conversation

soc: qcom: mdt_loader: Detect truncated read of segments

PATCH In review Bjorn Andersson 2 participants 2 messages Jan 7, 2021 – Apr 8, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: qcom: mdt_loader: Detect truncated read of segments

Given that no validation of how much data the firmware loader read in for a given segment truncated segment files would best case result in a hash verification failure, without any indication of what went wrong.

Improve this by validating that the firmware loader did return the amount of data requested.

Fixes 445c2410a449 ("soc: qcom: mdt_loader: Use request_firmware_into_buf()")
---
 drivers/soc/qcom/mdt_loader.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/soc/qcom/mdt_loader.c +8 -0
index 24cd193dec55..e01d18e9ad2b 100644
@@ -253,6 +253,14 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,
 				break;
 			}
 
+			if (seg_fw->size != phdr->p_filesz) {
+				dev_err(dev,
+					"failed to load segment %d from truncated file %s\n",
+					i, fw_name);
+				ret = -EINVAL;
+				break;
+			}
+
 			release_firmware(seg_fw);
 		}
 
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw

Hey Bjorn,

Thanks for the patch!

Quoted 18 lines · Bjorn Andersson

Given that no validation of how much data the firmware loader read in for a given segment truncated segment files would best case result in a hash verification failure, without any indication of what went wrong.

Improve this by validating that the firmware loader did return the amount of data requested.

Fixes 445c2410a449 ("soc: qcom: mdt_loader: Use request_firmware_into_buf()")
---
  drivers/soc/qcom/mdt_loader.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/soc/qcom/mdt_loader.c +0 -0
index 24cd193dec55..e01d18e9ad2b 100644

drivers/soc/qcom/mdt_loader.c static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, · line 261

Quoted 9 lines
drivers/soc/qcom/mdt_loader.c +6 -0
@@ -253,6 +253,14 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,
  				break;
  			}
 
+			if (seg_fw->size != phdr->p_filesz) {
+				dev_err(dev,
+					"failed to load segment %d from truncated file %s\n",
+					i, fw_name);
+				ret = -EINVAL;
+				break;

seg_fw has to be released on error condition as well. With ^^ fixed you can have my R-b.

Quoted 6 lines
drivers/soc/qcom/mdt_loader.c +2 -0
+			}
+
  			release_firmware(seg_fw);
  		}
 
Signature · 3 lines
Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc, is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project