soc: qcom: mdt_loader: Validate that p_filesz < p_memsz
Subsystems (2)
PATCH 1/1 soc: qcom: mdt_loader: Validate that p_filesz < p_memsz
The code validates that segments of p_memsz bytes of a segment will fit in the provided memory region, but does not validate that p_filesz bytes will, which means that an incorrectly crafted ELF header might write beyond the provided memory region.
--- drivers/soc/qcom/mdt_loader.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/soc/qcom/mdt_loader.c +8 -0
@@ -230,6 +230,14 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,break ; } +if (phdr->p_filesz > phdr->p_memsz) { +dev_err (dev, +"refusing to load segment %d with p_filesz > p_memsz\n" , + i); + ret = -EINVAL ; +break ; + } + ptr = mem_region + offset;if (phdr->p_filesz && phdr->p_offset < fw->size) {
Signature · 1 line
2.29.2
Hey Bjorn,
Thanks for the patch!
Quoted 17 lines · Bjorn Andersson
The code validates that segments of
p_memszbytes of a segment will fit in the provided memory region, but does not validate thatp_fileszbytes will, which means that an incorrectly crafted ELF header might write beyond the provided memory region.Fixes 051fb70fd4ea ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5")Signed-off-by Bjorn Andersson <[email protected]>--- drivers/soc/qcom/mdt_loader.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/soc/qcom/mdt_loader.c +0
-0@@ -230,6 +230,14 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,break ;
drivers/soc/qcom/mdt_loader.c static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, · line 240
Quoted 10 lines
drivers/soc/qcom/mdt_loader.c +8
-0} +if (phdr->p_filesz > phdr->p_memsz) { +dev_err (dev, +"refusing to load segment %d with p_filesz > p_memsz\n" , + i); + ret = -EINVAL ; +break ; + } +
Quoted 4 lines
drivers/soc/qcom/mdt_loader.c +0
-0ptr = mem_region + offset;if (phdr->p_filesz && phdr->p_offset < fw->size) {
Signature · 3 lines
Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc, is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
This patch was applied to qcom/linux.git (refs/heads/for-next):
Hello:
This patch was applied to qcom/linux.git (refs/heads/for-next):
Quoted 9 lines · On Thu, 7 Jan 2021 15:31:19 -0800 you wrote:
The code validates that segments of
p_memszbytes of a segment will fit in the provided memory region, but does not validate thatp_fileszbytes will, which means that an incorrectly crafted ELF header might write beyond the provided memory region.Fixes 051fb70fd4ea ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5")Signed-off-by Bjorn Andersson <[email protected]>[...]
Here is the summary with links:
- soc: qcom: mdt_loader: Validate that p_filesz < p_memsz
https://git.kernel.org/qcom/c/84168d1b54e7
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html