Skip to contentSkip to conversation

Fix reiserfs deadlock

PATCH In review Jan Kara 2 participants 2 messages Apr 21, 2006

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 Fix reiserfs deadlock

Hello!

the patch below fixes potential deadlock in reiserfs code. The problem
is we can sometimes return 1 even if we did not manage to find the xattr. Later we take the xattr lock because the function returned 1. But then the code in the error path of reiserfs_new_inode() checks i_default_acl and because it is not set it assumes we have not taken the lock and tries to retake it -> deadlock.
Jeff has larger rewrite of the xattr locking but it will take some
time before it will be accepted so this could be used as a temporary fix. Andrew, please apply.

Honza

Signature · 27 lines
Jan Kara <[email protected]>
SuSE CR Labs

reiserfs_cache_default_acl() should return whether we successfully found the
acl or not. We have to return correct value even if reiserfs_get_acl() returns
error code and not just 0. Otherwise callers such as reiserfs_mkdir() can
unnecessarily lock the xattrs and later functions such as reiserfs_new_inode()
fail to notice that we have already taken the lock and try to take it again
with obvious consequences.

Signed-off-by: Jan Kara <[email protected]>

diff -rupX /home/jack/.kerndiffexclude linux-2.6.5-SLES9_SP3_BRANCH/fs/reiserfs/xattr_acl.c linux-2.6.5-SLES9_SP3_BRANCH-1-reiser_xattr_fix/fs/reiserfs/xattr_acl.c
--- linux-2.6.5-SLES9_SP3_BRANCH/fs/reiserfs/xattr_acl.c	2006-01-21 03:02:06.000000000 +0100
+++ linux-2.6.5-SLES9_SP3_BRANCH-1-reiser_xattr_fix/fs/reiserfs/xattr_acl.c	2006-01-21 09:09:04.000000000 +0100
@@ -410,8 +410,10 @@ reiserfs_cache_default_acl (struct inode
         acl = reiserfs_get_acl (inode, ACL_TYPE_DEFAULT);
         reiserfs_read_unlock_xattrs (inode->i_sb);
         reiserfs_read_unlock_xattr_i (inode);
-        ret = acl ? 1 : 0;
+	if (!acl || IS_ERR(acl))
+		return 0;
         posix_acl_release (acl);
+	ret = 1;
     }
 
     return ret;
#1 lore raw
Quoted 15 lines · Jan Kara

reiserfs_cache_default_acl() should return whether we successfully found the acl or not. We have to return correct value even if reiserfs_get_acl() returns error code and not just 0. Otherwise callers such as reiserfs_mkdir() can unnecessarily lock the xattrs and later functions such as reiserfs_new_inode() fail to notice that we have already taken the lock and try to take it again with obvious consequences.

diff -rupX /home/jack/.kerndiffexclude linux-2.6.5-SLES9_SP3_BRANCH/fs/reiserfs/xattr_acl.c linux-2.6.5-SLES9_SP3_BRANCH-1-reiser_xattr_fix/fs/reiserfs/xattr_acl.c

fs/reiserfs/xattr_acl.c +0 -0
@@ -410,8 +410,10 @@ reiserfs_cache_default_acl (struct inode
         acl = reiserfs_get_acl (inode, ACL_TYPE_DEFAULT);

fs/reiserfs/xattr_acl.c reiserfs_cache_default_acl (struct inode · line 419

Quoted 10 lines
fs/reiserfs/xattr_acl.c +3 -1
         reiserfs_read_unlock_xattrs (inode->i_sb);
         reiserfs_read_unlock_xattr_i (inode);
-        ret = acl ? 1 : 0;
+	if (!acl || IS_ERR(acl))
+		return 0;
         posix_acl_release (acl);
+	ret = 1;
     }
 
     return ret;

Your email client did something ghastly to this patch. Please fix it.

I typed it in again. While I was there I structured it a bit more nicely.

fs/reiserfs/xattr_acl.c renamed from fs/reiserfs/xattr_acl.c~fix-reiserfs-deadlock +3 -2
@@ -408,8 +408,9 @@ int reiserfs_cache_default_acl(struct in
 		acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
 		reiserfs_read_unlock_xattrs(inode->i_sb);
 		reiserfs_read_unlock_xattr_i(inode);
-		ret = acl ? 1 : 0;
-		posix_acl_release(acl);
+		ret = (acl && !IS_ERR(acl));
+		if (ret)
+			posix_acl_release(acl);
 	}
 
 	return ret;

_