Skip to content

Commit

Permalink
ufs: fix deadlocks introduced by sb mutex merge
Browse files Browse the repository at this point in the history
Commit 0244756 ("ufs: sb mutex merge + mutex_destroy") introduces
deadlocks in ufs_new_inode() and ufs_free_inode().
Most callers of that functions acqure the mutex by themselves and
ufs_{new,free}_inode() do that via lock_ufs(),
i.e we have an unavoidable double lock.

The patch proposes to resolve the issue by making sure that
ufs_{new,free}_inode() are not called with the mutex held.

Found by Linux Driver Verification project (linuxtesting.org).

Cc: [email protected] # 3.16
Signed-off-by: Alexey Khoroshilov <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
khoroshilov authored and Al Viro committed Sep 7, 2014
1 parent 81b6b06 commit 9ef7db7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
7 changes: 2 additions & 5 deletions fs/ufs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,6 @@ void ufs_evict_inode(struct inode * inode)
invalidate_inode_buffers(inode);
clear_inode(inode);

if (want_delete) {
lock_ufs(inode->i_sb);
ufs_free_inode (inode);
unlock_ufs(inode->i_sb);
}
if (want_delete)
ufs_free_inode(inode);
}
14 changes: 6 additions & 8 deletions fs/ufs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ static int ufs_symlink (struct inode * dir, struct dentry * dentry,
if (l > sb->s_blocksize)
goto out_notlocked;

lock_ufs(dir->i_sb);
inode = ufs_new_inode(dir, S_IFLNK | S_IRWXUGO);
err = PTR_ERR(inode);
if (IS_ERR(inode))
goto out;
goto out_notlocked;

lock_ufs(dir->i_sb);
if (l > UFS_SB(sb)->s_uspi->s_maxsymlinklen) {
/* slow symlink */
inode->i_op = &ufs_symlink_inode_operations;
Expand Down Expand Up @@ -181,20 +181,19 @@ static int ufs_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode)
struct inode * inode;
int err;

lock_ufs(dir->i_sb);
inode_inc_link_count(dir);

inode = ufs_new_inode(dir, S_IFDIR|mode);
err = PTR_ERR(inode);
if (IS_ERR(inode))
goto out_dir;
return PTR_ERR(inode);

inode->i_op = &ufs_dir_inode_operations;
inode->i_fop = &ufs_dir_operations;
inode->i_mapping->a_ops = &ufs_aops;

inode_inc_link_count(inode);

lock_ufs(dir->i_sb);
inode_inc_link_count(dir);

err = ufs_make_empty(inode, dir);
if (err)
goto out_fail;
Expand All @@ -212,7 +211,6 @@ static int ufs_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode)
inode_dec_link_count(inode);
inode_dec_link_count(inode);
iput (inode);
out_dir:
inode_dec_link_count(dir);
unlock_ufs(dir->i_sb);
goto out;
Expand Down

0 comments on commit 9ef7db7

Please sign in to comment.