Browse code

libarchive: Fix CVE-2018-1000877, CVE-2018-1000878

Added the upstream patch to fix the CVE

Change-Id: Iff7e4a70603a1fed8b43771df54a2f3fd5c08153
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/6835
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Anish Swaminathan <anishs@vmware.com>

Ankit Jain authored on 2019/03/09 03:24:47
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,31 @@
0
+From 021efa522ad729ff0f5806c4ce53e4a6cc1daa31 Mon Sep 17 00:00:00 2001
1
+From: Daniel Axtens <dja@axtens.net>
2
+Date: Tue, 20 Nov 2018 17:56:29 +1100
3
+Subject: [PATCH] Avoid a double-free when a window size of 0 is specified
4
+
5
+new_size can be 0 with a malicious or corrupted RAR archive.
6
+
7
+realloc(area, 0) is equivalent to free(area), so the region would
8
+be free()d here and the free()d again in the cleanup function.
9
+
10
+Found with a setup running AFL, afl-rb, and qsym.
11
+---
12
+ libarchive/archive_read_support_format_rar.c | 5 +++++
13
+ 1 file changed, 5 insertions(+)
14
+
15
+diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c
16
+index 234522229..6f419c270 100644
17
+--- a/libarchive/archive_read_support_format_rar.c
18
+@@ -2300,6 +2300,11 @@ parse_codes(struct archive_read *a)
19
+       new_size = DICTIONARY_MAX_SIZE;
20
+     else
21
+       new_size = rar_fls((unsigned int)rar->unp_size) << 1;
22
++    if (new_size == 0) {
23
++      archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
24
++                        "Zero window size is invalid.");
25
++      return (ARCHIVE_FATAL);
26
++    }
27
+     new_window = realloc(rar->lzss.window, new_size);
28
+     if (new_window == NULL) {
29
+       archive_set_error(&a->archive, ENOMEM,
0 30
new file mode 100644
... ...
@@ -0,0 +1,72 @@
0
+From bfcfe6f04ed20db2504db8a254d1f40a1d84eb28 Mon Sep 17 00:00:00 2001
1
+From: Daniel Axtens <dja@axtens.net>
2
+Date: Tue, 4 Dec 2018 00:55:22 +1100
3
+Subject: [PATCH] rar: file split across multi-part archives must match
4
+
5
+Fuzzing uncovered some UAF and memory overrun bugs where a file in a
6
+single file archive reported that it was split across multiple
7
+volumes. This was caused by ppmd7 operations calling
8
+rar_br_fillup. This would invoke rar_read_ahead, which would in some
9
+situations invoke archive_read_format_rar_read_header.  That would
10
+check the new file name against the old file name, and if they didn't
11
+match up it would free the ppmd7 buffer and allocate a new
12
+one. However, because the ppmd7 decoder wasn't actually done with the
13
+buffer, it would continue to used the freed buffer. Both reads and
14
+writes to the freed region can be observed.
15
+
16
+This is quite tricky to solve: once the buffer has been freed it is
17
+too late, as the ppmd7 decoder functions almost universally assume
18
+success - there's no way for ppmd_read to signal error, nor are there
19
+good ways for functions like Range_Normalise to propagate them. So we
20
+can't detect after the fact that we're in an invalid state - e.g. by
21
+checking rar->cursor, we have to prevent ourselves from ever ending up
22
+there. So, when we are in the dangerous part or rar_read_ahead that
23
+assumes a valid split, we set a flag force read_header to either go
24
+down the path for split files or bail. This means that the ppmd7
25
+decoder keeps a valid buffer and just runs out of data.
26
+
27
+Found with a combination of AFL, afl-rb and qsym.
28
+---
29
+ libarchive/archive_read_support_format_rar.c | 9 +++++++++
30
+ 1 file changed, 9 insertions(+)
31
+
32
+diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c
33
+index 6f419c270..a8cc5c94d 100644
34
+--- a/libarchive/archive_read_support_format_rar.c
35
+@@ -258,6 +258,7 @@ struct rar
36
+   struct data_block_offsets *dbo;
37
+   unsigned int cursor;
38
+   unsigned int nodes;
39
++  char filename_must_match;
40
+ 
41
+   /* LZSS members */
42
+   struct huffman_code maincode;
43
+@@ -1560,6 +1561,12 @@ read_header(struct archive_read *a, struct archive_entry *entry,
44
+     }
45
+     return ret;
46
+   }
47
++  else if (rar->filename_must_match)
48
++  {
49
++    archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
50
++      "Mismatch of file parts split across multi-volume archive");
51
++    return (ARCHIVE_FATAL);
52
++  }
53
+ 
54
+   rar->filename_save = (char*)realloc(rar->filename_save,
55
+                                       filename_size + 1);
56
+@@ -2933,12 +2940,14 @@ rar_read_ahead(struct archive_read *a, size_t min, ssize_t *avail)
57
+     else if (*avail == 0 && rar->main_flags & MHD_VOLUME &&
58
+       rar->file_flags & FHD_SPLIT_AFTER)
59
+     {
60
++      rar->filename_must_match = 1;
61
+       ret = archive_read_format_rar_read_header(a, a->entry);
62
+       if (ret == (ARCHIVE_EOF))
63
+       {
64
+         rar->has_endarc_header = 1;
65
+         ret = archive_read_format_rar_read_header(a, a->entry);
66
+       }
67
++      rar->filename_must_match = 0;
68
+       if (ret != (ARCHIVE_OK))
69
+         return NULL;
70
+       return rar_read_ahead(a, min, avail);
... ...
@@ -1,7 +1,7 @@
1 1
 Summary:    Multi-format archive and compression library
2 2
 Name:       libarchive
3 3
 Version:    3.3.1
4
-Release:    1%{?dist}
4
+Release:    2%{?dist}
5 5
 License:    BSD 2-Clause License
6 6
 URL:        http://www.libarchive.org/
7 7
 Group:      System Environment/Development
... ...
@@ -9,6 +9,8 @@ Vendor:     VMware, Inc.
9 9
 Distribution:   Photon
10 10
 Source0:    http://www.libarchive.org/downloads/%{name}-%{version}.tar.gz
11 11
 %define sha1 libarchive=d5616f81804aba92547629c08a3ccff86c2844ae
12
+Patch0:     libarchive-CVE-2018-1000877.patch
13
+Patch1:     libarchive-CVE-2018-1000878.patch
12 14
 
13 15
 %description
14 16
 Multi-format archive and compression library
... ...
@@ -21,6 +23,8 @@ It contains the libraries and header files to create applications
21 21
 
22 22
 %prep
23 23
 %setup -q
24
+%patch0 -p1
25
+%patch1 -p1
24 26
 
25 27
 %build
26 28
 export CFLAGS="%{optflags}"
... ...
@@ -50,6 +54,8 @@ find %{buildroot}%{_libdir} -name '*.la' -delete
50 50
 %{_libdir}/pkgconfig/*.pc
51 51
 
52 52
 %changelog
53
+*   Fri Mar 08 2019 Ankit Jain <ankitja@vmware.com> 3.3.1-2
54
+-   Fix for CVE-2018-1000877 and CVE-2018-1000878
53 55
 *   Thu Apr 06 2017 Divya Thaluru <dthaluru@vmware.com> 3.3.1-1
54 56
 -   Upgrade version to 3.3.1
55 57
 *   Thu Sep 22 2016 Anish Swaminathan <anishs@vmware.com> 3.1.2-7