Browse code

Adding securtiy patches for libarchive

dthaluru authored on 2015/08/15 03:18:36
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,149 @@
0
+From 59357157706d47c365b2227739e17daba3607526 Mon Sep 17 00:00:00 2001
1
+From: Alessandro Ghedini <alessandro@ghedini.me>
2
+Date: Sun, 1 Mar 2015 12:07:45 +0100
3
+Subject: [PATCH] Add ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS option
4
+
5
+This fixes a directory traversal in the cpio tool.
6
+
7
+
8
+Upstream-Status: backport
9
+
10
+Signed-off-by: Li Zhou <li.zhou@windriver.com>
11
+---
12
+ cpio/bsdcpio.1                           |    3 ++-
13
+ cpio/cpio.c                              |    2 ++
14
+ libarchive/archive.h                     |    2 ++
15
+ libarchive/archive_write_disk.3          |    3 +++
16
+ libarchive/archive_write_disk_posix.c    |   14 +++++++++++---
17
+ libarchive/test/test_write_disk_secure.c |   23 +++++++++++++++++++++++
18
+ 6 files changed, 43 insertions(+), 4 deletions(-)
19
+
20
+diff --git a/cpio/bsdcpio.1 b/cpio/bsdcpio.1
21
+index f966aa0..e52546e 100644
22
+--- a/cpio/bsdcpio.1
23
+@@ -156,7 +156,8 @@ See above for description.
24
+ .It Fl Fl insecure
25
+ (i and p mode only)
26
+ Disable security checks during extraction or copying.
27
+-This allows extraction via symbolic links and path names containing
28
++This allows extraction via symbolic links, absolute paths,
29
++and path names containing
30
+ .Sq ..
31
+ in the name.
32
+ .It Fl J , Fl Fl xz
33
+diff --git a/cpio/cpio.c b/cpio/cpio.c
34
+index 0acde11..b267e9b 100644
35
+--- a/cpio/cpio.c
36
+@@ -171,6 +171,7 @@ main(int argc, char *argv[])
37
+ 	cpio->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
38
+ 	cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_SYMLINKS;
39
+ 	cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NODOTDOT;
40
++	cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS;
41
+ 	cpio->extract_flags |= ARCHIVE_EXTRACT_PERM;
42
+ 	cpio->extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
43
+ 	cpio->extract_flags |= ARCHIVE_EXTRACT_ACL;
44
+@@ -256,6 +257,7 @@ main(int argc, char *argv[])
45
+ 		case OPTION_INSECURE:
46
+ 			cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_SYMLINKS;
47
+ 			cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT;
48
++			cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS;
49
+ 			break;
50
+ 		case 'L': /* GNU cpio */
51
+ 			cpio->option_follow_links = 1;
52
+diff --git a/libarchive/archive.h b/libarchive/archive.h
53
+index 1f0fc38..ef635ac 100644
54
+--- a/libarchive/archive.h
55
+@@ -649,6 +649,8 @@ __LA_DECL int archive_read_set_passphrase_callback(struct archive *,
56
+ /* Default: Do not use HFS+ compression if it was not compressed. */
57
+ /* This has no effect except on Mac OS v10.6 or later. */
58
+ #define	ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED	(0x8000)
59
++/* Default: Do not reject entries with absolute paths */
60
++#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
61
+ 
62
+ __LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
63
+ 		     int flags);
64
+diff --git a/libarchive/archive_write_disk.3 b/libarchive/archive_write_disk.3
65
+index fa925cc..a2e7afa 100644
66
+--- a/libarchive/archive_write_disk.3
67
+@@ -177,6 +177,9 @@ The default is to not refuse such paths.
68
+ Note that paths ending in
69
+ .Pa ..
70
+ always cause an error, regardless of this flag.
71
++.It Cm ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
72
++Refuse to extract an absolute path.
73
++The default is to not refuse such paths.
74
+ .It Cm ARCHIVE_EXTRACT_SPARSE
75
+ Scan data for blocks of NUL bytes and try to recreate them with holes.
76
+ This results in sparse files, independent of whether the archive format
77
+diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c
78
+index ab3bdac..c1290eb 100644
79
+--- a/libarchive/archive_write_disk_posix.c
80
+@@ -2509,8 +2509,9 @@ cleanup_pathname_win(struct archive_write_disk *a)
81
+ /*
82
+  * Canonicalize the pathname.  In particular, this strips duplicate
83
+  * '/' characters, '.' elements, and trailing '/'.  It also raises an
84
+- * error for an empty path, a trailing '..' or (if _SECURE_NODOTDOT is
85
+- * set) any '..' in the path.
86
++ * error for an empty path, a trailing '..', (if _SECURE_NODOTDOT is
87
++ * set) any '..' in the path or (if ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
88
++ * is set) if the path is absolute.
89
+  */
90
+ static int
91
+ cleanup_pathname(struct archive_write_disk *a)
92
+@@ -2529,8 +2530,15 @@ cleanup_pathname(struct archive_write_disk *a)
93
+ 	cleanup_pathname_win(a);
94
+ #endif
95
+ 	/* Skip leading '/'. */
96
+-	if (*src == '/')
97
++	if (*src == '/') {
98
++		if (a->flags & ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS) {
99
++			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
100
++			                  "Path is absolute");
101
++			return (ARCHIVE_FAILED);
102
++		}
103
++
104
+ 		separator = *src++;
105
++	}
106
+ 
107
+ 	/* Scan the pathname one element at a time. */
108
+ 	for (;;) {
109
+diff --git a/libarchive/test/test_write_disk_secure.c b/libarchive/test/test_write_disk_secure.c
110
+index 31c5bfd..2c94206 100644
111
+--- a/libarchive/test/test_write_disk_secure.c
112
+@@ -178,6 +178,29 @@ DEFINE_TEST(test_write_disk_secure)
113
+ 	assert(S_ISDIR(st.st_mode));
114
+ 	archive_entry_free(ae);
115
+ 
116
++	/*
117
++	 * Without security checks, we should be able to
118
++	 * extract an absolute path.
119
++	 */
120
++	assert((ae = archive_entry_new()) != NULL);
121
++	archive_entry_copy_pathname(ae, "/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp");
122
++	archive_entry_set_mode(ae, S_IFREG | 0777);
123
++	assert(0 == archive_write_header(a, ae));
124
++	assert(0 == archive_write_finish_entry(a));
125
++	assertFileExists("/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp");
126
++	assert(0 == unlink("/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp"));
127
++
128
++	/* But with security checks enabled, this should fail. */
129
++	assert(archive_entry_clear(ae) != NULL);
130
++	archive_entry_copy_pathname(ae, "/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp");
131
++	archive_entry_set_mode(ae, S_IFREG | 0777);
132
++	archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS);
133
++	failure("Extracting an absolute path should fail here.");
134
++	assertEqualInt(ARCHIVE_FAILED, archive_write_header(a, ae));
135
++	archive_entry_free(ae);
136
++	assert(0 == archive_write_finish_entry(a));
137
++	assertFileNotExists("/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp");
138
++
139
+ 	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
140
+ 
141
+ 	/* Test the entries on disk. */
142
+---
0 143
new file mode 100644
... ...
@@ -0,0 +1,36 @@
0
+From 2f55d6bd308ea61975558c2469ae349dba297e89 Mon Sep 17 00:00:00 2001
1
+From: Robert Yang <liezhi.yang@windriver.com>
2
+Date: Sat, 22 Feb 2014 14:35:59 +0800
3
+Subject: [PATCH] Fix CVE-2013-0211
4
+
5
+This patch comes from:https://github.com/libarchive/libarchive/commit/22531545514043e04633e1c015c7540b9de9dbe4
6
+
7
+Upstream-Status: Backport
8
+
9
+Signed-off-by: Baogen shang <baogen.shang@windriver.com>
10
+
11
+Update the patch because of uprev on 20140222
12
+
13
+Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
14
+---
15
+ libarchive/archive_write.c | 4 ++++
16
+ 1 file changed, 4 insertions(+)
17
+
18
+diff --git a/libarchive/archive_write.c b/libarchive/archive_write.c
19
+index a3d1a33..a323588 100644
20
+--- a/libarchive/archive_write.c
21
+@@ -671,8 +671,12 @@ static ssize_t
22
+ _archive_write_data(struct archive *_a, const void *buff, size_t s)
23
+ {
24
+ 	struct archive_write *a = (struct archive_write *)_a;
25
++	const size_t max_write = INT_MAX;
26
+ 	archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
27
+ 	    ARCHIVE_STATE_DATA, "archive_write_data");
28
++	/* In particular, this catches attempts to pass negative values. */
29
++	if (s > max_write)
30
++		s = max_write;
31
+ 	archive_clear_error(&a->archive);
32
+ 	return ((a->format_write_data)(a, buff, s));
33
+ }
34
+-- 
... ...
@@ -1,7 +1,7 @@
1 1
 Summary:    Multi-format archive and compression library
2 2
 Name:       libarchive
3 3
 Version:    3.1.2
4
-Release:    2%{?dist}
4
+Release:    3%{?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=6a991777ecb0f890be931cec4aec856d1a195489
12
+Patch0: libarchive-CVE-2013-0211.patch
13
+Patch1:	0001-Add-ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS-option.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}"
... ...
@@ -46,6 +50,8 @@ make DESTDIR=%{buildroot} install
46 46
 %{_mandir}
47 47
 
48 48
 %changelog
49
+*   Fri Aug 14 2015 Alexey Makhalov <amakhalov@vmware.com> 3.1.2-3
50
+-   Adding patches for security fixes CVE-2013-2011 and CVE-2015-2304.
49 51
 *   Wed Jul 8 2015 Alexey Makhalov <amakhalov@vmware.com> 3.1.2-2
50 52
 -   Added devel package, dist tag. Use macroses part.
51 53
 *   Fri Jun 5 2015 Touseef Liaqat <tliaqat@vmware.com> 3.1.2-1