]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
configfs: fix a deadlock in configfs_symlink()
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 3 Aug 2019 15:51:18 +0000 (11:51 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 10 Dec 2019 18:01:20 +0000 (18:01 +0000)
commit9c64678adf6713cb86d5111c534f2d40805f0502
treee0f8c341cfeacf9a64a2a5dc3a1733293e10af4c
parent0d589fdceb28b3d39523d1dd0d4ad959efb57d0f
configfs: fix a deadlock in configfs_symlink()

commit 351e5d869e5ac10cb40c78b5f2d7dfc816ad4587 upstream.

Configfs abuses symlink(2).  Unlike the normal filesystems, it
wants the target resolved at symlink(2) time, like link(2) would've
done.  The problem is that ->symlink() is called with the parent
directory locked exclusive, so resolving the target inside the
->symlink() is easily deadlocked.

Short of really ugly games in sys_symlink() itself, all we can
do is to unlock the parent before resolving the target and
relock it after.  However, that invalidates the checks done
by the caller of ->symlink(), so we have to
* check that dentry is still where it used to be
(it couldn't have been moved, but it could've been unhashed)
* recheck that it's still negative (somebody else
might've successfully created a symlink with the same name
while we were looking the target up)
* recheck the permissions on the parent directory.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christoph Hellwig <hch@lst.de>
[bwh: Backported to 3.16: open-code inode_{,un}lock()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/configfs/symlink.c