blob: 07d1d654674692bf07c1069e756044e70fe79197 [file] [log] [blame]
Brad Bishop96ff1982019-08-19 13:50:42 -04001From 30bcc01478433a1cb05b36dc5c4beef7d2c89b5b Mon Sep 17 00:00:00 2001
2From: Alan Modra <amodra@gmail.com>
3Date: Fri, 21 Jun 2019 11:51:38 +0930
4Subject: [PATCH] PR24689, string table corruption
5
6The testcase in the PR had a e_shstrndx section of type SHT_GROUP.
7hdr->contents were initialized by setup_group rather than being read
8from the file, thus last byte was not zero and string dereference ran
9off the end of the buffer.
10
11 PR 24689
12 * elfcode.h (elf_object_p): Check type of e_shstrndx section.
13
14Upstream-Status: Backport
15CVE: CVE-2019-12972
16Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
17---
18 bfd/ChangeLog | 5 +++++
19 bfd/elfcode.h | 3 ++-
20 2 files changed, 7 insertions(+), 1 deletion(-)
21
22diff --git a/bfd/ChangeLog b/bfd/ChangeLog
23index 91f09e6346..e66fb40a2c 100644
24--- a/bfd/ChangeLog
25+++ b/bfd/ChangeLog
26@@ -1,3 +1,8 @@
27+2019-06-21 Alan Modra <amodra@gmail.com>
28+
29+ PR 24689
30+ * elfcode.h (elf_object_p): Check type of e_shstrndx section.
31+
32 2019-02-20 Alan Modra <amodra@gmail.com>
33
34 PR 24236
35diff --git a/bfd/elfcode.h b/bfd/elfcode.h
36index ec5ea766de..a35a629087 100644
37--- a/bfd/elfcode.h
38+++ b/bfd/elfcode.h
39@@ -755,7 +755,8 @@ elf_object_p (bfd *abfd)
40 /* A further sanity check. */
41 if (i_ehdrp->e_shnum != 0)
42 {
43- if (i_ehdrp->e_shstrndx >= elf_numsections (abfd))
44+ if (i_ehdrp->e_shstrndx >= elf_numsections (abfd)
45+ || i_shdrp[i_ehdrp->e_shstrndx].sh_type != SHT_STRTAB)
46 {
47 /* PR 2257:
48 We used to just goto got_wrong_format_error here
49--
502.20.1
51