简体   繁体   English

符号链接将“权限被拒绝”...给root

[英]Symlink giving “Permission denied”… to root

I wrote a simple script to automate creating a symbolic link. 我写了一个简单的脚本来自动创建一个符号链接。

#!/pseudo
today = "/tmp/" + date("Y-m-d")
exec("ln -sf " + today + " /tmp/today")

Simple enough; 很简单; get today's date and make a symlink. 得到今天的日期并制作符号链接。 Ideally run after midnight with -f so it just updates it in-place. 理想情况下,使用-f在午夜后运行,因此它只是就地更新它。

This works just fine! 这很好用! ...for my user. ...为我的用户。

xkeeper /tmp$ ls -ltr
drwxrwxrwx  xkeeper   xkeeper   2014-10-21
lrwxrwxrwx  xkeeper   xkeeper   today -> /tmp/2014-10-21/

xkeeper /tmp$ cd today
xkeeper /tmp/today$ cd ..

Notice that it works fine, all the permissions are world-readable, everything looks good. 请注意,它工作正常,所有权限都是世界可读的,一切看起来都不错。

But if someone else wants to use this link (we'll say, root, but any other user has this problem), something very strange happens: 但如果其他人想要使用这个链接(我们会说,root,但任何其他用户都有这个问题),会发生一些非常奇怪的事情:

root /tmp# cd today
bash: cd: today: Permission denied

I am at a complete loss as to why this is. 我完全不知道为什么会这样。 I've also tried creating the links with ln -s -n -f (not that " --no-dereferencing " is very well-explained), but the same issue appears. 我也尝试用ln -s -n -f创建链接(不是说“ --no-dereferencing ”非常好解释),但是出现了同样的问题。

Since /tmp usually has the sticky bit set, the access to /tmp/today is denied because of protected_symlinks . 由于/ tmp通常设置了粘滞位,因为protected_symlinks拒绝访问/ tmp / today。 You can disable this protection by setting 您可以通过设置禁用此保护

sysctl -w fs.protected_symlinks=0

protected_symlinks : protected_symlinks

A long-standing class of security issues is the symlink-based time-of-check-time-of-use race, most commonly seen in world-writable directories like /tmp. 长期存在的一类安全问题是基于符号链接的使用时间检查时间种族,最常见于/ tmp这样的世界可写目录。 The common method of exploitation of this flaw is to cross privilege boundaries when following a given symlink (ie a root process follows a symlink belonging to another user). 利用此缺陷的常用方法是在遵循给定符号链接时跨越特权边界(即根进程遵循属于另一个用户的符号链接)。 For a likely incomplete list of hundreds of examples across the years, please see: http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=/tmp 有关多年来数百个示例的可能不完整列表,请参阅: http//cve.mitre.org/cgi-bin/cvekey.cgi?keyword = / tmp

When set to "0", symlink following behavior is unrestricted. 设置为“0”时,符号链接跟随行为不受限制。

When set to "1" symlinks are permitted to be followed only when outside a sticky world-writable directory, or when the uid of the symlink and follower match, or when the directory owner matches the symlink's owner. 设置为“1”时,只有在粘性世界可写目录之外,或者符号链接和跟随符的uid匹配时,或者目录所有者与符号链接的所有者匹配时,才允许遵循符号链接。

This protection is based on the restrictions in Openwall and grsecurity. 这种保护基于Openwall和grsecurity的限制。

For further details check this . 有关详细信息,请查看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM