Skip to content

Commit a03e283

Browse files
ebiedermAl Viro
authored andcommitted
dcache: Reduce the scope of i_lock in d_splice_alias
i_lock is only needed until __d_find_any_alias calls dget on the alias dentry. After that the reference to new ensures that dentry_kill and d_delete will not remove the inode from the dentry, and remove the dentry from the inode->d_entry list. The inode i_lock came to be held over the the __d_move calls in d_splice_alias through a series of introduction of locks with increasing smaller scope. First it was the dcache_lock, then it was the dcache_inode_lock, and finally inode->i_lock. Furthermore inode->i_lock is not held over any other calls to d_move or __d_move so it can not provide any meaningful rename protection. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent cde93be commit a03e283

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎fs/dcache.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,7 @@ struct dentry *d_ancestor(struct dentry *p1, struct dentry *p2)
27182718
* This helper attempts to cope with remotely renamed directories
27192719
*
27202720
* It assumes that the caller is already holding
2721-
* dentry->d_parent->d_inode->i_mutex, inode->i_lock and rename_lock
2721+
* dentry->d_parent->d_inode->i_mutex, and rename_lock
27222722
*
27232723
* Note: If ever the locking in lock_rename() changes, then please
27242724
* remember to update this too...
@@ -2744,7 +2744,6 @@ static int __d_unalias(struct inode *inode,
27442744
__d_move(alias, dentry, false);
27452745
ret = 0;
27462746
out_err:
2747-
spin_unlock(&inode->i_lock);
27482747
if (m2)
27492748
mutex_unlock(m2);
27502749
if (m1)
@@ -2790,10 +2789,11 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
27902789
if (S_ISDIR(inode->i_mode)) {
27912790
struct dentry *new = __d_find_any_alias(inode);
27922791
if (unlikely(new)) {
2792+
/* The reference to new ensures it remains an alias */
2793+
spin_unlock(&inode->i_lock);
27932794
write_seqlock(&rename_lock);
27942795
if (unlikely(d_ancestor(new, dentry))) {
27952796
write_sequnlock(&rename_lock);
2796-
spin_unlock(&inode->i_lock);
27972797
dput(new);
27982798
new = ERR_PTR(-ELOOP);
27992799
pr_warn_ratelimited(
@@ -2812,7 +2812,6 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
28122812
} else {
28132813
__d_move(new, dentry, false);
28142814
write_sequnlock(&rename_lock);
2815-
spin_unlock(&inode->i_lock);
28162815
security_d_instantiate(new, inode);
28172816
}
28182817
iput(inode);

0 commit comments

Comments
 (0)