summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-12-17 17:43:19 +0100
committerMark Wielaard <mark@klomp.org>2021-12-18 02:24:28 +0100
commit3831c0b2c2334b129a9d04f12dc7549db412d3bd (patch)
tree2dba90d0ad60dc775c05bb5d043c8fa29a18c6e0 /libdwfl
parentlibdwfl: Make sure note data is properly aligned. (diff)
downloadelfutils-3831c0b2c2334b129a9d04f12dc7549db412d3bd.tar.gz
elfutils-3831c0b2c2334b129a9d04f12dc7549db412d3bd.tar.bz2
elfutils-3831c0b2c2334b129a9d04f12dc7549db412d3bd.tar.xz
libdwfl: Make dwfl_segment_report_module aware of maximum Elf size
At the end of dwfl_segment_report_module we might try to read in the whole contents described by a core file. To do this we first allocate a zeroed block of memory that is as big as possible. The core file however may describe much more loaded data than is actually available in the Elf image. So pass the maximum size so we can limit the amount of memory we reserve. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog8
-rw-r--r--libdwfl/core-file.c1
-rw-r--r--libdwfl/dwfl_segment_report_module.c5
-rw-r--r--libdwfl/libdwflP.h1
4 files changed, 13 insertions, 2 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index f18a0c45..6a3e041b 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,11 @@
12021-12-17 Mark Wielaard <mark@klomp.org>
2
3 * libdwflP.h (dwfl_segment_report_module): Add maxread argument.
4 * core-file.c (dwfl_core_file_report): Pass elf->maximum_size to
5 dwfl_segment_report_module.
6 * dwfl_segment_report_module.c (dwfl_segment_report_module): Add
7 maxread argument. Check file_trimmed_end against maxread.
8
12021-12-16 Mark Wielaard <mark@klomp.org> 92021-12-16 Mark Wielaard <mark@klomp.org>
2 10
3 * dwfl_segment_report_module.c (dwfl_segment_report_module): Check 11 * dwfl_segment_report_module.c (dwfl_segment_report_module): Check
diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c
index 4e4c9b3c..b04d1d18 100644
--- a/libdwfl/core-file.c
+++ b/libdwfl/core-file.c
@@ -559,6 +559,7 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const char *executable)
559 int seg = dwfl_segment_report_module (dwfl, ndx, NULL, 559 int seg = dwfl_segment_report_module (dwfl, ndx, NULL,
560 &dwfl_elf_phdr_memory_callback, elf, 560 &dwfl_elf_phdr_memory_callback, elf,
561 core_file_read_eagerly, elf, 561 core_file_read_eagerly, elf,
562 elf->maximum_size,
562 note_file, note_file_size, 563 note_file, note_file_size,
563 &r_debug_info); 564 &r_debug_info);
564 if (unlikely (seg < 0)) 565 if (unlikely (seg < 0))
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 2263e3cc..3e87d207 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -294,6 +294,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
294 void *memory_callback_arg, 294 void *memory_callback_arg,
295 Dwfl_Module_Callback *read_eagerly, 295 Dwfl_Module_Callback *read_eagerly,
296 void *read_eagerly_arg, 296 void *read_eagerly_arg,
297 size_t maxread,
297 const void *note_file, size_t note_file_size, 298 const void *note_file, size_t note_file_size,
298 const struct r_debug_info *r_debug_info) 299 const struct r_debug_info *r_debug_info)
299{ 300{
@@ -911,8 +912,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
911 /* The caller wants to read the whole file in right now, but hasn't 912 /* The caller wants to read the whole file in right now, but hasn't
912 done it for us. Fill in a local image of the virtual file. */ 913 done it for us. Fill in a local image of the virtual file. */
913 914
914 if (file_trimmed_end > SIZE_MAX) 915 if (file_trimmed_end > maxread)
915 goto out; 916 file_trimmed_end = maxread;
916 917
917 void *contents = calloc (1, file_trimmed_end); 918 void *contents = calloc (1, file_trimmed_end);
918 if (unlikely (contents == NULL)) 919 if (unlikely (contents == NULL))
diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h
index 4344e356..7503a627 100644
--- a/libdwfl/libdwflP.h
+++ b/libdwfl/libdwflP.h
@@ -698,6 +698,7 @@ extern int dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
698 void *memory_callback_arg, 698 void *memory_callback_arg,
699 Dwfl_Module_Callback *read_eagerly, 699 Dwfl_Module_Callback *read_eagerly,
700 void *read_eagerly_arg, 700 void *read_eagerly_arg,
701 size_t maxread,
701 const void *note_file, 702 const void *note_file,
702 size_t note_file_size, 703 size_t note_file_size,
703 const struct r_debug_info *r_debug_info); 704 const struct r_debug_info *r_debug_info);