[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 12/19] contrib/elf2dmp: Ensure segment fits in file
From: |
Akihiko Odaki |
Subject: |
[PATCH v3 12/19] contrib/elf2dmp: Ensure segment fits in file |
Date: |
Wed, 06 Mar 2024 15:12:18 +0900 |
This makes elf2dmp more robust against corrupted inputs.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
contrib/elf2dmp/addrspace.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c
index e01860d15b07..81295a11534a 100644
--- a/contrib/elf2dmp/addrspace.c
+++ b/contrib/elf2dmp/addrspace.c
@@ -88,11 +88,12 @@ void pa_space_create(struct pa_space *ps, QEMU_Elf
*qemu_elf)
ps->block = g_new(struct pa_block, ps->block_nr);
for (i = 0; i < phdr_nr; i++) {
- if (phdr[i].p_type == PT_LOAD) {
+ if (phdr[i].p_type == PT_LOAD && phdr[i].p_offset < qemu_elf->size) {
ps->block[block_i] = (struct pa_block) {
.addr = (uint8_t *)qemu_elf->map + phdr[i].p_offset,
.paddr = phdr[i].p_paddr,
- .size = phdr[i].p_filesz,
+ .size = MIN(phdr[i].p_filesz,
+ qemu_elf->size - phdr[i].p_offset),
};
pa_block_align(&ps->block[block_i]);
block_i = ps->block[block_i].size ? (block_i + 1) : block_i;
--
2.44.0
- [PATCH v3 01/19] contrib/elf2dmp: Remove unnecessary err flags, (continued)
- [PATCH v3 01/19] contrib/elf2dmp: Remove unnecessary err flags, Akihiko Odaki, 2024/03/06
- [PATCH v3 03/19] contrib/elf2dmp: Continue even contexts are lacking, Akihiko Odaki, 2024/03/06
- [PATCH v3 06/19] contrib/elf2dmp: Fix error reporting style in download.c, Akihiko Odaki, 2024/03/06
- [PATCH v3 07/19] contrib/elf2dmp: Fix error reporting style in pdb.c, Akihiko Odaki, 2024/03/06
- [PATCH v3 08/19] contrib/elf2dmp: Fix error reporting style in qemu_elf.c, Akihiko Odaki, 2024/03/06
- [PATCH v3 04/19] contrib/elf2dmp: Change pa_space_create() signature, Akihiko Odaki, 2024/03/06
- [PATCH v3 05/19] contrib/elf2dmp: Fix error reporting style in addrspace.c, Akihiko Odaki, 2024/03/06
- [PATCH v3 10/19] contrib/elf2dmp: Always check for PA resolution failure, Akihiko Odaki, 2024/03/06
- [PATCH v3 02/19] contrib/elf2dmp: Assume error by default, Akihiko Odaki, 2024/03/06
- [PATCH v3 09/19] contrib/elf2dmp: Fix error reporting style in main.c, Akihiko Odaki, 2024/03/06
- [PATCH v3 12/19] contrib/elf2dmp: Ensure segment fits in file,
Akihiko Odaki <=
- [PATCH v3 14/19] contrib/elf2dmp: Use rol64() to decode, Akihiko Odaki, 2024/03/06
- [PATCH v3 11/19] contrib/elf2dmp: Always destroy PA space, Akihiko Odaki, 2024/03/06
- [PATCH v3 13/19] contrib/elf2dmp: Use lduw_le_p() to read PDB, Akihiko Odaki, 2024/03/06
- [PATCH v3 15/19] MAINTAINERS: Add Akihiko Odaki as a elf2dmp reviewer, Akihiko Odaki, 2024/03/06
- [PATCH v3 16/19] contrib/elf2dmp: Build only for little endian host, Akihiko Odaki, 2024/03/06
- [PATCH v3 19/19] contrib/elf2dmp: Ensure phdrs fit in file, Akihiko Odaki, 2024/03/06
- [PATCH v3 17/19] contrib/elf2dmp: Use GPtrArray, Akihiko Odaki, 2024/03/06
- [PATCH v3 18/19] contrib/elf2dmp: Clamp QEMU note to file size, Akihiko Odaki, 2024/03/06