linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soc: qcom: mdt_loader: Allow empty section headers in mdt_header_valid()
       [not found] <cover.1754385120.git.dan.carpenter@linaro.org>
@ 2025-08-05  9:29 ` Dan Carpenter
  2025-08-05  9:53   ` Dmitry Baryshkov
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2025-08-05  9:29 UTC (permalink / raw)
  To: Val Packett; +Cc: Bjorn Andersson, Konrad Dybcio, linux-arm-msm, linux-kernel

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.

Fixes: 9f35ab0e53cc ("soc: qcom: mdt_loader: Fix error return values in mdt_header_valid()")
Cc: stable@vger.kernel.org
Reported-by: Val Packett <val@packett.cool>
Reported-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/soc/qcom/mdt_loader.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
index 0ca268bdf1f8..d91c5cb325e3 100644
--- a/drivers/soc/qcom/mdt_loader.c
+++ b/drivers/soc/qcom/mdt_loader.c
@@ -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);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] soc: qcom: mdt_loader: Allow empty section headers in mdt_header_valid()
  2025-08-05  9:29 ` Dan Carpenter
@ 2025-08-05  9:53   ` Dmitry Baryshkov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Baryshkov @ 2025-08-05  9:53 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Val Packett, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-kernel

On Tue, Aug 05, 2025 at 12:29:00PM +0300, Dan Carpenter wrote:
> 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.
> 
> Fixes: 9f35ab0e53cc ("soc: qcom: mdt_loader: Fix error return values in mdt_header_valid()")
> Cc: stable@vger.kernel.org
> Reported-by: Val Packett <val@packett.cool>
> Reported-by: Neil Armstrong <neil.armstrong@linaro.org>
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  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/20250804-mdtloader-changes-v1-3-5e74629a2241@oss.qualcomm.com/


-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] soc: qcom: mdt_loader: Allow empty section headers in mdt_header_valid()
@ 2025-09-01 14:36 Philippe Simons
  0 siblings, 0 replies; 3+ messages in thread
From: Philippe Simons @ 2025-09-01 14:36 UTC (permalink / raw)
  To: dan.carpenter; +Cc: andersson, konradybcio, linux-arm-msm, open list, val

This fix GMU firmware issues on SM8550.

[   19.858684] [drm] Loaded GMU firmware v4.1.9
[   19.875711] msm_dpu ae01000.display-controller:
[drm:adreno_load_gpu] *ERROR* gpu hw init failed: -22
[   19.885839] platform 3d6a000.gmu: [drm:a6xx_gmu_set_oob] *ERROR*
Timeout waiting for GMU OOB set GPU_SET: 0x0
[   19.909450] platform 3d6a000.gmu: [drm:a6xx_rpmh_start] *ERROR*
Unable to power on the GPU RSC
[   19.909570] msm_dpu ae01000.display-controller:
[drm:adreno_load_gpu] *ERROR* Couldn't power up the GPU: -110

Tested-by: Simons Philippe <simons.philippe@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-01 14:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01 14:36 [PATCH] soc: qcom: mdt_loader: Allow empty section headers in mdt_header_valid() Philippe Simons
     [not found] <cover.1754385120.git.dan.carpenter@linaro.org>
2025-08-05  9:29 ` Dan Carpenter
2025-08-05  9:53   ` Dmitry Baryshkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).