Skip to content

Commit 25daf9a

Browse files
quic-bjorandeandersson
authored andcommitted
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: 9f9967f ("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: 9f35ab0 ("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]>
1 parent 8f5ae30 commit 25daf9a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/soc/qcom/mdt_loader.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ static bool mdt_header_valid(const struct firmware *fw)
3939
if (phend > fw->size)
4040
return false;
4141

42-
if (ehdr->e_shentsize != sizeof(struct elf32_shdr))
43-
return false;
42+
if (ehdr->e_shentsize || ehdr->e_shnum) {
43+
if (ehdr->e_shentsize != sizeof(struct elf32_shdr))
44+
return false;
4445

45-
shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff);
46-
if (shend > fw->size)
47-
return false;
46+
shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff);
47+
if (shend > fw->size)
48+
return false;
49+
}
4850

4951
return true;
5052
}

0 commit comments

Comments
 (0)