From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 1D751138A1A for ; Thu, 19 Feb 2015 21:16:34 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 786A9E08C4; Thu, 19 Feb 2015 21:16:32 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 22AC9E08C4 for ; Thu, 19 Feb 2015 21:16:32 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E80163407BD for ; Thu, 19 Feb 2015 21:16:30 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id DB295121EA for ; Thu, 19 Feb 2015 21:16:27 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1424378344.a0378f38713e630e1af9101c2ece5d27ca2130fe.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/rc/checkpath.c X-VCS-Directories: src/rc/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: a0378f38713e630e1af9101c2ece5d27ca2130fe X-VCS-Branch: master Date: Thu, 19 Feb 2015 21:16:27 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 42a7df5a-4b55-4675-af1c-1ad7865fac52 X-Archives-Hash: 79fa53251a1f272ed18c9315630eb5f3 commit: a0378f38713e630e1af9101c2ece5d27ca2130fe Author: William Hubbs gmail com> AuthorDate: Thu Feb 19 18:44:21 2015 +0000 Commit: William Hubbs gentoo org> CommitDate: Thu Feb 19 20:39:04 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=a0378f38 checkpath: do not chown or chmod symbolic links This is another security fix. If you use chown() or chmod() on a symbolic link, it affects the referenced file, not the symbolic link itself. X-Gentoo-Bug: 540006 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=540006 --- src/rc/checkpath.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c index 4e36242..87115a4 100644 --- a/src/rc/checkpath.c +++ b/src/rc/checkpath.c @@ -68,7 +68,7 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode, int u; memset(&st, 0, sizeof(st)); - if (stat(path, &st) || trunc) { + if (lstat(path, &st) || trunc) { if (type == inode_file) { einfo("%s: creating file", path); if (!mode) /* 664 */ @@ -133,10 +133,14 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode, } if (mode && (st.st_mode & 0777) != mode) { - if ((type != inode_dir) && (st.st_nlink != 1)) { + if ((type != inode_dir) && (st.st_nlink > 1)) { eerror("%s: chmod: %s %s", applet, "Too many hard links to", path); return -1; } + if (S_ISLNK(st.st_mode)) { + eerror("%s: chmod: %s %s", applet, path, " is a symbolic link"); + return -1; + } einfo("%s: correcting mode", path); if (chmod(path, mode)) { eerror("%s: chmod: %s", applet, strerror(errno)); @@ -145,10 +149,14 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode, } if (chowner && (st.st_uid != uid || st.st_gid != gid)) { - if ((type != inode_dir) && (st.st_nlink != 1)) { + if ((type != inode_dir) && (st.st_nlink > 1)) { eerror("%s: chown: %s %s", applet, "Too many hard links to", path); return -1; } + if (S_ISLNK(st.st_mode)) { + eerror("%s: chown: %s %s", applet, path, " is a symbolic link"); + return -1; + } einfo("%s: correcting owner", path); if (chown(path, uid, gid)) { eerror("%s: chown: %s", applet, strerror(errno));