]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
soc: qcom: mdt_loader: Actually use the e_phoff
authorBjorn Andersson <bjorn.andersson@oss.qualcomm.com>
Wed, 11 Jun 2025 02:58:30 +0000 (21:58 -0500)
committerBjorn Andersson <andersson@kernel.org>
Tue, 17 Jun 2025 03:19:53 +0000 (22:19 -0500)
Rather than relying/assuming that the tools generating the firmware
places the program headers immediately following the ELF header, use
e_phoff as intended to find the program headers.

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20250610-mdt-loader-validation-and-fixes-v2-3-f7073e9ab899@oss.qualcomm.com
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
drivers/soc/qcom/mdt_loader.c

index 52f0c8bb7c5ee9f043009a274f147128f0778151..1b4ebae458f3e0e37ce40afeaea2e0fa3568c8dd 100644 (file)
@@ -117,7 +117,7 @@ ssize_t qcom_mdt_get_size(const struct firmware *fw)
                return -EINVAL;
 
        ehdr = (struct elf32_hdr *)fw->data;
-       phdrs = (struct elf32_phdr *)(ehdr + 1);
+       phdrs = (struct elf32_phdr *)(fw->data + ehdr->e_phoff);
 
        for (i = 0; i < ehdr->e_phnum; i++) {
                phdr = &phdrs[i];
@@ -172,7 +172,7 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len,
                return ERR_PTR(-EINVAL);
 
        ehdr = (struct elf32_hdr *)fw->data;
-       phdrs = (struct elf32_phdr *)(ehdr + 1);
+       phdrs = (struct elf32_phdr *)(fw->data + ehdr->e_phoff);
 
        if (ehdr->e_phnum < 2)
                return ERR_PTR(-EINVAL);
@@ -255,7 +255,7 @@ int qcom_mdt_pas_init(struct device *dev, const struct firmware *fw,
                return -EINVAL;
 
        ehdr = (struct elf32_hdr *)fw->data;
-       phdrs = (struct elf32_phdr *)(ehdr + 1);
+       phdrs = (struct elf32_phdr *)(fw->data + ehdr->e_phoff);
 
        for (i = 0; i < ehdr->e_phnum; i++) {
                phdr = &phdrs[i];
@@ -310,7 +310,7 @@ static bool qcom_mdt_bins_are_split(const struct firmware *fw, const char *fw_na
        int i;
 
        ehdr = (struct elf32_hdr *)fw->data;
-       phdrs = (struct elf32_phdr *)(ehdr + 1);
+       phdrs = (struct elf32_phdr *)(fw->data + ehdr->e_phoff);
 
        for (i = 0; i < ehdr->e_phnum; i++) {
                /*
@@ -355,7 +355,7 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,
 
        is_split = qcom_mdt_bins_are_split(fw, fw_name);
        ehdr = (struct elf32_hdr *)fw->data;
-       phdrs = (struct elf32_phdr *)(ehdr + 1);
+       phdrs = (struct elf32_phdr *)(fw->data + ehdr->e_phoff);
 
        for (i = 0; i < ehdr->e_phnum; i++) {
                phdr = &phdrs[i];