[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 13/20] contrib/elf2dmp: Ensure segment fits in file
From: |
Peter Maydell |
Subject: |
[PULL 13/20] contrib/elf2dmp: Ensure segment fits in file |
Date: |
Mon, 11 Mar 2024 19:12:34 +0000 |
From: Akihiko Odaki <akihiko.odaki@daynix.com>
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>
Tested-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>
Message-id: 20240307-elf2dmp-v4-12-4f324ad4d99d@daynix.com
Signed-off-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 e01860d15b0..81295a11534 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.34.1
- [PULL 15/20] contrib/elf2dmp: Use rol64() to decode, (continued)
- [PULL 15/20] contrib/elf2dmp: Use rol64() to decode, Peter Maydell, 2024/03/11
- [PULL 12/20] contrib/elf2dmp: Always destroy PA space, Peter Maydell, 2024/03/11
- [PULL 18/20] contrib/elf2dmp: Clamp QEMU note to file size, Peter Maydell, 2024/03/11
- [PULL 11/20] contrib/elf2dmp: Always check for PA resolution failure, Peter Maydell, 2024/03/11
- [PULL 20/20] docs: update copyright date to the year 2024, Peter Maydell, 2024/03/11
- [PULL 01/20] hw/arm: Deprecate various old Arm machine types, Peter Maydell, 2024/03/11
- [PULL 07/20] contrib/elf2dmp: Fix error reporting style in download.c, Peter Maydell, 2024/03/11
- [PULL 04/20] contrib/elf2dmp: Continue even contexts are lacking, Peter Maydell, 2024/03/11
- [PULL 02/20] contrib/elf2dmp: Remove unnecessary err flags, Peter Maydell, 2024/03/11
- [PULL 14/20] contrib/elf2dmp: Use lduw_le_p() to read PDB, Peter Maydell, 2024/03/11
- [PULL 13/20] contrib/elf2dmp: Ensure segment fits in file,
Peter Maydell <=
- [PULL 09/20] contrib/elf2dmp: Fix error reporting style in qemu_elf.c, Peter Maydell, 2024/03/11
- [PULL 05/20] contrib/elf2dmp: Change pa_space_create() signature, Peter Maydell, 2024/03/11
- [PULL 06/20] contrib/elf2dmp: Fix error reporting style in addrspace.c, Peter Maydell, 2024/03/11
- [PULL 17/20] contrib/elf2dmp: Use GPtrArray, Peter Maydell, 2024/03/11
- [PULL 10/20] contrib/elf2dmp: Fix error reporting style in main.c, Peter Maydell, 2024/03/11
- [PULL 16/20] MAINTAINERS: Add Akihiko Odaki as a elf2dmp reviewer, Peter Maydell, 2024/03/11
- [PULL 19/20] contrib/elf2dmp: Ensure phdrs fit in file, Peter Maydell, 2024/03/11
- Re: [PULL 00/20] target-arm queue, Peter Maydell, 2024/03/12