mount: forbid mount on path with symlinks
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Fri, 19 Jan 2018 17:28:38 +0000 (17:28 +0000)
committerAlan Jenkins <alan.christopher.jenkins@gmail.com>
Sat, 20 Jan 2018 22:06:34 +0000 (22:06 +0000)
commit25cd49647c83bacaee591afbc9b6fc047be66b58
tree1a7cf5e9f1bcbdb7b0d6ff8925398d2c0efa67cd
parent22bc57c58a3ad7570209e2ead6fa17e7d9b006cc
mount: forbid mount on path with symlinks

It was forbidden to create mount units for a symlink.  But the reason is
that the mount unit needs to know the real path that will appear in
/proc/self/mountinfo.  The kernel dereferences *all* the symlinks in the
path at mount time (I checked this with `mount -c` running under `strace`).

This will have no effect on most systems.  As recommended by docs, most
systems use /etc/fstab, as opposed to native mount unit files.
fstab-generator dereferences symlinks for backwards compatibility.

A relatively minor issue regarding Time Of Check / Time Of Use also exists
here.  I can't see how to get rid of it entirely.  If we pass an absolute
path to mount, the racing process can replace it with a symlink.  If we
chdir() to the mount point and pass ".", the racing process can move the
directory.  The latter might potentially be nicer, except that it breaks
WorkingDirectory=.

I'm not saying the race is relevant to security - I just want to consider
how bad the effect is.  Currently, it can make the mount unit active (and
hence the job return success), despite there never being a matching entry
in /proc/self/mountinfo.  This wart will be removed in the next commit;
i.e. it will make the mount unit fail instead.
src/core/automount.c
src/core/mount.c
src/core/unit.c
src/core/unit.h