From: David Michael Date: Tue, 26 Feb 2019 18:31:28 +0000 (-0500) Subject: test-fs-util: test chase_symlinks with user-owned dirs X-Git-Tag: v242-rc1~208^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a2fe6ed649fc68cb71ba7700e0ca72625ff51cb;p=thirdparty%2Fsystemd.git test-fs-util: test chase_symlinks with user-owned dirs This verifies the fix for the issue described in: https://github.com/systemd/systemd/pull/11820 --- diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index e049abc4a40..f0f015056e2 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -154,6 +154,30 @@ static void test_chase_symlinks(void) { assert_se(path_equal(result, q)); result = mfree(result); + /* Paths underneath the "root" with different UIDs while using CHASE_SAFE */ + + if (geteuid() == 0) { + p = strjoina(temp, "/user"); + assert_se(mkdir(p, 0755) >= 0); + assert_se(chown(p, UID_NOBODY, GID_NOBODY) >= 0); + + q = strjoina(temp, "/user/root"); + assert_se(mkdir(q, 0755) >= 0); + + p = strjoina(q, "/link"); + assert_se(symlink("/", p) >= 0); + + /* Fail when user-owned directories contain root-owned subdirectories. */ + r = chase_symlinks(p, temp, CHASE_SAFE, &result); + assert_se(r == -ENOLINK); + result = mfree(result); + + /* Allow this when the user-owned directories are all in the "root". */ + r = chase_symlinks(p, q, CHASE_SAFE, &result); + assert_se(r > 0); + result = mfree(result); + } + /* Paths using . */ r = chase_symlinks("/etc/./.././", NULL, 0, &result);