|
| 1 | +From 94b928448447a2b00d008315fc362e93c2842689 Mon Sep 17 00:00:00 2001 |
| 2 | +From: zengwei <zengwei1@uniontech.com> |
| 3 | +Date: Fri, 31 Oct 2025 15:35:05 +0800 |
| 4 | +Subject: [PATCH] CVE-2025-1176 |
| 5 | + |
| 6 | +--- |
| 7 | + bfd/elflink.c | 87 ++++++++++++++++++++++++++------------------------- |
| 8 | + 1 file changed, 44 insertions(+), 43 deletions(-) |
| 9 | + |
| 10 | +diff --git a/bfd/elflink.c b/bfd/elflink.c |
| 11 | +index 7217c2f0..161cdf8d 100644 |
| 12 | +--- a/bfd/elflink.c |
| 13 | ++++ b/bfd/elflink.c |
| 14 | +@@ -62,22 +62,38 @@ struct elf_find_verdep_info |
| 15 | + static bool _bfd_elf_fix_symbol_flags |
| 16 | + (struct elf_link_hash_entry *, struct elf_info_failed *); |
| 17 | + |
| 18 | +-asection * |
| 19 | +-_bfd_elf_section_for_symbol (struct elf_reloc_cookie *cookie, |
| 20 | +- unsigned long r_symndx, |
| 21 | +- bool discard) |
| 22 | ++static struct elf_link_hash_entry * |
| 23 | ++get_ext_sym_hash (struct elf_reloc_cookie *cookie, unsigned long r_symndx) |
| 24 | + { |
| 25 | +- if (r_symndx >= cookie->locsymcount |
| 26 | +- || ELF_ST_BIND (cookie->locsyms[r_symndx].st_info) != STB_LOCAL) |
| 27 | ++ struct elf_link_hash_entry *h = NULL; |
| 28 | ++ |
| 29 | ++ if ((r_symndx >= cookie->locsymcount |
| 30 | ++ || ELF_ST_BIND (cookie->locsyms[r_symndx].st_info) != STB_LOCAL) |
| 31 | ++ /* Guard against corrupt input. See PR 32636 for an example. */ |
| 32 | ++ && r_symndx >= cookie->extsymoff) |
| 33 | + { |
| 34 | +- struct elf_link_hash_entry *h; |
| 35 | + |
| 36 | + h = cookie->sym_hashes[r_symndx - cookie->extsymoff]; |
| 37 | + |
| 38 | + while (h->root.type == bfd_link_hash_indirect |
| 39 | + || h->root.type == bfd_link_hash_warning) |
| 40 | + h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 41 | ++ } |
| 42 | ++ |
| 43 | ++ return h; |
| 44 | ++} |
| 45 | ++ |
| 46 | ++asection * |
| 47 | ++_bfd_elf_section_for_symbol (struct elf_reloc_cookie *cookie, |
| 48 | ++ unsigned long r_symndx, |
| 49 | ++ bool discard) |
| 50 | ++{ |
| 51 | ++ struct elf_link_hash_entry *h; |
| 52 | + |
| 53 | ++ h = get_ext_sym_hash (cookie, r_symndx); |
| 54 | ++ |
| 55 | ++ if (h != NULL) |
| 56 | ++ { |
| 57 | + if ((h->root.type == bfd_link_hash_defined |
| 58 | + || h->root.type == bfd_link_hash_defweak) |
| 59 | + && discarded_section (h->root.u.def.section)) |
| 60 | +@@ -85,21 +101,19 @@ _bfd_elf_section_for_symbol (struct elf_reloc_cookie *cookie, |
| 61 | + else |
| 62 | + return NULL; |
| 63 | + } |
| 64 | +- else |
| 65 | +- { |
| 66 | +- /* It's not a relocation against a global symbol, |
| 67 | +- but it could be a relocation against a local |
| 68 | +- symbol for a discarded section. */ |
| 69 | +- asection *isec; |
| 70 | +- Elf_Internal_Sym *isym; |
| 71 | ++ /* It's not a relocation against a global symbol, |
| 72 | ++ but it could be a relocation against a local |
| 73 | ++ symbol for a discarded section. */ |
| 74 | ++ asection *isec; |
| 75 | ++ Elf_Internal_Sym *isym; |
| 76 | ++ |
| 77 | ++ /* Need to: get the symbol; get the section. */ |
| 78 | ++ isym = &cookie->locsyms[r_symndx]; |
| 79 | ++ isec = bfd_section_from_elf_index (cookie->abfd, isym->st_shndx); |
| 80 | ++ if (isec != NULL |
| 81 | ++ && discard ? discarded_section (isec) : 1) |
| 82 | ++ return isec; |
| 83 | + |
| 84 | +- /* Need to: get the symbol; get the section. */ |
| 85 | +- isym = &cookie->locsyms[r_symndx]; |
| 86 | +- isec = bfd_section_from_elf_index (cookie->abfd, isym->st_shndx); |
| 87 | +- if (isec != NULL |
| 88 | +- && discard ? discarded_section (isec) : 1) |
| 89 | +- return isec; |
| 90 | +- } |
| 91 | + return NULL; |
| 92 | + } |
| 93 | + |
| 94 | +@@ -13731,22 +13745,12 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_info *info, asection *sec, |
| 95 | + if (r_symndx == STN_UNDEF) |
| 96 | + return NULL; |
| 97 | + |
| 98 | +- if (r_symndx >= cookie->locsymcount |
| 99 | +- || ELF_ST_BIND (cookie->locsyms[r_symndx].st_info) != STB_LOCAL) |
| 100 | ++ h = get_ext_sym_hash (cookie, r_symndx); |
| 101 | ++ |
| 102 | ++ if (h != NULL) |
| 103 | + { |
| 104 | + bool was_marked; |
| 105 | + |
| 106 | +- h = cookie->sym_hashes[r_symndx - cookie->extsymoff]; |
| 107 | +- if (h == NULL) |
| 108 | +- { |
| 109 | +- info->callbacks->einfo (_("%F%P: corrupt input: %pB\n"), |
| 110 | +- sec->owner); |
| 111 | +- return NULL; |
| 112 | +- } |
| 113 | +- while (h->root.type == bfd_link_hash_indirect |
| 114 | +- || h->root.type == bfd_link_hash_warning) |
| 115 | +- h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 116 | +- |
| 117 | + was_marked = h->mark; |
| 118 | + h->mark = 1; |
| 119 | + /* Keep all aliases of the symbol too. If an object symbol |
| 120 | +@@ -14792,16 +14796,12 @@ bfd_elf_reloc_symbol_deleted_p (bfd_vma offset, void *cookie) |
| 121 | + if (r_symndx == STN_UNDEF) |
| 122 | + return true; |
| 123 | + |
| 124 | +- if (r_symndx >= rcookie->locsymcount |
| 125 | +- || ELF_ST_BIND (rcookie->locsyms[r_symndx].st_info) != STB_LOCAL) |
| 126 | +- { |
| 127 | +- struct elf_link_hash_entry *h; |
| 128 | +- |
| 129 | +- h = rcookie->sym_hashes[r_symndx - rcookie->extsymoff]; |
| 130 | ++ struct elf_link_hash_entry *h; |
| 131 | + |
| 132 | +- while (h->root.type == bfd_link_hash_indirect |
| 133 | +- || h->root.type == bfd_link_hash_warning) |
| 134 | +- h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 135 | ++ h = get_ext_sym_hash (rcookie, r_symndx); |
| 136 | ++ |
| 137 | ++ if (h != NULL) |
| 138 | ++ { |
| 139 | + |
| 140 | + if ((h->root.type == bfd_link_hash_defined |
| 141 | + || h->root.type == bfd_link_hash_defweak) |
| 142 | +@@ -14826,6 +14826,7 @@ bfd_elf_reloc_symbol_deleted_p (bfd_vma offset, void *cookie) |
| 143 | + || discarded_section (isec))) |
| 144 | + return true; |
| 145 | + } |
| 146 | ++ |
| 147 | + return false; |
| 148 | + } |
| 149 | + return false; |
| 150 | +-- |
| 151 | +2.20.1 |
| 152 | + |
0 commit comments