Commit bb2314b4 authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Al Viro

fs: Allow unprivileged linkat(..., AT_EMPTY_PATH) aka flink

Every now and then someone proposes a new flink syscall, and this spawns
a long discussion of whether it would be a security problem.  I think
that this is missing the point: flink is *already* allowed without
privilege as long as /proc is mounted -- it's called AT_SYMLINK_FOLLOW.

Now that O_TMPFILE is here, the ability to create a file with O_TMPFILE,
write it, and link it in is very convenient.  The only problem is that
it requires that /proc be mounted so that you can do:

linkat(AT_FDCWD, "/proc/self/fd/<tmpfd>", dfd, path, AT_SYMLINK_NOFOLLOW)

This sucks -- it's much nicer to do:

linkat(tmpfd, "", dfd, path, AT_EMPTY_PATH)

Let's allow it.

If this turns out to be excessively scary, it we could instead require
that the inode in question be I_LINKABLE, but this seems pointless given
the /proc situation
Signed-off-by: default avatarAndy Lutomirski <luto@amacapital.net>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent e305f48b
...@@ -3671,15 +3671,11 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname, ...@@ -3671,15 +3671,11 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0) if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0)
return -EINVAL; return -EINVAL;
/* /*
* To use null names we require CAP_DAC_READ_SEARCH * Using empty names is equivalent to using AT_SYMLINK_FOLLOW
* This ensures that not everyone will be able to create * on /proc/self/fd/<fd>.
* handlink using the passed filedescriptor.
*/ */
if (flags & AT_EMPTY_PATH) { if (flags & AT_EMPTY_PATH)
if (!capable(CAP_DAC_READ_SEARCH))
return -ENOENT;
how = LOOKUP_EMPTY; how = LOOKUP_EMPTY;
}
if (flags & AT_SYMLINK_FOLLOW) if (flags & AT_SYMLINK_FOLLOW)
how |= LOOKUP_FOLLOW; how |= LOOKUP_FOLLOW;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment