* [PATCH] soc: qcom: mdt_loader: Add Upperbounds check for program header access
@ 2024-01-31 9:42 Auditya Bhattaram
2024-02-01 14:50 ` Konrad Dybcio
0 siblings, 1 reply; 3+ messages in thread
From: Auditya Bhattaram @ 2024-01-31 9:42 UTC (permalink / raw)
To: andersson, konrad.dybcio; +Cc: linux-arm-msm, linux-kernel, Auditya Bhattaram
hash_index is evaluated by looping phdrs till QCOM_MDT_TYPE_HASH
is found. Add an upperbound check to phdrs to access within elf size.
Signed-off-by: Auditya Bhattaram <quic_audityab@quicinc.com>
---
drivers/soc/qcom/mdt_loader.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
index 6f177e46fa0f..fee86317ad83 100644
--- a/drivers/soc/qcom/mdt_loader.c
+++ b/drivers/soc/qcom/mdt_loader.c
@@ -145,6 +145,9 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len,
if (phdrs[0].p_type == PT_LOAD)
return ERR_PTR(-EINVAL);
+ if (((size_t)(phdrs + ehdr->e_phnum)) > ((size_t)ehdr + fw->size))
+ return ERR_PTR(-EINVAL);
+
for (i = 1; i < ehdr->e_phnum; i++) {
if ((phdrs[i].p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH) {
hash_segment = i;
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] soc: qcom: mdt_loader: Add Upperbounds check for program header access
2024-01-31 9:42 [PATCH] soc: qcom: mdt_loader: Add Upperbounds check for program header access Auditya Bhattaram
@ 2024-02-01 14:50 ` Konrad Dybcio
2024-02-02 6:37 ` Auditya Bhattaram
0 siblings, 1 reply; 3+ messages in thread
From: Konrad Dybcio @ 2024-02-01 14:50 UTC (permalink / raw)
To: Auditya Bhattaram, andersson; +Cc: linux-arm-msm, linux-kernel
On 31.01.2024 10:42, Auditya Bhattaram wrote:
> hash_index is evaluated by looping phdrs till QCOM_MDT_TYPE_HASH
> is found. Add an upperbound check to phdrs to access within elf size.
>
> Signed-off-by: Auditya Bhattaram <quic_audityab@quicinc.com>
> ---
Could you print an error when this happens? There's a lot of EINVALs
in the MDT loader codepaths, but you never know which one fired..
Konrad
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] soc: qcom: mdt_loader: Add Upperbounds check for program header access
2024-02-01 14:50 ` Konrad Dybcio
@ 2024-02-02 6:37 ` Auditya Bhattaram
0 siblings, 0 replies; 3+ messages in thread
From: Auditya Bhattaram @ 2024-02-02 6:37 UTC (permalink / raw)
To: Konrad Dybcio, andersson; +Cc: linux-arm-msm, linux-kernel
On 2/1/2024 8:20 PM, Konrad Dybcio wrote:
> On 31.01.2024 10:42, Auditya Bhattaram wrote:
>> hash_index is evaluated by looping phdrs till QCOM_MDT_TYPE_HASH
>> is found. Add an upperbound check to phdrs to access within elf size.
>>
>> Signed-off-by: Auditya Bhattaram <quic_audityab@quicinc.com>
>> ---
>
> Could you print an error when this happens? There's a lot of EINVALs
> in the MDT loader codepaths, but you never know which one fired..
>
> Konrad
Sure, will add error prints
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-02 6:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-31 9:42 [PATCH] soc: qcom: mdt_loader: Add Upperbounds check for program header access Auditya Bhattaram
2024-02-01 14:50 ` Konrad Dybcio
2024-02-02 6:37 ` Auditya Bhattaram
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®