Skip to contentSkip to conversation

fs: fix: second lock in function d_prune_aliases().

PATCH NAK YANG LI 4 participants 4 messages Dec 30, 2020 VFS

lore
Share & tools
lore

YANG LI

author
#0 lore raw

PATCH 1/1 fs: fix: second lock in function d_prune_aliases().

Goto statement jumping will cause lock to be executed again without executing unlock, placing the lock statement in front of goto label to fix this problem.

---
 fs/dcache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dcache.c +1 -1
index 97e81a8..bf38446 100644
@@ -1050,6 +1050,6 @@ void d_prune_aliases(struct inode *inode)
 {
 	struct dentry *dentry;
-restart:
 	spin_lock(&inode->i_lock);
+restart:
 	hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
 		spin_lock(&dentry->d_lock);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 15 lines · YANG LI

Goto statement jumping will cause lock to be executed again without executing unlock, placing the lock statement in front of goto label to fix this problem.

---
  fs/dcache.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
fs/dcache.c +0 -0
index 97e81a8..bf38446 100644

fs/dcache.c void d_prune_aliases(struct inode *inode) · line 1052

Quoted 4 lines
fs/dcache.c +0 -1
@@ -1050,6 +1050,6 @@ void d_prune_aliases(struct inode *inode)
   {
      struct dentry *dentry;
-restart:
      spin_lock(&inode->i_lock);

This inode lock should be released at __dentry_kill->dentry_unlink_inode.

Regards,
Hao Lee

Quoted 4 lines
fs/dcache.c +1 -0
+restart:
      hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
          spin_lock(&dentry->d_lock);
maintainer NAK
#2 lore raw
In reply to YANG LI
Quoted 6 lines · YANG LI

Goto statement jumping will cause lock to be executed again without executing unlock, placing the lock statement in front of goto label to fix this problem.

I am sorry, but have you even attempted to trigger that codepath? Just to test your patch...

FWIW, the patch is completely broken. Obviously so, since you have dput() done just before goto restart and dput() in very much capable of blocking. It should never be called with spinlocks held. And if you look at __dentry_kill() (well, dentry_unlink_inode() called by __dentry_kill()), you will see that it bloody well *DOES* drop inode->i_lock.

NAK.

#3 lore raw
Quoted 11 lines · Al Viro
Quoted 6 lines · YANG LI

Goto statement jumping will cause lock to be executed again without executing unlock, placing the lock statement in front of goto label to fix this problem.

I am sorry, but have you even attempted to trigger that codepath? Just to test your patch...

Quoted 6 lines

FWIW, the patch is completely broken. Obviously so, since you have dput() done just before goto restart and dput() in very much capable of blocking. It should never be called with spinlocks held. And if you look at __dentry_kill() (well, dentry_unlink_inode() called by __dentry_kill()), you will see that it bloody well *DOES* drop inode->i_lock.

Not only that, but the function is even _annotated_ to that effect. So this 'abaci' tool you have isn't even capable of the bare minimum.