Is this Ubuntu's mission?
|
|
|
Comments (31)
11 earlier comments in the full thread.
@gus, can you delete the file as root?
@ta: Yes.
can you then access it using the hard link
Yes.
I've just tested it. I have a seperate home partition., and I certainly can't create a hard link across partitions, I can create a soft link though. If I create a hard link within the same partition, I can delete the file and still access the file via the hard link.
Here's what I did.
As root, I copied a text file "qwerty" to /bin
cp /home/tracy/qwerty /bin
I then attempted to hard link to it as tracy in my home directory
tracy@annie:~$ ln /bin/qwerty /home/tracy/qwertylink ln: creating hard link `/home/tracy/qwertylink' => `/bin/qwerty': Invalid cross-device link tracy@annie:~$
and got the above error.
the following works fine
tracy@annie:~$ ln -s /bin/qwerty /home/tracy/qwertylink tracy@annie:~$ ls qwertylink qwertylink tracy@annie:~$
As root I can run
root@annie:/root# ln /bin/qwerty /root/qwertylink root@annie:/root# ls qwertylink qwertylink root@annie:/root#
and it works fine, creating ahardlink.
attempting the same thing into /home/tracy as root does not
root@annie:/root# ln /bin/qwerty /home/tracyr/qwertylinkr ln: creating hard link `/home/tracyr/qwertylinkr' => `/bin/qwerty': No such file or directory root@annie:/root#
So it is not possible to to create a hard link across filesystems.
now I can read the file /bin/qwerty from my home directory using the soft link, and I can read the file from the root user directory using the hard link.
But if I delete the file /bin/qwerty
root@annie:/bin# rm /bin/qwerty root@annie:/bin# ls qwerty ls: cannot access qwerty: No such file or directory root@annie:/bin#
and I attempt to read the file using the soft link in /home/tracy
tracy@annie:~$ cat qwertylink cat: qwertylink: No such file or directory tracy@annie:~$ ls qwertylink qwertylink
the link is still there. but the file it links to has gone.
but if I attempt the same things as root using the hardlink.
root@annie:/root# cat qwertylink chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} root@annie:/root#
if displays the contents of the now non existent file.
root@annie:/root# ls /bin/qwerty ls: cannot access /bin/qwerty: No such file or directory root@annie:/root#
So as the article describes, the inode continues to exist for as long as the hardlink exists, even if you create a new copy of the file.
root@annie:/bin# cp /home/tracy/qwerty /bin root@annie:/bin# cat /bin/qwerty chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}
root@annie:/root# cat qwertylink chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} root@annie:/root#
as you can see the hardlink in /root is still displaying the contents of the deleted file.
Here's what I did.
As root, I copied a text file "qwerty" to /bin
cp /home/tracy/qwerty /bin
I then attempted to hard link to it as tracy in my home directory
tracy@annie:~$ ln /bin/qwerty /home/tracy/qwertylink ln: creating hard link `/home/tracy/qwertylink' => `/bin/qwerty': Invalid cross-device link tracy@annie:~$
and got the above error.
the following works fine
tracy@annie:~$ ln -s /bin/qwerty /home/tracy/qwertylink tracy@annie:~$ ls qwertylink qwertylink tracy@annie:~$
As root I can run
root@annie:/root# ln /bin/qwerty /root/qwertylink root@annie:/root# ls qwertylink qwertylink root@annie:/root#
and it works fine, creating ahardlink.
attempting the same thing into /home/tracy as root does not
root@annie:/root# ln /bin/qwerty /home/tracyr/qwertylinkr ln: creating hard link `/home/tracyr/qwertylinkr' => `/bin/qwerty': No such file or directory root@annie:/root#
So it is not possible to to create a hard link across filesystems.
now I can read the file /bin/qwerty from my home directory using the soft link, and I can read the file from the root user directory using the hard link.
But if I delete the file /bin/qwerty
root@annie:/bin# rm /bin/qwerty root@annie:/bin# ls qwerty ls: cannot access qwerty: No such file or directory root@annie:/bin#
and I attempt to read the file using the soft link in /home/tracy
tracy@annie:~$ cat qwertylink cat: qwertylink: No such file or directory tracy@annie:~$ ls qwertylink qwertylink
the link is still there. but the file it links to has gone.
but if I attempt the same things as root using the hardlink.
root@annie:/root# cat qwertylink chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} root@annie:/root#
if displays the contents of the now non existent file.
root@annie:/root# ls /bin/qwerty ls: cannot access /bin/qwerty: No such file or directory root@annie:/root#
So as the article describes, the inode continues to exist for as long as the hardlink exists, even if you create a new copy of the file.
root@annie:/bin# cp /home/tracy/qwerty /bin root@annie:/bin# cat /bin/qwerty chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}
root@annie:/root# cat qwertylink chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} root@annie:/root#
as you can see the hardlink in /root is still displaying the contents of the deleted file.
@ta:
1. What kernel version?
2. Create hard link to root-owned file, without root privileges?
3. Delete said hard link, without root privileges?
1. What kernel version?
2. Create hard link to root-owned file, without root privileges?
3. Delete said hard link, without root privileges?
1. What kernel version? 2.6.31-17-generic (Ubuntu)
2. Create hard link to root-owned file, without root privileges?
root@annie:/bin# cp /xorg.conf.new /home/tracy root@annie:/bin# ls /home/tracy/xorg.conf.new /home/tracy/xorg.conf.new root@annie:/bin#
tracy@annie:~$ ln xorg.conf.new lin2rootowned tracy@annie:~$ ls link2rootowned ls: cannot access link2rootowned: No such file or directory tracy@annie:~$ ls lin2rootowned lin2rootowned tracy@annie:~$ cat lin2rootowned Section "ServerLayout" Identifier "X.org Configured" Screen 0 "Screen0" 0 0 InputDevice "Mouse0" "CorePointer" InputDevice "Keyboard0" "CoreKeyboard" Viewport 0 0 Depth 24
....removed to reduce size of posting ....
EndSubSection EndSection
3. Delete said hard link, without root privileges?
tracy@annie:~$ rm xorg.conf.new rm: remove write-protected regular file `xorg.conf.new'? y tracy@annie:~$ ls xorg.conf.new ls: cannot access xorg.conf.new: No such file or directory tracy@annie:~$ cat lin2rootowned Section "ServerLayout" Identifier "X.org Configured" Screen 0 "Screen0" 0 0 InputDevice "Mouse0" "CorePointer" InputDevice "Keyboard0" "CoreKeyboard" .....removed to reduce size of post EndSubSection EndSection
tracy@annie:~$
As you can see the hardlink can be created so long as the file and the hardlink are in the same filesystem, and the inode remains intact so long as the hardlink exists.
2. Create hard link to root-owned file, without root privileges?
root@annie:/bin# cp /xorg.conf.new /home/tracy root@annie:/bin# ls /home/tracy/xorg.conf.new /home/tracy/xorg.conf.new root@annie:/bin#
tracy@annie:~$ ln xorg.conf.new lin2rootowned tracy@annie:~$ ls link2rootowned ls: cannot access link2rootowned: No such file or directory tracy@annie:~$ ls lin2rootowned lin2rootowned tracy@annie:~$ cat lin2rootowned Section "ServerLayout" Identifier "X.org Configured" Screen 0 "Screen0" 0 0 InputDevice "Mouse0" "CorePointer" InputDevice "Keyboard0" "CoreKeyboard" Viewport 0 0 Depth 24
....removed to reduce size of posting ....
EndSubSection EndSection
3. Delete said hard link, without root privileges?
tracy@annie:~$ rm xorg.conf.new rm: remove write-protected regular file `xorg.conf.new'? y tracy@annie:~$ ls xorg.conf.new ls: cannot access xorg.conf.new: No such file or directory tracy@annie:~$ cat lin2rootowned Section "ServerLayout" Identifier "X.org Configured" Screen 0 "Screen0" 0 0 InputDevice "Mouse0" "CorePointer" InputDevice "Keyboard0" "CoreKeyboard" .....removed to reduce size of post EndSubSection EndSection
tracy@annie:~$
As you can see the hardlink can be created so long as the file and the hardlink are in the same filesystem, and the inode remains intact so long as the hardlink exists.
Quoting: At last [HYPERLINK@www.hackinglinuxexposed.com] this explains something that has always concerned me about the single partition that is the default for Ubuntu.All linux distributions have many user writable directories (/tmp, /var/tmp, /var/lock, /var/spool/samba) besides /home and no one places all these on separate partitions to avoid the mentioned vulnerability. Besides if the suid program was used to compromise the system, it stands to reason that the attacker can make copies etc. even across filesystems. If anything one would rather say that this is a hole in "ln".
@krisum, read the article, read what I did to demonstrate.
@tracyanne, I have read both. Read my comment again.
@tracyanne:
Okay, I tried your approach, and got your results. Try hard-linking a root-owned file in /sbin to something in /var/tmp, and see if you get my "create, but not delete" results.
So now, the big questions seem to be:
1. Why, in certain circumstances (yet-to-be determined), can an EUID without write access to an inode, create and remove references to it?
2. Why, in other circumstances, can an EUID without write access to an inode, create but not remove references to it?
3. What is/are the circumstance(s) to make the difference?
Okay, I tried your approach, and got your results. Try hard-linking a root-owned file in /sbin to something in /var/tmp, and see if you get my "create, but not delete" results.
So now, the big questions seem to be:
1. Why, in certain circumstances (yet-to-be determined), can an EUID without write access to an inode, create and remove references to it?
2. Why, in other circumstances, can an EUID without write access to an inode, create but not remove references to it?
3. What is/are the circumstance(s) to make the difference?
@krisum, you missed the point. It wasn't about user writeable directories. It was about Inodes staying active while there is a hardlink to the file that has been deleted, and the danger that potentially creates when there is a a single filesystem. the point was it is possible to open up the system to an attacker, by not removing the hardlinks, not what an attacker might be able do once they are in.
Ubuntu attempts to mitigate this by providing the user with the ability to create soft links, the "Create a Link" in the right mouse click menu. But that only works by assuming the user will never experiment with ln, remains ignorant of the commandline, and never uses the commandline. Not a likely prospect given the amount of advice in the ubuntu forums to "sudo something or another". It's security by obscurity.
Yes there probably is something wrong that needs fixing, but "ln" is doing exactly what it was designed to do, so I can't see that there is a bug there. Maybe there needs to be a system change in the way "ln" is used, maybe hardlinks should only be available to "root", and even the "adinistrator" group in suid should be excluded to stop the type of user Ubuntu are attempting stop, from using hard links.
Ubuntu attempts to mitigate this by providing the user with the ability to create soft links, the "Create a Link" in the right mouse click menu. But that only works by assuming the user will never experiment with ln, remains ignorant of the commandline, and never uses the commandline. Not a likely prospect given the amount of advice in the ubuntu forums to "sudo something or another". It's security by obscurity.
Yes there probably is something wrong that needs fixing, but "ln" is doing exactly what it was designed to do, so I can't see that there is a bug there. Maybe there needs to be a system change in the way "ln" is used, maybe hardlinks should only be available to "root", and even the "adinistrator" group in suid should be excluded to stop the type of user Ubuntu are attempting stop, from using hard links.
@tracyanne
edit: Also notice that if one were to replace a file with a new version using normal "cp" then all hard-links will also point to the new version. The problem will only be if one were to first remove the old file and then add the new file in the same place. Apt and other installers will normally do the former so there is no vulnerability in any case in the normal course of actions.
Quoting: you missed the point. It wasn't about user writeable directories. It was about Inodes staying active while there is a hardlink to the file that has been deleted, and the danger that potentially creates when there is a a single filesystem. the point was it is possible to open up the system to an attacker, by not removing the hardlinks, not what an attacker might be able do once they are in.Exactly, and that is why the real issue is user writable directories. If there are no user writable directories (edit: I mean in the same partition where suid programs reside) then an attacker cannot create hard-links in the first place to suid programs (though as I mentioned this point is likely to be moot if the system has been compromised) -- notice that for non-suid programs this does not matter in any case since a hard-link is functionally equivalent to a cp from attacker's POV. So what if an attacker makes a copy so that there is a supposedly vulnerable version still around? If someone were to make a copy of "apache", for example, it does not matter since the system will not be executing it during init etc -- it is completely a users binary which works such. Why do you think that a vulnerable version of "apache", for example, in user's home directory is a security hole? Of course, if the user were to run it explicitly then it might be a problem just like for any other vulnerable binaries in user's home. You are completely missing the point that the real problem is with suid programs. That is why the site makes an oblique reference to it in second recommendation "If they ran suid program scanners, they would have picked up this 'new' suid program" but does not make this point sufficiently clear. One of the recommendations that the site mentions is to have user writable directories /home, /tmp, /var/tmp on separate partitions, but as I mentioned a typical linux installation will have many more user writable directories and no distro I know of will offer separate partitions by default for all of those.
Quoting: Ubuntu attempts to mitigate this by providing the user with the ability to create soft links, the "Create a Link" in the right mouse click menu.No no, this has got to do nothing with Ubuntu or soft-links -- see above.
Quoting: Yes there probably is something wrong that needs fixing, but "ln" is doing exactly what it was designed to do, so I can't see that there is a bug there.If permission-wise "ln" were to behave like "cp" then users cannot create hard-links to programs having suid bit still set.
edit: Also notice that if one were to replace a file with a new version using normal "cp" then all hard-links will also point to the new version. The problem will only be if one were to first remove the old file and then add the new file in the same place. Apt and other installers will normally do the former so there is no vulnerability in any case in the normal course of actions.
gus I get the same results as you.
root@annie:/sbin# cp /home/tracy/qwerty /sbin/qwerty root@annie:/sbin#
tracy@annie:~$ cd /var/tmp tracy@annie:/var/tmp$ ln /sbin/qwerty qwertylink tracy@annie:/var/tmp$ ls qwertylink qwertylink tracy@annie:/var/tmp$ cat qwertylink chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} tracy@annie:/var/tmp$ rm /sbin/qwerty rm: remove write-protected regular file `/sbin/qwerty'? y rm: cannot remove `/sbin/qwerty': Permission denied tracy@annie:/var/tmp$ rm qwertylink rm: remove write-protected regular file `qwertylink'? y rm: cannot remove `qwertylink': Operation not permitted tracy@annie:/var/tmp$
root@annie:/sbin# rm /var/tmp/qwertylink root@annie:/sbin# rm /sbin/qwerty root@annie:/sbin#
root@annie:/sbin# cp /home/tracy/qwerty /sbin/qwerty root@annie:/sbin#
tracy@annie:~$ cd /var/tmp tracy@annie:/var/tmp$ ln /sbin/qwerty qwertylink tracy@annie:/var/tmp$ ls qwertylink qwertylink tracy@annie:/var/tmp$ cat qwertylink chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{}chapter{Bc,sfsd fsdfhjgdsjf gjhfdg}chapter{} tracy@annie:/var/tmp$ rm /sbin/qwerty rm: remove write-protected regular file `/sbin/qwerty'? y rm: cannot remove `/sbin/qwerty': Permission denied tracy@annie:/var/tmp$ rm qwertylink rm: remove write-protected regular file `qwertylink'? y rm: cannot remove `qwertylink': Operation not permitted tracy@annie:/var/tmp$
root@annie:/sbin# rm /var/tmp/qwertylink root@annie:/sbin# rm /sbin/qwerty root@annie:/sbin#
@gus3
Quoting: 1. Why, in certain circumstances (yet-to-be determined), can an EUID without write access to an inode, create and remove references to it?If the user has write permissions for the target directory e.g. /var/tmp or /home. For creating links the permissions of the source do not matter (holds for both hard-links and symlinks). It only comes into play when using that link.
Quoting: 2. Why, in other circumstances, can an EUID without write access to an inode, create but not remove references to it?Because /var/tmp or /tmp have sticky perms (1777) so only the user owning a file/link can remove that file/link. However, if the user has normal write perms like in /home/user or any directory without sticky bit then remove will be fine just for any other normal files. The ownership of symlink itself is stored separately while for a hardlink it is the same as that of the source.
@krisum:
That's the scenario I was starting to see in my mind's eye. According to my research, it's been that way for a long time in Unix, and Linux seems to have carried on with that "tradition." The problem (with security implications) is that, unlike the inode permissions, the inode reference count is not subject to the effective UID of a process.
...which leads to the next question: What are the implications of restricting reference count alterations to the permissions on the inode? Or, more succinctly, "why can someone without write permission on a file create a hard link to it?"
Sadly, the materials available to me do not explain this.
That's the scenario I was starting to see in my mind's eye. According to my research, it's been that way for a long time in Unix, and Linux seems to have carried on with that "tradition." The problem (with security implications) is that, unlike the inode permissions, the inode reference count is not subject to the effective UID of a process.
...which leads to the next question: What are the implications of restricting reference count alterations to the permissions on the inode? Or, more succinctly, "why can someone without write permission on a file create a hard link to it?"
Sadly, the materials available to me do not explain this.
Quoting: Or, more succinctly, "why can someone without write permission on a file create a hard link to it?"That holds for copy too i.e. someone without write permission on a file can certainly create a copy of it as long as the user has write permissions on the target directory. However, the copy comes with permissions of the user as against that of the source as in hardlink. I think that if "ln" were to behave more like "cp" especially for suid programs, then security-wise it will be okay (alternatively just disallow creating hardlinks to suid programs if having own permissions for hardlink is not possible). I guess linux would be following the POSIX specifications in this. No idea of the implications of this change though.
Copying doesn't alter the file metadata, except (perhaps) the atime.
I had a blurb here about removing read permissions on programs, but a quick test revealed that unreadable files can't be dlopen()'ed, and dynamic linking fails. Funnily enough, removing execute permissions doesn't inhibit dynamic linking.
It's times like this that I remind myself it's all ones and zeros, and their meaning depends entirely on the context. Sigh.
I had a blurb here about removing read permissions on programs, but a quick test revealed that unreadable files can't be dlopen()'ed, and dynamic linking fails. Funnily enough, removing execute permissions doesn't inhibit dynamic linking.
It's times like this that I remind myself it's all ones and zeros, and their meaning depends entirely on the context. Sigh.
Quoting: Copying doesn't alter the file metadata, except (perhaps) the atime.Certainly changes the owner and suid bits.
Not on the original.
Post a comment
A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.
Your message:Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help
Sign up and post (it is free) or Log in and post
