aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Andersson <[email protected]>2025-07-30 20:51:51 +0000
committerBjorn Andersson <[email protected]>2025-08-11 02:02:14 +0000
commit25daf9af0ac1bf12490b723b5efaf8dcc85980bc (patch)
treee86816bf91025a4dc0775dd3dfdec78b56178bce
parentLinux 6.17-rc1 (diff)
downloadkernel-25daf9af0ac1bf12490b723b5efaf8dcc85980bc.tar.gz
kernel-25daf9af0ac1bf12490b723b5efaf8dcc85980bc.zip
soc: qcom: mdt_loader: Deal with zero e_shentsize
Firmware that doesn't provide section headers leave both e_shentsize and e_shnum 0, which obvious isn't compatible with the newly introduced stricter checks. Make the section-related checks conditional on either of these values being non-zero. Fixes: 9f9967fed9d0 ("soc: qcom: mdt_loader: Ensure we don't read past the ELF header") Reported-by: Val Packett <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Reported-by: Neil Armstrong <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Bjorn Andersson <[email protected]> Fixes: 9f35ab0e53cc ("soc: qcom: mdt_loader: Fix error return values in mdt_header_valid()") Tested-by: Neil Armstrong <[email protected]> # on SM8650-QRD Reviewed-by: Dmitry Baryshkov <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/20250730-mdt-loader-shentsize-zero-v1-1-04f43186229c@oss.qualcomm.com Signed-off-by: Bjorn Andersson <[email protected]>
-rw-r--r--drivers/soc/qcom/mdt_loader.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
index 0ca268bdf1f8..5710ac0c07a8 100644
--- a/drivers/soc/qcom/mdt_loader.c
+++ b/drivers/soc/qcom/mdt_loader.c
@@ -39,12 +39,14 @@ static bool mdt_header_valid(const struct firmware *fw)
if (phend > fw->size)
return false;
- if (ehdr->e_shentsize != sizeof(struct elf32_shdr))
- return false;
+ if (ehdr->e_shentsize || ehdr->e_shnum) {
+ if (ehdr->e_shentsize != sizeof(struct elf32_shdr))
+ return false;
- shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff);
- if (shend > fw->size)
- return false;
+ shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff);
+ if (shend > fw->size)
+ return false;
+ }
return true;
}