Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame^] | 1 | From 09dd135df9ebc7a4b640537e23e26a03a288a789 Mon Sep 17 00:00:00 2001 |
| 2 | From: Alan Modra <amodra@gmail.com> |
| 3 | Date: Wed, 9 Oct 2019 00:07:29 +1030 |
| 4 | Subject: [PATCH] PR25078, stack overflow in function find_abstract_instance |
| 5 | |
| 6 | Selectively backporting fix for bfd/dwarf2.c, but not the ChangeLog |
| 7 | file. There are newer versions of binutils, but none of them contain the |
| 8 | commit fixing CVE-2019-17450, so backport it to master and zeus. |
| 9 | |
| 10 | Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=063c511bd79] |
| 11 | CVE: CVE-2019-17450 |
| 12 | Signed-off-by: Trevor Gamblin <trevor.gamblin@windriver.com> |
| 13 | |
| 14 | PR 25078 |
| 15 | * dwarf2.c (find_abstract_instance): Delete orig_info_ptr, add |
| 16 | recur_count. Error on recur_count reaching 100 rather than |
| 17 | info_ptr matching orig_info_ptr. Adjust calls. |
| 18 | |
| 19 | --- |
| 20 | bfd/dwarf2.c | 35 +++++++++++++++++------------------ |
| 21 | 1 file changed, 17 insertions(+), 18 deletions(-) |
| 22 | |
| 23 | diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c |
| 24 | index 0b4e485582..20ec9e2e56 100644 |
| 25 | --- a/bfd/dwarf2.c |
| 26 | +++ b/bfd/dwarf2.c |
| 27 | @@ -2803,13 +2803,13 @@ lookup_symbol_in_variable_table (struct comp_unit *unit, |
| 28 | } |
| 29 | |
| 30 | static bfd_boolean |
| 31 | -find_abstract_instance (struct comp_unit * unit, |
| 32 | - bfd_byte * orig_info_ptr, |
| 33 | - struct attribute * attr_ptr, |
| 34 | - const char ** pname, |
| 35 | - bfd_boolean * is_linkage, |
| 36 | - char ** filename_ptr, |
| 37 | - int * linenumber_ptr) |
| 38 | +find_abstract_instance (struct comp_unit *unit, |
| 39 | + struct attribute *attr_ptr, |
| 40 | + unsigned int recur_count, |
| 41 | + const char **pname, |
| 42 | + bfd_boolean *is_linkage, |
| 43 | + char **filename_ptr, |
| 44 | + int *linenumber_ptr) |
| 45 | { |
| 46 | bfd *abfd = unit->abfd; |
| 47 | bfd_byte *info_ptr; |
| 48 | @@ -2820,6 +2820,14 @@ find_abstract_instance (struct comp_unit * unit, |
| 49 | struct attribute attr; |
| 50 | const char *name = NULL; |
| 51 | |
| 52 | + if (recur_count == 100) |
| 53 | + { |
| 54 | + _bfd_error_handler |
| 55 | + (_("DWARF error: abstract instance recursion detected")); |
| 56 | + bfd_set_error (bfd_error_bad_value); |
| 57 | + return FALSE; |
| 58 | + } |
| 59 | + |
| 60 | /* DW_FORM_ref_addr can reference an entry in a different CU. It |
| 61 | is an offset from the .debug_info section, not the current CU. */ |
| 62 | if (attr_ptr->form == DW_FORM_ref_addr) |
| 63 | @@ -2939,15 +2947,6 @@ find_abstract_instance (struct comp_unit * unit, |
| 64 | info_ptr, info_ptr_end); |
| 65 | if (info_ptr == NULL) |
| 66 | break; |
| 67 | - /* It doesn't ever make sense for DW_AT_specification to |
| 68 | - refer to the same DIE. Stop simple recursion. */ |
| 69 | - if (info_ptr == orig_info_ptr) |
| 70 | - { |
| 71 | - _bfd_error_handler |
| 72 | - (_("DWARF error: abstract instance recursion detected")); |
| 73 | - bfd_set_error (bfd_error_bad_value); |
| 74 | - return FALSE; |
| 75 | - } |
| 76 | switch (attr.name) |
| 77 | { |
| 78 | case DW_AT_name: |
| 79 | @@ -2961,7 +2960,7 @@ find_abstract_instance (struct comp_unit * unit, |
| 80 | } |
| 81 | break; |
| 82 | case DW_AT_specification: |
| 83 | - if (!find_abstract_instance (unit, info_ptr, &attr, |
| 84 | + if (!find_abstract_instance (unit, &attr, recur_count + 1, |
| 85 | &name, is_linkage, |
| 86 | filename_ptr, linenumber_ptr)) |
| 87 | return FALSE; |
| 88 | @@ -3175,7 +3174,7 @@ scan_unit_for_symbols (struct comp_unit *unit) |
| 89 | |
| 90 | case DW_AT_abstract_origin: |
| 91 | case DW_AT_specification: |
| 92 | - if (!find_abstract_instance (unit, info_ptr, &attr, |
| 93 | + if (!find_abstract_instance (unit, &attr, 0, |
| 94 | &func->name, |
| 95 | &func->is_linkage, |
| 96 | &func->file, |
| 97 | -- |
| 98 | 2.23.0 |
| 99 | |