Skip to contentSkip to conversation

lib: utils: fdt_fixup: avoid buffer overrun

PATCH New Heinrich Schuchardt 3 participants 3 messages Mar 31, 2023 – Apr 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib: utils: fdt_fixup: avoid buffer overrun

fdt_reserved_memory_fixup() uses filtered_order[PMP_COUNT]. The index must not reach PMP_COUNT.

Fixes 199189bd1c17 ("lib: utils: Mark only the largest region as reserved in FDT")

Addresses-Coverity-ID: 1536994 ("Out-of-bounds write")

---
v2:
fix typo in commit message

---
 lib/utils/fdt/fdt_fixup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_fixup.c +1 -1
index c10179b..ae6be00 100644
@@ -355,7 +355,7 @@ int fdt_reserved_memory_fixup(void *fdt)
 		if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
 			continue;
 
-		if (i > PMP_COUNT) {
+		if (i >= PMP_COUNT) {
 			sbi_printf("%s: Too many memory regions to fixup.\n",
 				   __func__);
 			return SBI_ENOSPC;
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 1/1 lib: utils: fdt_fixup: avoid buffer overrun

? 2023-03-31???? 15:15 +0200?Heinrich Schuchardt???

Quoted 6 lines

fdt_reserved_memory_fixup() uses filtered_order[PMP_COUNT]. The index must not reach PMP_COUNT.

Fixes 199189bd1c17 ("lib: utils: Mark only the largest region as reserved in FDT")

Addresses-Coverity-ID: 1536994 ("Out-of-bounds write")

LGTM

Quoted 24 lines

---
v2:
????????fix typo in commit message
---
?lib/utils/fdt/fdt_fixup.c | 2 +-
?1 file changed, 1 insertion(+), 1 deletion(-)

lib/utils/fdt/fdt_fixup.c +0 -0
index c10179b..ae6be00 100644
@@ -355,7 +355,7 @@ int fdt_reserved_memory_fixup(void *fdt)
 ????????????????if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
 ????????????????????????continue;

?
-???????????????if (i > PMP_COUNT) {
+???????????????if (i >= PMP_COUNT) { ????????????????????????sbi_printf("%s: Too many memory regions to fixup.\n", ?????????????????????????????????? __func__); ????????????????????????return SBI_ENOSPC;

Signature · 1 line
2.39.2
Applied
#2 lore raw

PATCH v2 1/1 lib: utils: fdt_fixup: avoid buffer overrun

In reply to Heinrich Schuchardt
Quoted 7 lines · On Fri, Mar 31, 2023 at 6:45?PM Heinrich Schuchardt…

fdt_reserved_memory_fixup() uses filtered_order[PMP_COUNT]. The index must not reach PMP_COUNT.

Fixes 199189bd1c17 ("lib: utils: Mark only the largest region as reserved in FDT")

Addresses-Coverity-ID: 1536994 ("Out-of-bounds write")

Looks good to me.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 23 lines

---
v2:
fix typo in commit message

---
 lib/utils/fdt/fdt_fixup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_fixup.c +1 -2
index c10179b..ae6be00 100644
@@ -355,7 +355,7 @@ int fdt_reserved_memory_fixup(void *fdt)
                if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
                        continue;
 
-               if (i > PMP_COUNT) {
+               if (i >= PMP_COUNT) {
                        sbi_printf("%s: Too many memory regions to fixup.\n",
                                   __func__);
                        return SBI_ENOSPC;
--

2.39.2