From e5d36040a86457ed66782496d79136d6bdc4d9a3 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 22 Feb 2018 18:00:11 -0500 Subject: [PATCH] Naively ignore hard links to avoid security mishaps. If an attacker can introduce a hard link into a directory with a default ACL, then he may be able to trick the user into applying that default ACL to the target of the hard link which lives somewhere else entirely. That can be exploited to gain access to the user's files, and is hard to detect. To avoid that problem entirely, great care must be taken. For now, a naive check of the target path is implemented to ensure that (at the start of the routine) it has only one name on the filesystem. This still admits a race condition, but is an improvement. The new behavior is now documented in the man page, and a test has been added to ensure that pre-existing hard links are ignored. --- doc/man/apply-default-acl.1 | 4 +-- run-tests.sh | 19 ++++++++++++++ src/apply-default-acl.c | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/doc/man/apply-default-acl.1 b/doc/man/apply-default-acl.1 index 75c7a75..bfbb724 100644 --- a/doc/man/apply-default-acl.1 +++ b/doc/man/apply-default-acl.1 @@ -11,8 +11,8 @@ apply-default-acl \- Apply default POSIX ACLs to files and directories. .P If the directory containing \fIpath\fR has a default ACL, the ACL on -\fIpath\fR is replaced with that default. Symbolic links are not -followed. +\fIpath\fR is replaced with that default. Neither symbolic nor hard +links are followed. .P By default, a heuristic is used to determine whether or not the diff --git a/run-tests.sh b/run-tests.sh index d055560..7f7ba8f 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -730,3 +730,22 @@ other::r-- EOF ) compare + + +# Ensure that hard links are ignored. +TESTNUM=30 +TARGET="${TESTDIR}/foo" +LINK2TARGET="${TESTDIR}/bar" +touch "${TARGET}" +ln "${TARGET}" "${LINK2TARGET}" +setfacl --default --modify user:${USERS[0]}:rwx "${TESTDIR}" +"${BIN}" "${LINK2TARGET}" +ACTUAL=$( getfacl --omit-header "${TARGET}" ) +EXPECTED=$(cat <