From owner-svn-src-all@freebsd.org Sat May 21 09:27:31 2016 Return-Path: Delivered-To: svn-src-all@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 AC01FB44729; Sat, 21 May 2016 09:27:31 +0000 (UTC) (envelope-from mm@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 8871618C0; Sat, 21 May 2016 09:27:31 +0000 (UTC) (envelope-from mm@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4L9RUcr076568; Sat, 21 May 2016 09:27:30 GMT (envelope-from mm@FreeBSD.org) Received: (from mm@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4L9RUNu076562; Sat, 21 May 2016 09:27:30 GMT (envelope-from mm@FreeBSD.org) Message-Id: <201605210927.u4L9RUNu076562@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mm set sender to mm@FreeBSD.org using -f From: Martin Matuska Date: Sat, 21 May 2016 09:27:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r300363 - in stable/9/contrib/libarchive: cpio libarchive libarchive/test X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 May 2016 09:27:31 -0000 Author: mm Date: Sat May 21 09:27:30 2016 New Revision: 300363 URL: https://svnweb.freebsd.org/changeset/base/300363 Log: Backport security fix for absolute path traversal vulnerability in bsdcpio. This is a direct commit to stable/9. Vendor git commits: 59357157706d47c365b2227739e17daba3607526 199d5c79b547cebe3d7d33e5acd10ae03008c4a2 Security: CVE-2015-2304 Modified: stable/9/contrib/libarchive/cpio/bsdcpio.1 stable/9/contrib/libarchive/cpio/cpio.c stable/9/contrib/libarchive/libarchive/archive.h stable/9/contrib/libarchive/libarchive/archive_write.c stable/9/contrib/libarchive/libarchive/archive_write_disk.3 stable/9/contrib/libarchive/libarchive/test/test_write_disk_secure.c Modified: stable/9/contrib/libarchive/cpio/bsdcpio.1 ============================================================================== --- stable/9/contrib/libarchive/cpio/bsdcpio.1 Sat May 21 09:24:02 2016 (r300362) +++ stable/9/contrib/libarchive/cpio/bsdcpio.1 Sat May 21 09:27:30 2016 (r300363) @@ -159,7 +159,8 @@ See above for description. .It 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 Modified: stable/9/contrib/libarchive/cpio/cpio.c ============================================================================== --- stable/9/contrib/libarchive/cpio/cpio.c Sat May 21 09:24:02 2016 (r300362) +++ stable/9/contrib/libarchive/cpio/cpio.c Sat May 21 09:27:30 2016 (r300363) @@ -162,6 +162,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; @@ -231,6 +232,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; @@ -265,6 +267,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: stable/9/contrib/libarchive/libarchive/archive.h ============================================================================== --- stable/9/contrib/libarchive/libarchive/archive.h Sat May 21 09:24:02 2016 (r300362) +++ stable/9/contrib/libarchive/libarchive/archive.h Sat May 21 09:27:30 2016 (r300363) @@ -477,6 +477,8 @@ __LA_DECL int archive_read_set_options( #define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800) /* Detect blocks of 0 and write holes instead. */ #define ARCHIVE_EXTRACT_SPARSE (0x1000) +/* 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: stable/9/contrib/libarchive/libarchive/archive_write.c ============================================================================== --- stable/9/contrib/libarchive/libarchive/archive_write.c Sat May 21 09:24:02 2016 (r300362) +++ stable/9/contrib/libarchive/libarchive/archive_write.c Sat May 21 09:27:30 2016 (r300363) @@ -459,8 +459,12 @@ static ssize_t _archive_write_data(struct archive *_a, const void *buff, size_t s) { struct archive_write *a = (struct archive_write *)_a; + const size_t max_write = INT_MAX; __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_DATA, "archive_write_data"); + /* In particular, this catches attempts to pass negative values. */ + if (s > max_write) + s = max_write; archive_clear_error(&a->archive); return ((a->format_write_data)(a, buff, s)); } Modified: stable/9/contrib/libarchive/libarchive/archive_write_disk.3 ============================================================================== --- stable/9/contrib/libarchive/libarchive/archive_write_disk.3 Sat May 21 09:24:02 2016 (r300362) +++ stable/9/contrib/libarchive/libarchive/archive_write_disk.3 Sat May 21 09:27:30 2016 (r300363) @@ -169,6 +169,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: stable/9/contrib/libarchive/libarchive/test/test_write_disk_secure.c ============================================================================== --- stable/9/contrib/libarchive/libarchive/test/test_write_disk_secure.c Sat May 21 09:24:02 2016 (r300362) +++ stable/9/contrib/libarchive/libarchive/test/test_write_disk_secure.c Sat May 21 09:27:30 2016 (r300363) @@ -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"); + assert(0 == archive_write_finish(a)); /* Test the entries on disk. */