soc: qcom: mdt_loader: Detect truncated read of segments
authorBjorn Andersson <bjorn.andersson@linaro.org>
Thu, 7 Jan 2021 23:25:26 +0000 (15:25 -0800)
committerBjorn Andersson <bjorn.andersson@linaro.org>
Thu, 8 Apr 2021 15:28:59 +0000 (10:28 -0500)
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()")
Reviewed-by: Sibi Sankar <sibis@codeaurora.org>
Link: https://lore.kernel.org/r/20210107232526.716989-1-bjorn.andersson@linaro.org
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
drivers/soc/qcom/mdt_loader.c

index 2ddaee5..eba7f76 100644 (file)
@@ -261,6 +261,15 @@ 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);
+                               release_firmware(seg_fw);
+                               ret = -EINVAL;
+                               break;
+                       }
+
                        release_firmware(seg_fw);
                }