From owner-freebsd-bugs@FreeBSD.ORG Sat Dec 15 21:00:08 2007 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6C24916A420 for ; Sat, 15 Dec 2007 21:00:08 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 5A6DA13C44B for ; Sat, 15 Dec 2007 21:00:08 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id lBFL08PZ066617 for ; Sat, 15 Dec 2007 21:00:08 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id lBFL08BA066616; Sat, 15 Dec 2007 21:00:08 GMT (envelope-from gnats) Date: Sat, 15 Dec 2007 21:00:08 GMT Message-Id: <200712152100.lBFL08BA066616@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: John E Hein Cc: Subject: Re: bin/112336: install -S (safe copy) with -C or -p is not so safe X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: John E Hein List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Dec 2007 21:00:08 -0000 The following reply was made to PR bin/112336; it has been noted by GNATS. From: John E Hein To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org Cc: Subject: Re: bin/112336: install -S (safe copy) with -C or -p is not so safe Date: Sat, 15 Dec 2007 13:34:12 -0700 Here is an update to the patch to refresh it after a recent commit to xinstall.c and to additionally check euid which is important in some non-superuser cases. Index: xinstall.c =================================================================== RCS file: /base/FreeBSD-CVS/src/usr.bin/xinstall/xinstall.c,v retrieving revision 1.68 diff -u -p -r1.68 xinstall.c --- xinstall.c 14 Dec 2007 08:46:57 -0000 1.68 +++ xinstall.c 15 Dec 2007 20:21:35 -0000 @@ -278,6 +278,7 @@ install(const char *from_name, const cha int devnull, files_match, from_fd, serrno, target; int tempcopy, temp_fd, to_fd; char backup[MAXPATHLEN], *p, pathbuf[MAXPATHLEN], tempfile[MAXPATHLEN]; + uid_t euid; files_match = 0; from_fd = -1; @@ -322,7 +323,20 @@ install(const char *from_name, const cha if (docompare && !dostrip && target) { if ((to_fd = open(to_name, O_RDONLY, 0)) < 0) err(EX_OSERR, "%s", to_name); - if (devnull) + /* + * Even if the contents are the same, we want to rename + * temp files when doing a "safe" copy if the + * permissions and ownership need to change. We may + * not have permission to chown/chmod the "to" file + * directly. + */ + if (tempcopy && (euid = geteuid()) != 0 && + euid != to_sb.st_uid && + ((gid != (gid_t)-1 && gid != to_sb.st_gid) || + (uid != (uid_t)-1 && uid != to_sb.st_uid) || + (mode != (to_sb.st_mode & ALLPERMS)))) + files_match = 0; + else if (devnull) files_match = to_sb.st_size == 0; else files_match = !(compare(from_fd, from_name,