Re: Hard link creation witout write access

Taylor R Campbell <[email protected]> Thu, 7 Sep 2023 12:13:22 +0000
Newsgroups gmane.os.netbsd.devel.security
Message-ID <[email protected]>
> Date: Thu, 7 Sep 2023 07:46:48 -0400 (EDT)
> From: Mouse <[email protected]>
> 
> > Today I learned that you can create hard links to a file you don't
> > own and can't write to or even read from:
> 
> > $ su -l root -c 'touch /tmp/foo && chmod 600 /tmp/foo'
> > $ ln /tmp/foo /tmp/bar
> 
> > This strikes me as bonkers and a likely source of security issues.
> 
> What issues?  The only one I can see is that it allows anyone who can
> write to any directory on that filesystem to cause the file to stick
> around after its original name is unlinked.  That strikes me as a
> non-hazard.
> 
> Do you see potential damage from that, or do you see some additional
> threat?

Requires extra care to prevent things like this:

ln /etc/motd /var/mail/mouse
echo hello world | mail.local mouse

It's surprising to me that you can modify a file -- changing its link
count, even if you don't consider creating another (non-symbolic)
directory link pointing to it to be modifying it -- that you don't own
and don't have write access to.  Things that are surprising like that
are likely sources of security issues.

What's a _legitimate_ use case for this that can't be done with
symlinks?