soc: qcom: mdt_loader: Allow empty section headers in mdt_header_valid()
Subsystems (2)
PATCH 1/1 soc: qcom: mdt_loader: Allow empty section headers in mdt_header_valid()
In reply to a message not in the archiveThe mdt_header_valid() function checks all the members for the elf header to ensure that reading the firmware doesn't lead to a buffer overflow or an integer overflow. However it has a bug, in that it doesn't allow for firmware with no section headers and this prevents the firmware from loading.
I know from bug reports that there are firmwares which have zero section headers, but the same logic applies to program headers. An empty program header won't lead to a buffer overflow so it's safe to allow it.
--- drivers/soc/qcom/mdt_loader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/qcom/mdt_loader.c +2 -2
@@ -32,14 +32,14 @@ static bool mdt_header_valid(const struct firmware *fw)if (memcmp (ehdr->e_ident,ELFMAG ,SELFMAG ))return false; -if (ehdr->e_phentsize !=sizeof (struct elf32_phdr )) +if (ehdr->e_phentsize && ehdr->e_phentsize !=sizeof (struct elf32_phdr ))return false; phend =size_add (size_mul (sizeof (struct elf32_phdr ), ehdr->e_phnum), ehdr->e_phoff);if (phend > fw->size)return false; -if (ehdr->e_shentsize !=sizeof (struct elf32_shdr )) +if (ehdr->e_shentsize && ehdr->e_shentsize !=sizeof (struct elf32_shdr ))return false; shend =size_add (size_mul (sizeof (struct elf32_shdr ), ehdr->e_shnum), ehdr->e_shoff);
Signature · 1 line
2.47.2
Quoted 11 lines · Dan Carpenter
The
mdt_header_valid()function checks all the members for the elf header to ensure that reading the firmware doesn't lead to a buffer overflow or an integer overflow. However it has a bug, in that it doesn't allow for firmware with no section headers and this prevents the firmware from loading.I know from bug reports that there are firmwares which have zero section headers, but the same logic applies to program headers. An empty program header won't lead to a buffer overflow so it's safe to allow it.
Quoted 8 lines
Fixes 9f35ab0e53cc ("soc: qcom: mdt_loader: Fix error return values in mdt_header_valid()")Reported-by Val Packett <[email protected]>Reported-by Neil Armstrong <[email protected]>Signed-off-by Dan Carpenter <[email protected]>--- drivers/soc/qcom/mdt_loader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
There was a patch posted by Mukesh: [1]
[1] https://lore.kernel.org/linux-arm-msm/[email protected]/
Signature · 2 lines
With best wishes Dmitry