当 cd 到 /tmp 中的符号链接目录(值为 700 并且由普通用户拥有)时,权限被拒绝

Tim*_*Tim 4 permissions directory cd-command symlink linux-kernel

问题:

\n\n

当我能够切换到目录本身时,为什么我无法 cd 进入具有 700 权限、由普通用户(作为 root)拥有的符号链接目录?

\n\n

例子:

\n\n
ttucker@plato:/tmp# uname -a\nLinux plato 4.4.0-140-generic #166~14.04.1-Ubuntu SMP Sat Nov 17 01:52:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux\n\nttucker@plato:/tmp$ whoami\nttucker\nttucker@plato:/tmp$ mkdir -v test_dir\nmkdir: created directory \xe2\x80\x98test_dir\xe2\x80\x99\nttucker@plato:/tmp$ chmod -v 700 test_dir\nmode of \xe2\x80\x98test_dir\xe2\x80\x99 changed from 0775 (rwxrwxr-x) to 0700 (rwx------)\nttucker@plato:/tmp$ ln -s -v test_dir/ test_sym\n\xe2\x80\x98test_sym\xe2\x80\x99 -> \xe2\x80\x98test_dir/\xe2\x80\x99\nttucker@plato:/tmp$ ls -ld test_*\ndrwx------ 2 ttucker ttucker 4096 Mar 21 10:29 test_dir\nlrwxrwxrwx 1 ttucker ttucker    9 Mar 21 10:29 test_sym -> test_dir/\n\nttucker@plato:/tmp$ sudo su -\nroot@plato:~# whoami\nroot\nroot@plato:~# cd /tmp/test_sym/\n-su: cd: /tmp/test_sym/: Permission denied\nroot@plato:~# cd /tmp/test_dir/\nroot@plato:/tmp/test_dir# pwd\n/tmp/test_dir\n
Run Code Online (Sandbox Code Playgroud)\n\n

其他信息:

\n\n

Redhat 上也会出现这种情况。

\n

Tim*_*Tim 5

我在这里找不到答案,所以我想将其放在这里供其他人使用。

回答:

这里的行为取决于 /proc/sys/fs/protected_symlinks 的设置

root@plato:/tmp# cat /proc/sys/fs/protected_symlinks 
1
Run Code Online (Sandbox Code Playgroud)

也可以看看:

RedHat Bug 1034239 - root 无法遵循其他用户拥有的符号链接

https://bugzilla.redhat.com/show_bug.cgi?id=1034239