ocfs2: take inode lock in ocfs2_iop_set/get_acl()
authorTariq Saeed <tariq.x.saeed@oracle.com>
Fri, 4 Sep 2015 22:44:34 +0000 (15:44 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 4 Sep 2015 23:54:41 +0000 (16:54 -0700)
This bug in mainline code is pointed out by Mark Fasheh.  When
ocfs2_iop_set_acl() and ocfs2_iop_get_acl() are entered from VFS layer,
inode lock is not held.  This seems to be regression from older kernels.
The patch is to fix that.

Orabug: 20189959
Signed-off-by: Tariq Saeed <tariq.x.saeed@oracle.com>
Reviewed-by: Mark Fasheh <mfasheh@suse.de>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ocfs2/acl.c

index c58a1bcfda0fdfa83f2a42169eb308580c759def..0cdf497c91efbb915512aceed2bf58acaa37fa1d 100644 (file)
@@ -284,7 +284,19 @@ int ocfs2_set_acl(handle_t *handle,
 
 int ocfs2_iop_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 {
-       return ocfs2_set_acl(NULL, inode, NULL, type, acl, NULL, NULL);
+       struct buffer_head *bh = NULL;
+       int status = 0;
+
+       status = ocfs2_inode_lock(inode, &bh, 1);
+       if (status < 0) {
+               if (status != -ENOENT)
+                       mlog_errno(status);
+               return status;
+       }
+       status = ocfs2_set_acl(NULL, inode, bh, type, acl, NULL, NULL);
+       ocfs2_inode_unlock(inode, 1);
+       brelse(bh);
+       return status;
 }
 
 struct posix_acl *ocfs2_iop_get_acl(struct inode *inode, int type)
@@ -292,19 +304,21 @@ struct posix_acl *ocfs2_iop_get_acl(struct inode *inode, int type)
        struct ocfs2_super *osb;
        struct buffer_head *di_bh = NULL;
        struct posix_acl *acl;
-       int ret = -EAGAIN;
+       int ret;
 
        osb = OCFS2_SB(inode->i_sb);
        if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
                return NULL;
-
-       ret = ocfs2_read_inode_block(inode, &di_bh);
-       if (ret < 0)
+       ret = ocfs2_inode_lock(inode, &di_bh, 0);
+       if (ret < 0) {
+               if (ret != -ENOENT)
+                       mlog_errno(ret);
                return ERR_PTR(ret);
+       }
 
        acl = ocfs2_get_acl_nolock(inode, type, di_bh);
 
+       ocfs2_inode_unlock(inode, 0);
        brelse(di_bh);
-
        return acl;
 }