Skip to contentSkip to conversation

soc: qcom: mdt_loader: Add Upperbounds check for program header access

PATCH In review Auditya Bhattaram 2 participants 3 messages Jan 31, 2024 – Feb 2, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: qcom: mdt_loader: Add Upperbounds check for program header access

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.

---
 drivers/soc/qcom/mdt_loader.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/soc/qcom/mdt_loader.c +3 -0
index 6f177e46fa0f..fee86317ad83 100644
@@ -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

#1 lore raw
Quoted 5 lines · 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.

---

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

#2 lore raw
Quoted 11 lines · Konrad Dybcio
Quoted 5 lines · 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.

---

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