* [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize
@ 2025-07-30 20:51 Bjorn Andersson
2025-07-30 21:13 ` Dmitry Baryshkov
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Bjorn Andersson @ 2025-07-30 20:51 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Dmitry Baryshkov
Cc: linux-arm-msm, linux-kernel, Val Packett, Neil Armstrong,
Bjorn Andersson
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: 9f9967fed9d0 ("soc: qcom: mdt_loader: Ensure we don't read past the ELF header")
Reported-by: Val Packett <val@packett.cool>
Closes: https://lore.kernel.org/all/ece307c3-7d65-440f-babd-88cf9705b908@packett.cool/
Reported-by: Neil Armstrong <neil.armstrong@linaro.org>
Closes: https://lore.kernel.org/all/aec9cd03-6fc2-4dc8-b937-8b7cf7bf4128@linaro.org/
Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
---
drivers/soc/qcom/mdt_loader.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
index 0ca268bdf1f8c579b36a04fd94417be172fc1099..5710ac0c07a8c8a56110e3fc5e30b8610e106449 100644
--- a/drivers/soc/qcom/mdt_loader.c
+++ b/drivers/soc/qcom/mdt_loader.c
@@ -39,12 +39,14 @@ static bool mdt_header_valid(const struct firmware *fw)
if (phend > fw->size)
return false;
- if (ehdr->e_shentsize != sizeof(struct elf32_shdr))
- return false;
+ if (ehdr->e_shentsize || ehdr->e_shnum) {
+ if (ehdr->e_shentsize != sizeof(struct elf32_shdr))
+ return false;
- shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff);
- if (shend > fw->size)
- return false;
+ shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff);
+ if (shend > fw->size)
+ return false;
+ }
return true;
}
---
base-commit: 79fb37f39b77bbf9a56304e9af843cd93a7a1916
change-id: 20250730-mdt-loader-shentsize-zero-8c99653b6343
Best regards,
--
Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize
2025-07-30 20:51 [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize Bjorn Andersson
@ 2025-07-30 21:13 ` Dmitry Baryshkov
2025-07-31 14:58 ` Neil Armstrong
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Dmitry Baryshkov @ 2025-07-30 21:13 UTC (permalink / raw)
To: Bjorn Andersson
Cc: Bjorn Andersson, Konrad Dybcio, linux-arm-msm, linux-kernel,
Val Packett, Neil Armstrong
On Wed, Jul 30, 2025 at 03:51:51PM -0500, Bjorn Andersson wrote:
> 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: 9f9967fed9d0 ("soc: qcom: mdt_loader: Ensure we don't read past the ELF header")
> Reported-by: Val Packett <val@packett.cool>
> Closes: https://lore.kernel.org/all/ece307c3-7d65-440f-babd-88cf9705b908@packett.cool/
> Reported-by: Neil Armstrong <neil.armstrong@linaro.org>
> Closes: https://lore.kernel.org/all/aec9cd03-6fc2-4dc8-b937-8b7cf7bf4128@linaro.org/
> Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
> ---
> drivers/soc/qcom/mdt_loader.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize
2025-07-30 20:51 [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize Bjorn Andersson
2025-07-30 21:13 ` Dmitry Baryshkov
@ 2025-07-31 14:58 ` Neil Armstrong
2025-07-31 20:23 ` Dmitry Baryshkov
2025-08-11 9:23 ` Neil Armstrong
2025-08-11 14:57 ` Bjorn Andersson
3 siblings, 1 reply; 7+ messages in thread
From: Neil Armstrong @ 2025-07-31 14:58 UTC (permalink / raw)
To: Bjorn Andersson, Bjorn Andersson, Konrad Dybcio, Dmitry Baryshkov
Cc: linux-arm-msm, linux-kernel, Val Packett
On 30/07/2025 22:51, Bjorn Andersson wrote:
> 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.
>
Missing:
Fixes: 9f35ab0e53cc ("soc: qcom: mdt_loader: Fix error return values in mdt_header_valid()")
Or it won't apply on stable kernels
> Fixes: 9f9967fed9d0 ("soc: qcom: mdt_loader: Ensure we don't read past the ELF header")
> Reported-by: Val Packett <val@packett.cool>
> Closes: https://lore.kernel.org/all/ece307c3-7d65-440f-babd-88cf9705b908@packett.cool/
> Reported-by: Neil Armstrong <neil.armstrong@linaro.org>
> Closes: https://lore.kernel.org/all/aec9cd03-6fc2-4dc8-b937-8b7cf7bf4128@linaro.org/
> Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
> ---
> drivers/soc/qcom/mdt_loader.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
> index 0ca268bdf1f8c579b36a04fd94417be172fc1099..5710ac0c07a8c8a56110e3fc5e30b8610e106449 100644
> --- a/drivers/soc/qcom/mdt_loader.c
> +++ b/drivers/soc/qcom/mdt_loader.c
> @@ -39,12 +39,14 @@ static bool mdt_header_valid(const struct firmware *fw)
> if (phend > fw->size)
> return false;
>
> - if (ehdr->e_shentsize != sizeof(struct elf32_shdr))
> - return false;
> + if (ehdr->e_shentsize || ehdr->e_shnum) {
> + if (ehdr->e_shentsize != sizeof(struct elf32_shdr))
> + return false;
>
> - shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff);
> - if (shend > fw->size)
> - return false;
> + shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff);
> + if (shend > fw->size)
> + return false;
> + }
>
> return true;
> }
>
> ---
> base-commit: 79fb37f39b77bbf9a56304e9af843cd93a7a1916
> change-id: 20250730-mdt-loader-shentsize-zero-8c99653b6343
>
> Best regards,
Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8650-QRD
Thanks,
Neil
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize
2025-07-31 14:58 ` Neil Armstrong
@ 2025-07-31 20:23 ` Dmitry Baryshkov
2025-08-06 1:51 ` Bjorn Andersson
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Baryshkov @ 2025-07-31 20:23 UTC (permalink / raw)
To: Neil Armstrong
Cc: Bjorn Andersson, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
linux-kernel, Val Packett
On Thu, Jul 31, 2025 at 04:58:09PM +0200, Neil Armstrong wrote:
> On 30/07/2025 22:51, Bjorn Andersson wrote:
> > 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.
> >
> Missing:
> Fixes: 9f35ab0e53cc ("soc: qcom: mdt_loader: Fix error return values in mdt_header_valid()")
>
> Or it won't apply on stable kernels
Then it should also be:
Cc: stable@vger.kernel.org
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize
2025-07-31 20:23 ` Dmitry Baryshkov
@ 2025-08-06 1:51 ` Bjorn Andersson
0 siblings, 0 replies; 7+ messages in thread
From: Bjorn Andersson @ 2025-08-06 1:51 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Neil Armstrong, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
linux-kernel, Val Packett
On Thu, Jul 31, 2025 at 11:23:25PM +0300, Dmitry Baryshkov wrote:
> On Thu, Jul 31, 2025 at 04:58:09PM +0200, Neil Armstrong wrote:
> > On 30/07/2025 22:51, Bjorn Andersson wrote:
> > > 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.
> > >
> > Missing:
> > Fixes: 9f35ab0e53cc ("soc: qcom: mdt_loader: Fix error return values in mdt_header_valid()")
> >
> > Or it won't apply on stable kernels
>
> Then it should also be:
>
> Cc: stable@vger.kernel.org
>
Given that the fixed commit is Cc: stable, it makes sense to include
both.
Thanks,
Bjorn
>
> --
> With best wishes
> Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize
2025-07-30 20:51 [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize Bjorn Andersson
2025-07-30 21:13 ` Dmitry Baryshkov
2025-07-31 14:58 ` Neil Armstrong
@ 2025-08-11 9:23 ` Neil Armstrong
2025-08-11 14:57 ` Bjorn Andersson
3 siblings, 0 replies; 7+ messages in thread
From: Neil Armstrong @ 2025-08-11 9:23 UTC (permalink / raw)
To: Bjorn Andersson, Bjorn Andersson, Konrad Dybcio, Dmitry Baryshkov
Cc: linux-arm-msm, linux-kernel, Val Packett
On 30/07/2025 22:51, Bjorn Andersson wrote:
> 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: 9f9967fed9d0 ("soc: qcom: mdt_loader: Ensure we don't read past the ELF header")
> Reported-by: Val Packett <val@packett.cool>
> Closes: https://lore.kernel.org/all/ece307c3-7d65-440f-babd-88cf9705b908@packett.cool/
> Reported-by: Neil Armstrong <neil.armstrong@linaro.org>
> Closes: https://lore.kernel.org/all/aec9cd03-6fc2-4dc8-b937-8b7cf7bf4128@linaro.org/
> Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
> ---
> drivers/soc/qcom/mdt_loader.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
The issue solved by this fix is still present on v6.17-rc1, even if we reported
a breakage over -next on the 22th of July.
Neil
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize
2025-07-30 20:51 [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize Bjorn Andersson
` (2 preceding siblings ...)
2025-08-11 9:23 ` Neil Armstrong
@ 2025-08-11 14:57 ` Bjorn Andersson
3 siblings, 0 replies; 7+ messages in thread
From: Bjorn Andersson @ 2025-08-11 14:57 UTC (permalink / raw)
To: Konrad Dybcio, Dmitry Baryshkov, Bjorn Andersson
Cc: linux-arm-msm, linux-kernel, Val Packett, Neil Armstrong
On Wed, 30 Jul 2025 15:51:51 -0500, Bjorn Andersson wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] soc: qcom: mdt_loader: Deal with zero e_shentsize
commit: 25daf9af0ac1bf12490b723b5efaf8dcc85980bc
Best regards,
--
Bjorn Andersson <andersson@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-08-11 14:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-30 20:51 [PATCH] soc: qcom: mdt_loader: Deal with zero e_shentsize Bjorn Andersson
2025-07-30 21:13 ` Dmitry Baryshkov
2025-07-31 14:58 ` Neil Armstrong
2025-07-31 20:23 ` Dmitry Baryshkov
2025-08-06 1:51 ` Bjorn Andersson
2025-08-11 9:23 ` Neil Armstrong
2025-08-11 14:57 ` Bjorn Andersson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®