]> code.ossystems Code Review - openembedded-core.git/blob
2465924acf878016bfcb73ab2e524ac146e4839d
[openembedded-core.git] /
1 From d08572f7c9692c335afdb6f8dde48d77731209c3 Mon Sep 17 00:00:00 2001
2 From: Mark Wielaard <mark@klomp.org>
3 Date: Fri, 28 Sep 2018 10:45:56 +0800
4 Subject: [PATCH 2/2] libelf: Return error if elf_compress_gnu is used on
5  SHF_COMPRESSED section.
6
7 Compressing a section that is already compressed is fine, but useless.
8 But it isn't possible to gnu compress (or decompress) a SHF_COMPRESSED
9 section since there is no state kept that would tell if the section was
10 first GNU compressed or first gabi compressed. Calling elf_compress_gnu
11 on a section and then calling elf_compress on it to decompress it twice
12 could cause a crash (the other way around is fine). Just disallow it.
13
14 https://sourceware.org/bugzilla/show_bug.cgi?id=23528
15
16 Signed-off-by: Mark Wielaard <mark@klomp.org>
17
18 Upstream-Status: Backport [https://sourceware.org/git/?p=elfutils.git;a=commit;h=56b18521fb8d46d40fc090c0de9d11a08bc982fa]
19 CVE: CVE-2018-16402
20 Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
21 ---
22  libelf/elf_compress_gnu.c | 4 +++-
23  libelf/libelf.h           | 5 +++++
24  2 files changed, 8 insertions(+), 1 deletion(-)
25
26 diff --git a/libelf/elf_compress_gnu.c b/libelf/elf_compress_gnu.c
27 index c35dc39..dfa7c57 100644
28 --- a/libelf/elf_compress_gnu.c
29 +++ b/libelf/elf_compress_gnu.c
30 @@ -80,7 +80,9 @@ elf_compress_gnu (Elf_Scn *scn, int inflate, unsigned int flags)
31        sh_addralign = shdr->sh_addralign;
32      }
33  
34 -  if ((sh_flags & SHF_ALLOC) != 0)
35 +  /* Allocated sections, or sections that are already are compressed
36 +     cannot (also) be GNU compressed.  */
37 +  if ((sh_flags & SHF_ALLOC) != 0 || (sh_flags & SHF_COMPRESSED))
38      {
39        __libelf_seterrno (ELF_E_INVALID_SECTION_FLAGS);
40        return -1;
41 diff --git a/libelf/libelf.h b/libelf/libelf.h
42 index 547c0f5..fa568f7 100644
43 --- a/libelf/libelf.h
44 +++ b/libelf/libelf.h
45 @@ -366,6 +366,11 @@ extern Elf64_Chdr *elf64_getchdr (Elf_Scn *__scn);
46     It is an error to request compression for a section that already
47     has SHF_COMPRESSED set, or (for elf_compress) to request
48     decompression for an section that doesn't have SHF_COMPRESSED set.
49 +   If a section has SHF_COMPRESSED set then calling elf_compress_gnu
50 +   will result in an error.  The section has to be decompressed first
51 +   using elf_compress.  Calling elf_compress on a section compressed
52 +   with elf_compress_gnu is fine, but probably useless.
53 +
54     It is always an error to call these functions on SHT_NOBITS
55     sections or if the section has the SHF_ALLOC flag set.
56     elf_compress_gnu will not check whether the section name starts
57 -- 
58 2.7.4
59