|
| 1 | +From efcfd4821532ae4909d702c5f7212060e80e786d Mon Sep 17 00:00:00 2001 |
| 2 | +From: "H.J. Lu" <hjl.tools@gmail.com> |
| 3 | +Date: Mon, 22 Sep 2025 15:20:34 +0800 |
| 4 | +Subject: [PATCH] elf: Don't read beyond .eh_frame section size |
| 5 | + |
| 6 | +PR ld/33464 |
| 7 | +* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Don't read beyond |
| 8 | +.eh_frame section size. |
| 9 | + |
| 10 | +Signed-off-by: H.J. Lu <hjl.tools@gmail.com> |
| 11 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 12 | +Upstream-reference: https://github.com/bminor/binutils-gdb/commit/ea1a0737c7692737a644af0486b71e4a392cbca8.patch |
| 13 | +--- |
| 14 | + bfd/elf-eh-frame.c | 8 ++++++-- |
| 15 | + 1 file changed, 6 insertions(+), 2 deletions(-) |
| 16 | + |
| 17 | +diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c |
| 18 | +index 2e22d0c..d821bb2 100644 |
| 19 | +--- a/bfd/elf-eh-frame.c |
| 20 | ++++ b/bfd/elf-eh-frame.c |
| 21 | +@@ -733,6 +733,7 @@ _bfd_elf_parse_eh_frame (bfd *abfd, struct bfd_link_info *info, |
| 22 | + if (hdr_id == 0) |
| 23 | + { |
| 24 | + unsigned int initial_insn_length; |
| 25 | ++ char *null_byte; |
| 26 | + |
| 27 | + /* CIE */ |
| 28 | + this_inf->cie = 1; |
| 29 | +@@ -749,10 +750,13 @@ _bfd_elf_parse_eh_frame (bfd *abfd, struct bfd_link_info *info, |
| 30 | + REQUIRE (cie->version == 1 |
| 31 | + || cie->version == 3 |
| 32 | + || cie->version == 4); |
| 33 | +- REQUIRE (strlen ((char *) buf) < sizeof (cie->augmentation)); |
| 34 | ++ null_byte = memchr ((char *) buf, 0, end - buf); |
| 35 | ++ REQUIRE (null_byte != NULL); |
| 36 | ++ REQUIRE ((size_t) (null_byte - (char *) buf) |
| 37 | ++ < sizeof (cie->augmentation)); |
| 38 | + |
| 39 | + strcpy (cie->augmentation, (char *) buf); |
| 40 | +- buf = (bfd_byte *) strchr ((char *) buf, '\0') + 1; |
| 41 | ++ buf = (bfd_byte *) null_byte + 1; |
| 42 | + this_inf->u.cie.aug_str_len = buf - start - 1; |
| 43 | + ENSURE_NO_RELOCS (buf); |
| 44 | + if (buf[0] == 'e' && buf[1] == 'h') |
| 45 | +-- |
| 46 | +2.45.4 |
| 47 | + |