From owner-svn-src-releng@freebsd.org Tue May 31 16:33:58 2016 Return-Path: Delivered-To: svn-src-releng@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 49391B55085; Tue, 31 May 2016 16:33:58 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 06EFD1AA6; Tue, 31 May 2016 16:33:57 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4VGXvax096381; Tue, 31 May 2016 16:33:57 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4VGXupT096375; Tue, 31 May 2016 16:33:56 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201605311633.u4VGXupT096375@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Tue, 31 May 2016 16:33:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-releng@freebsd.org Subject: svn commit: r301047 - in releng/10.2/contrib/libarchive: cpio libarchive libarchive/test X-SVN-Group: releng MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-releng@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the release engineering / security commits to the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2016 16:33:58 -0000 Author: glebius Date: Tue May 31 16:33:56 2016 New Revision: 301047 URL: https://svnweb.freebsd.org/changeset/base/301047 Log: Merge r300361 by mm@: Backport security fix for absolute path traversal vulnerability in bsdcpio. Security: CVE-2015-2304 Security: SA-16:22 Approved by: so Modified: releng/10.2/contrib/libarchive/cpio/bsdcpio.1 releng/10.2/contrib/libarchive/cpio/cpio.c releng/10.2/contrib/libarchive/libarchive/archive.h releng/10.2/contrib/libarchive/libarchive/archive_write_disk.3 releng/10.2/contrib/libarchive/libarchive/archive_write_disk_posix.c releng/10.2/contrib/libarchive/libarchive/test/test_write_disk_secure.c Directory Properties: releng/10.2/ (props changed) Modified: releng/10.2/contrib/libarchive/cpio/bsdcpio.1 ============================================================================== --- releng/10.2/contrib/libarchive/cpio/bsdcpio.1 Tue May 31 16:32:42 2016 (r301046) +++ releng/10.2/contrib/libarchive/cpio/bsdcpio.1 Tue May 31 16:33:56 2016 (r301047) @@ -156,7 +156,8 @@ See above for description. .It Fl Fl insecure (i and p mode only) Disable security checks during extraction or copying. -This allows extraction via symbolic links and path names containing +This allows extraction via symbolic links, absolute paths, +and path names containing .Sq .. in the name. .It Fl J , Fl Fl xz Modified: releng/10.2/contrib/libarchive/cpio/cpio.c ============================================================================== --- releng/10.2/contrib/libarchive/cpio/cpio.c Tue May 31 16:32:42 2016 (r301046) +++ releng/10.2/contrib/libarchive/cpio/cpio.c Tue May 31 16:33:56 2016 (r301047) @@ -179,6 +179,7 @@ main(int argc, char *argv[]) cpio->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_SYMLINKS; cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NODOTDOT; + cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS; cpio->extract_flags |= ARCHIVE_EXTRACT_PERM; cpio->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; cpio->extract_flags |= ARCHIVE_EXTRACT_ACL; @@ -264,6 +265,7 @@ main(int argc, char *argv[]) case OPTION_INSECURE: cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_SYMLINKS; cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; + cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS; break; case 'L': /* GNU cpio */ cpio->option_follow_links = 1; @@ -300,6 +302,7 @@ main(int argc, char *argv[]) "Cannot use both -p and -%c", cpio->mode); cpio->mode = opt; cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; + cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS; break; case OPTION_PRESERVE_OWNER: cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER; Modified: releng/10.2/contrib/libarchive/libarchive/archive.h ============================================================================== --- releng/10.2/contrib/libarchive/libarchive/archive.h Tue May 31 16:32:42 2016 (r301046) +++ releng/10.2/contrib/libarchive/libarchive/archive.h Tue May 31 16:33:56 2016 (r301047) @@ -562,6 +562,8 @@ __LA_DECL int archive_read_set_options(s /* Default: Do not use HFS+ compression if it was not compressed. */ /* This has no effect except on Mac OS v10.6 or later. */ #define ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED (0x8000) +/* Default: Do not reject entries with absolute paths */ +#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000) __LA_DECL int archive_read_extract(struct archive *, struct archive_entry *, int flags); Modified: releng/10.2/contrib/libarchive/libarchive/archive_write_disk.3 ============================================================================== --- releng/10.2/contrib/libarchive/libarchive/archive_write_disk.3 Tue May 31 16:32:42 2016 (r301046) +++ releng/10.2/contrib/libarchive/libarchive/archive_write_disk.3 Tue May 31 16:33:56 2016 (r301047) @@ -177,6 +177,9 @@ The default is to not refuse such paths. Note that paths ending in .Pa .. always cause an error, regardless of this flag. +.It Cm ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS +Refuse to extract an absolute path. +The default is to not refuse such paths. .It Cm ARCHIVE_EXTRACT_SPARSE Scan data for blocks of NUL bytes and try to recreate them with holes. This results in sparse files, independent of whether the archive format Modified: releng/10.2/contrib/libarchive/libarchive/archive_write_disk_posix.c ============================================================================== --- releng/10.2/contrib/libarchive/libarchive/archive_write_disk_posix.c Tue May 31 16:32:42 2016 (r301046) +++ releng/10.2/contrib/libarchive/libarchive/archive_write_disk_posix.c Tue May 31 16:33:56 2016 (r301047) @@ -2504,8 +2504,9 @@ cleanup_pathname_win(struct archive_writ /* * Canonicalize the pathname. In particular, this strips duplicate * '/' characters, '.' elements, and trailing '/'. It also raises an - * error for an empty path, a trailing '..' or (if _SECURE_NODOTDOT is - * set) any '..' in the path. + * error for an empty path, a trailing '..', (if _SECURE_NODOTDOT is + * set) any '..' in the path or (if ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS + * is set) if the path is absolute. */ static int cleanup_pathname(struct archive_write_disk *a) @@ -2524,8 +2525,15 @@ cleanup_pathname(struct archive_write_di cleanup_pathname_win(a); #endif /* Skip leading '/'. */ - if (*src == '/') + if (*src == '/') { + if (a->flags & ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Path is absolute"); + return (ARCHIVE_FAILED); + } + separator = *src++; + } /* Scan the pathname one element at a time. */ for (;;) { Modified: releng/10.2/contrib/libarchive/libarchive/test/test_write_disk_secure.c ============================================================================== --- releng/10.2/contrib/libarchive/libarchive/test/test_write_disk_secure.c Tue May 31 16:32:42 2016 (r301046) +++ releng/10.2/contrib/libarchive/libarchive/test/test_write_disk_secure.c Tue May 31 16:33:56 2016 (r301047) @@ -178,6 +178,29 @@ DEFINE_TEST(test_write_disk_secure) assert(S_ISDIR(st.st_mode)); archive_entry_free(ae); + /* + * Without security checks, we should be able to + * extract an absolute path. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp"); + archive_entry_set_mode(ae, S_IFREG | 0777); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + assertFileExists("/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp"); + assert(0 == unlink("/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp")); + + /* But with security checks enabled, this should fail. */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS); + failure("Extracting an absolute path should fail here."); + assertEqualInt(ARCHIVE_FAILED, archive_write_header(a, ae)); + archive_entry_free(ae); + assert(0 == archive_write_finish_entry(a)); + assertFileNotExists("/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp"); + assertEqualInt(ARCHIVE_OK, archive_write_free(a)); /* Test the entries on disk. */