From owner-svn-src-head@freebsd.org Tue Sep 20 21:38:13 2016 Return-Path: Delivered-To: svn-src-head@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 5EAB2BE36C5; Tue, 20 Sep 2016 21:38:13 +0000 (UTC) (envelope-from emaste@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 2EEEC165C; Tue, 20 Sep 2016 21:38:13 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u8KLcCAG007579; Tue, 20 Sep 2016 21:38:12 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8KLcCqf007578; Tue, 20 Sep 2016 21:38:12 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201609202138.u8KLcCqf007578@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Tue, 20 Sep 2016 21:38:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r306056 - head/usr.bin/elfdump 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.23 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: Tue, 20 Sep 2016 21:38:13 -0000 Author: emaste Date: Tue Sep 20 21:38:12 2016 New Revision: 306056 URL: https://svnweb.freebsd.org/changeset/base/306056 Log: elfdump: limit STDIN to no rights rather than closing it Closing stdin/stdout/stderr is often a bad idea as a future open() can end up with its fd. Leave it open and limit it to no rights instead. Reviewed by: cem Differential Revision: https://reviews.freebsd.org/D7984 Modified: head/usr.bin/elfdump/elfdump.c Modified: head/usr.bin/elfdump/elfdump.c ============================================================================== --- head/usr.bin/elfdump/elfdump.c Tue Sep 20 21:33:57 2016 (r306055) +++ head/usr.bin/elfdump/elfdump.c Tue Sep 20 21:38:12 2016 (r306056) @@ -573,7 +573,7 @@ main(int ac, char **av) cap_rights_init(&rights, CAP_MMAP_R); if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS) err(1, "unable to limit rights for %s", *av); - close(STDIN_FILENO); + cap_rights_limit(STDIN_FILENO, cap_rights_init(&rights)); cap_rights_init(&rights, CAP_FSTAT, CAP_IOCTL, CAP_WRITE); cmd = TIOCGETA; /* required by isatty(3) in printf(3) */ if ((cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS) ||