Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 1 | From 59fcd64fe65a89fb0acaf5463840310701189375 Mon Sep 17 00:00:00 2001 |
| 2 | From: Nick Clifton <nickc@redhat.com> |
| 3 | Date: Mon, 20 Feb 2017 14:40:39 +0000 |
| 4 | Subject: Fix another memory access error in readelf when parsing a corrupt |
| 5 | binary. |
| 6 | |
| 7 | PR binutils/21156 |
| 8 | * dwarf.c (cu_tu_indexes_read): Move into... |
| 9 | (load_cu_tu_indexes): ... here. Change the variable into |
| 10 | tri-state. Change the function into boolean, returning |
| 11 | false if the indicies could not be loaded. |
| 12 | (find_cu_tu_set): Return NULL if the indicies could not be |
| 13 | loaded. |
| 14 | |
| 15 | CVE: CVE-2017-6969 |
| 16 | Upstream-Status: Backport [master] |
| 17 | |
| 18 | Signed-off-by: Yuanjie Huang <yuanjie.huang@windriver.com> |
| 19 | --- |
| 20 | binutils/ChangeLog | 10 ++++++++++ |
| 21 | binutils/dwarf.c | 34 ++++++++++++++++++++-------------- |
| 22 | 2 files changed, 30 insertions(+), 14 deletions(-) |
| 23 | |
| 24 | diff --git a/binutils/ChangeLog b/binutils/ChangeLog |
| 25 | index dbf8eb079e..55d2f8ba40 100644 |
| 26 | --- a/binutils/ChangeLog |
| 27 | +++ b/binutils/ChangeLog |
| 28 | @@ -1,3 +1,13 @@ |
| 29 | +2017-02-20 Nick Clifton <nickc@redhat.com> |
| 30 | + |
| 31 | + PR binutils/21156 |
| 32 | + * dwarf.c (cu_tu_indexes_read): Move into... |
| 33 | + (load_cu_tu_indexes): ... here. Change the variable into |
| 34 | + tri-state. Change the function into boolean, returning |
| 35 | + false if the indicies could not be loaded. |
| 36 | + (find_cu_tu_set): Return NULL if the indicies could not be |
| 37 | + loaded. |
| 38 | + |
| 39 | 2017-02-17 Nick Clifton <nickc@redhat.com> |
| 40 | |
| 41 | PR binutils/21156 |
| 42 | diff --git a/binutils/dwarf.c b/binutils/dwarf.c |
| 43 | index 282e069958..a23267feb6 100644 |
| 44 | --- a/binutils/dwarf.c |
| 45 | +++ b/binutils/dwarf.c |
| 46 | @@ -76,7 +76,6 @@ int dwarf_check = 0; |
| 47 | as a zero-terminated list of section indexes comprising one set of debug |
| 48 | sections from a .dwo file. */ |
| 49 | |
| 50 | -static int cu_tu_indexes_read = 0; |
| 51 | static unsigned int *shndx_pool = NULL; |
| 52 | static unsigned int shndx_pool_size = 0; |
| 53 | static unsigned int shndx_pool_used = 0; |
| 54 | @@ -99,7 +98,7 @@ static int tu_count = 0; |
| 55 | static struct cu_tu_set *cu_sets = NULL; |
| 56 | static struct cu_tu_set *tu_sets = NULL; |
| 57 | |
| 58 | -static void load_cu_tu_indexes (void *file); |
| 59 | +static bfd_boolean load_cu_tu_indexes (void *); |
| 60 | |
| 61 | /* Values for do_debug_lines. */ |
| 62 | #define FLAG_DEBUG_LINES_RAW 1 |
| 63 | @@ -2713,7 +2712,7 @@ load_debug_info (void * file) |
| 64 | return num_debug_info_entries; |
| 65 | |
| 66 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
| 67 | - load_cu_tu_indexes (file); |
| 68 | + (void) load_cu_tu_indexes (file); |
| 69 | |
| 70 | if (load_debug_section (info, file) |
| 71 | && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0)) |
| 72 | @@ -7302,21 +7301,27 @@ process_cu_tu_index (struct dwarf_section *section, int do_display) |
| 73 | section sets that we can use to associate a .debug_info.dwo section |
| 74 | with its associated .debug_abbrev.dwo section in a .dwp file. */ |
| 75 | |
| 76 | -static void |
| 77 | +static bfd_boolean |
| 78 | load_cu_tu_indexes (void *file) |
| 79 | { |
| 80 | + static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
| 81 | + |
| 82 | /* If we have already loaded (or tried to load) the CU and TU indexes |
| 83 | then do not bother to repeat the task. */ |
| 84 | - if (cu_tu_indexes_read) |
| 85 | - return; |
| 86 | - |
| 87 | - if (load_debug_section (dwp_cu_index, file)) |
| 88 | - process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0); |
| 89 | - |
| 90 | - if (load_debug_section (dwp_tu_index, file)) |
| 91 | - process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0); |
| 92 | + if (cu_tu_indexes_read == -1) |
| 93 | + { |
| 94 | + cu_tu_indexes_read = TRUE; |
| 95 | + |
| 96 | + if (load_debug_section (dwp_cu_index, file)) |
| 97 | + if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
| 98 | + cu_tu_indexes_read = FALSE; |
| 99 | + |
| 100 | + if (load_debug_section (dwp_tu_index, file)) |
| 101 | + if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
| 102 | + cu_tu_indexes_read = FALSE; |
| 103 | + } |
| 104 | |
| 105 | - cu_tu_indexes_read = 1; |
| 106 | + return (bfd_boolean) cu_tu_indexes_read; |
| 107 | } |
| 108 | |
| 109 | /* Find the set of sections that includes section SHNDX. */ |
| 110 | @@ -7326,7 +7331,8 @@ find_cu_tu_set (void *file, unsigned int shndx) |
| 111 | { |
| 112 | unsigned int i; |
| 113 | |
| 114 | - load_cu_tu_indexes (file); |
| 115 | + if (! load_cu_tu_indexes (file)) |
| 116 | + return NULL; |
| 117 | |
| 118 | /* Find SHNDX in the shndx pool. */ |
| 119 | for (i = 0; i < shndx_pool_used; i++) |
| 120 | -- |
| 121 | 2.11.0 |
| 122 | |