summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-12-12 23:26:18 +0100
committerMark Wielaard <mark@klomp.org>2021-12-12 23:26:18 +0100
commitdb862a11910a5d4c007c549c2b4ce4cad62f242b (patch)
tree26617b35eddb02757146ed8ede413cc2e936eaba /libdwfl
parentPR28661: debuginfo connection thread pool support (diff)
downloadelfutils-db862a11910a5d4c007c549c2b4ce4cad62f242b.tar.gz
elfutils-db862a11910a5d4c007c549c2b4ce4cad62f242b.tar.bz2
elfutils-db862a11910a5d4c007c549c2b4ce4cad62f242b.tar.xz
libdwfl: Don't allocate more than SIZE_MAX in dwfl_segment_report_module.
The code in dwfl_segment_report_module tries to allocate and fill in memory as described in a core file. Normally all memory in filled in through the (phdrs) memory_callback or the read_eagerly callback. If the last callback doesn't work we try to calloc file_trimmed_end bytes and then try to fill in the parts of memory we can from the core file at the correct offsets. file_trimmed_end is a GElf_Off which is an unsigned 64bit type. On 32bit systems this means when cast to a size_t to do an allocation might allocate truncated (much smaller) value. So make sure to not allocate more than SIZE_MAX bytes. It would be nice to have a better way to limit the amount of memory allocated here. A core file might describe really big memory areas for which it doesn't provide any data. In that case we really shouldn't calloc mega- or giga-bytes of zeroed out memory. Reported-by: Evgeny Vereshchagin <evvers@ya.ru> Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/dwfl_segment_report_module.c3
2 files changed, 8 insertions, 0 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 856bd335..aaea164c 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
12021-12-12 Mark Wielaard <mark@klomp.org>
2
3 * dwfl_segment_report_module.c (dwfl_segment_report_module): Don't
4 allocate more than SIZE_MAX.
5
12021-12-09 Mark Wielaard <mark@klomp.org> 62021-12-09 Mark Wielaard <mark@klomp.org>
2 7
3 * link_map.c (dwfl_link_map_report): Limit dyn_filesz malloc size 8 * link_map.c (dwfl_link_map_report): Limit dyn_filesz malloc size
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index f4acfe53..46564ec5 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -904,6 +904,9 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
904 /* The caller wants to read the whole file in right now, but hasn't 904 /* The caller wants to read the whole file in right now, but hasn't
905 done it for us. Fill in a local image of the virtual file. */ 905 done it for us. Fill in a local image of the virtual file. */
906 906
907 if (file_trimmed_end > SIZE_MAX)
908 goto out;
909
907 void *contents = calloc (1, file_trimmed_end); 910 void *contents = calloc (1, file_trimmed_end);
908 if (unlikely (contents == NULL)) 911 if (unlikely (contents == NULL))
909 goto out; 912 goto out;