diff options
author | Mark Wielaard <mark@klomp.org> | 2021-12-08 18:02:27 +0100 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2021-12-16 22:52:30 +0100 |
commit | 9098a37fcfb67342ad955efc71d1398e2f8a69c1 (patch) | |
tree | d88765cab77d3e5900a08e8991197cdd93a0b4ad /libdwfl | |
parent | libdwfl: Make sure phent is sane and there is at least one phdr (diff) | |
download | elfutils-9098a37fcfb67342ad955efc71d1398e2f8a69c1.tar.gz elfutils-9098a37fcfb67342ad955efc71d1398e2f8a69c1.tar.bz2 elfutils-9098a37fcfb67342ad955efc71d1398e2f8a69c1.tar.xz |
libdwfl: Add overflow check while iterating in dwfl_segment_report_module
While iterating the notes we could overflow the len variable if the
note name or description was too big. Fix this by adding an (unsigned)
overflow check.
https://sourceware.org/bugzilla/show_bug.cgi?id=28654
Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdwfl')
-rw-r--r-- | libdwfl/ChangeLog | 5 | ||||
-rw-r--r-- | libdwfl/dwfl_segment_report_module.c | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 7bf789e0..f849b816 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog | |||
@@ -1,3 +1,8 @@ | |||
1 | 2021-12-08 Mark Wielaard <mark@klomp.org> | ||
2 | |||
3 | * dwfl_segment_report_module.c (dwfl_segment_report_module): Add | ||
4 | len overflow check while iterating notes. | ||
5 | |||
1 | 2021-12-15 Mark Wielaard <mark@klomp.org> | 6 | 2021-12-15 Mark Wielaard <mark@klomp.org> |
2 | 7 | ||
3 | * link_map.c (dwfl_link_map_report): Make sure phent is either sizeof | 8 | * link_map.c (dwfl_link_map_report): Make sure phent is either sizeof |
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c index 46564ec5..f323929e 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c | |||
@@ -543,10 +543,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, | |||
543 | 543 | ||
544 | const GElf_Nhdr *nh = notes; | 544 | const GElf_Nhdr *nh = notes; |
545 | size_t len = 0; | 545 | size_t len = 0; |
546 | size_t last_len; | ||
546 | while (filesz > len + sizeof (*nh)) | 547 | while (filesz > len + sizeof (*nh)) |
547 | { | 548 | { |
548 | const void *note_name; | 549 | const void *note_name; |
549 | const void *note_desc; | 550 | const void *note_desc; |
551 | last_len = len; | ||
550 | 552 | ||
551 | len += sizeof (*nh); | 553 | len += sizeof (*nh); |
552 | note_name = notes + len; | 554 | note_name = notes + len; |
@@ -555,7 +557,9 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, | |||
555 | len = align == 8 ? NOTE_ALIGN8 (len) : NOTE_ALIGN4 (len); | 557 | len = align == 8 ? NOTE_ALIGN8 (len) : NOTE_ALIGN4 (len); |
556 | note_desc = notes + len; | 558 | note_desc = notes + len; |
557 | 559 | ||
558 | if (unlikely (filesz < len + nh->n_descsz)) | 560 | if (unlikely (filesz < len + nh->n_descsz |
561 | || len < last_len | ||
562 | || len + nh->n_descsz < last_len)) | ||
559 | break; | 563 | break; |
560 | 564 | ||
561 | if (nh->n_type == NT_GNU_BUILD_ID | 565 | if (nh->n_type == NT_GNU_BUILD_ID |