]> git.baikalelectronics.ru Git - kernel.git/commit
ecryptfs: fix unlink and rmdir in face of underlying fs modifications
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 3 Nov 2019 17:07:15 +0000 (12:07 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 10 Nov 2019 16:57:44 +0000 (11:57 -0500)
commit68d4909847edcc240ccd312c04e1634f6b8a9bcb
treeb7af3ca1f5cfa9966fe1644b7d82d255a1db6f53
parentd26b270717ff338eba3f6b90b3beb7c05cf38d0e
ecryptfs: fix unlink and rmdir in face of underlying fs modifications

A problem similar to the one caught in commit cc655fa9aa19 ("ecryptfs_rename():
verify that lower dentries are still OK after lock_rename()") exists for
unlink/rmdir as well.

Instead of playing with dget_parent() of underlying dentry of victim
and hoping it's the same as underlying dentry of our directory,
do the following:
        * find the underlying dentry of victim
        * find the underlying directory of victim's parent (stable
since the victim is ecryptfs dentry and inode of its parent is
held exclusive by the caller).
        * lock the inode of dentry underlying the victim's parent
        * check that underlying dentry of victim is still hashed and
has the right parent - it can be moved, but it can't be moved to/from
the directory we are holding exclusive.  So while ->d_parent itself
might not be stable, the result of comparison is.

If the check passes, everything is fine - underlying directory is locked,
underlying victim is still a child of that directory and we can go ahead
and feed them to vfs_unlink().  As in the current mainline we need to
pin the underlying dentry of victim, so that it wouldn't go negative under
us, but that's the only temporary reference that needs to be grabbed there.
Underlying dentry of parent won't go away (it's pinned by the parent,
which is held by caller), so there's no need to grab it.

The same problem (with the same solution) exists for rmdir.  Moreover,
rename gets simpler and more robust with the same "don't bother with
dget_parent()" approach.

Fixes: cc655fa9aa1 "ecryptfs_rename(): verify that lower dentries are still OK after lock_rename()"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/ecryptfs/inode.c