summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-12-23 23:16:25 +0100
committerMark Wielaard <mark@klomp.org>2022-01-04 00:36:49 +0100
commit1cf73965853037301a6099dea5368a1303cde2ba (patch)
tree7de7e275009a2fa2eb04b54712a6a807a4a76609 /libdwfl
parentlibdwfl: Always clean up build_id.memory (diff)
downloadelfutils-1cf73965853037301a6099dea5368a1303cde2ba.tar.gz
elfutils-1cf73965853037301a6099dea5368a1303cde2ba.tar.bz2
elfutils-1cf73965853037301a6099dea5368a1303cde2ba.tar.xz
libdwfl: Make sure dwfl_elf_phdr_memory_callback returns at least minread
The callers of dwfl_elf_phdr_memory_callback assume at least minread bytes are read and available. Make sure to check start is smaller than elf->maximum_size before reading more. Return false if end - start is smaller than minread. Found by afl-fuzz. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/core-file.c6
2 files changed, 10 insertions, 1 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index abd5c34a..49a35e41 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
12021-12-23 Mark Wielaard <mark@klomp.org>
2
3 * core-file.c (dwfl_elf_phdr_memory_callback): Check start <
4 elf->maximum_size and end - start < minread.
5
12021-12-20 Mark Wielaard <mark@klomp.org> 62021-12-20 Mark Wielaard <mark@klomp.org>
2 7
3 * dwfl_segment_report_module.c (dwfl_segment_report_module): Move 8 * dwfl_segment_report_module.c (dwfl_segment_report_module): Move
diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c
index b04d1d18..cefc3db0 100644
--- a/libdwfl/core-file.c
+++ b/libdwfl/core-file.c
@@ -1,5 +1,6 @@
1/* Core file handling. 1/* Core file handling.
2 Copyright (C) 2008-2010, 2013, 2015 Red Hat, Inc. 2 Copyright (C) 2008-2010, 2013, 2015 Red Hat, Inc.
3 Copyright (C) 2021 Mark J. Wielaard <mark@klomp.org>
3 This file is part of elfutils. 4 This file is part of elfutils.
4 5
5 This file is free software; you can redistribute it and/or modify 6 This file is free software; you can redistribute it and/or modify
@@ -320,7 +321,7 @@ dwfl_elf_phdr_memory_callback (Dwfl *dwfl, int ndx,
320 (void) more (*buffer_available); 321 (void) more (*buffer_available);
321 322
322 /* If it's already on hand anyway, use as much as there is. */ 323 /* If it's already on hand anyway, use as much as there is. */
323 if (elf->map_address != NULL) 324 if (elf->map_address != NULL && start < elf->maximum_size)
324 (void) more (elf->maximum_size - start); 325 (void) more (elf->maximum_size - start);
325 326
326 /* Make sure we don't look past the end of the actual file, 327 /* Make sure we don't look past the end of the actual file,
@@ -332,6 +333,9 @@ dwfl_elf_phdr_memory_callback (Dwfl *dwfl, int ndx,
332 if (unlikely (start >= end)) 333 if (unlikely (start >= end))
333 return false; 334 return false;
334 335
336 if (end - start < minread)
337 return false;
338
335 if (elf->map_address != NULL) 339 if (elf->map_address != NULL)
336 { 340 {
337 void *contents = elf->map_address + elf->start_offset + start; 341 void *contents = elf->map_address + elf->start_offset + start;