summaryrefslogtreecommitdiffstats
path: root/fs/overlayfs/util.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2023-11-20 20:02:11 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2023-11-25 02:54:14 -0500
commita8b0026847b8c43445c921ad2c85521c92eb175f (patch)
tree39078ede8594fab57ee0486e522655df86cb131f /fs/overlayfs/util.c
parentdbd4540df2b2857a91593754275c02f3e415fc30 (diff)
downloadlinux-stable-a8b0026847b8c43445c921ad2c85521c92eb175f.tar.gz
linux-stable-a8b0026847b8c43445c921ad2c85521c92eb175f.tar.bz2
linux-stable-a8b0026847b8c43445c921ad2c85521c92eb175f.zip
rename(): avoid a deadlock in the case of parents having no common ancestor
... and fix the directory locking documentation and proof of correctness. Holding ->s_vfs_rename_mutex *almost* prevents ->d_parent changes; the case where we really don't want it is splicing the root of disconnected tree to somewhere. In other words, ->s_vfs_rename_mutex is sufficient to stabilize "X is an ancestor of Y" only if X and Y are already in the same tree. Otherwise it can go from false to true, and one can construct a deadlock on that. Make lock_two_directories() report an error in such case and update the callers of lock_rename()/lock_rename_child() to handle such errors. And yes, such conditions are not impossible to create ;-/ Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/overlayfs/util.c')
-rw-r--r--fs/overlayfs/util.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index 50a201e9cd39..7b667345e673 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -1198,12 +1198,17 @@ void ovl_nlink_end(struct dentry *dentry)
int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir)
{
+ struct dentry *trap;
+
/* Workdir should not be the same as upperdir */
if (workdir == upperdir)
goto err;
/* Workdir should not be subdir of upperdir and vice versa */
- if (lock_rename(workdir, upperdir) != NULL)
+ trap = lock_rename(workdir, upperdir);
+ if (IS_ERR(trap))
+ goto err;
+ if (trap)
goto err_unlock;
return 0;