mount: create not working symlink when unmounting fails
authorRafał Miłecki <rafal@milecki.pl>
Fri, 16 Feb 2018 15:01:12 +0000 (16:01 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Wed, 21 Feb 2018 08:34:45 +0000 (09:34 +0100)
commit1b62489ceaf0270887d60db13b103c2b8bee33a1
treedd6b4f071894c7ada9e823a0bce7a1ad0b579de8
parente77dc6d122ea398e319c8cc310077deb4b096362
mount: create not working symlink when unmounting fails

If device disappears but there is still some application trying to
access it, unmounting will fail with the EBUSY errno. Unlinking
/tmp/mounts/<symlink> would succeed but things could go wrong depending
on the application accessing that path.

If some app doesn't check if /tmp/mounts/<symlink> exists it could just
create it and start writing to it filling RAM instead of saving data to
a mounted drive.

Moreover the next time mountd tries to create that symlink it will fail
because there will be already a directory under that path. Things could
go even worse once mountd fires /sbin/hotplug-call and other apps start
using /tmp/mounts/<symlink> believing there's a mounteg storage there.

To fix this, detect failed umount call and replace /tmp/mounts/<symlink>
with a new symlink pointing to the not existing file. That will prevent
applications from re-creating that directory and writing to it filling
the RAM.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
mount.c