From owner-svn-src-head@FreeBSD.ORG Thu Apr 9 13:45:18 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 553FD2D2; Thu, 9 Apr 2015 13:45:18 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 40897B43; Thu, 9 Apr 2015 13:45:18 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t39DjIgQ016703; Thu, 9 Apr 2015 13:45:18 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t39DjIIs016702; Thu, 9 Apr 2015 13:45:18 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201504091345.t39DjIIs016702@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Thu, 9 Apr 2015 13:45:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r281311 - head/usr.bin/ar X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Apr 2015 13:45:18 -0000 Author: emaste Date: Thu Apr 9 13:45:17 2015 New Revision: 281311 URL: https://svnweb.freebsd.org/changeset/base/281311 Log: ar: Disallow directory traversal Set ARCHIVE_EXTRACT_SECURE_SYMLINKS and ARCHIVE_EXTRACT_SECURE_NODOTDOT as in bsdtar to prevent extraction of archive entries whose pathnames contain .. or whose target directory would be altered by a symlink. Also disallow absolute pathnames. We don't currently provide an option to disable this behaviour (as bsdtar's -P does). It is unlikely to be a problem in practice for ar(1), but the -P option is not currently used and available if we want to consider it for this purpose. Differential Revision: https://reviews.freebsd.org/D1524 Reported by: Alexander Cherepanov Approved by: delphij Obtained from: ELF tool chain ar, Ticket #474 MFC after: 1 week Relnotes: Yes Sponsored by: The FreeBSD Foundation Modified: head/usr.bin/ar/read.c Modified: head/usr.bin/ar/read.c ============================================================================== --- head/usr.bin/ar/read.c Thu Apr 9 13:09:05 2015 (r281310) +++ head/usr.bin/ar/read.c Thu Apr 9 13:45:17 2015 (r281311) @@ -187,7 +187,15 @@ read_archive(struct bsdar *bsdar, char m if (bsdar->options & AR_V) (void)fprintf(stdout, "x - %s\n", name); - flags = 0; + /* Disallow absolute paths. */ + if (name[0] == '/') { + bsdar_warnc(bsdar, 0, + "Absolute path '%s'", name); + continue; + } + /* Basic path security flags. */ + flags = ARCHIVE_EXTRACT_SECURE_SYMLINKS | \ + ARCHIVE_EXTRACT_SECURE_NODOTDOT; if (bsdar->options & AR_O) flags |= ARCHIVE_EXTRACT_TIME;