Skip to content

Commit 04f5224

Browse files
ukernelgregkh
authored andcommitted
ceph: fix recursion between ceph_set_acl() and __ceph_setattr()
commit 8179a101eb5f4ef0ac9a915fcea9a9d3109efa90 upstream. ceph_set_acl() calls __ceph_setattr() if the setacl operation needs to modify inode's i_mode. __ceph_setattr() updates inode's i_mode, then calls posix_acl_chmod(). The problem is that __ceph_setattr() calls posix_acl_chmod() before sending the setattr request. The get_acl() call in posix_acl_chmod() can trigger a getxattr request. The reply of the getxattr request can restore inode's i_mode to its old value. The set_acl() call in posix_acl_chmod() sees old value of inode's i_mode, so it calls __ceph_setattr() again. Cc: stable@vger.kernel.org # needs backporting for < 4.9 Link: http://tracker.ceph.com/issues/19688 Reported-by: Jerry Lee <leisurelysw24@gmail.com> Signed-off-by: "Yan, Zheng" <zyan@redhat.com> Reviewed-by: Jeff Layton <jlayton@redhat.com> Tested-by: Luis Henriques <lhenriques@suse.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com> [luis: introduce __ceph_setattr() and make ceph_set_acl() call it, as suggested by Yan.] Signed-off-by: Luis Henriques <lhenriques@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: “Yan, Zheng” <zyan@redhat.com>
1 parent 0e9e19a commit 04f5224

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

fs/ceph/acl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)
128128
if (new_mode != old_mode) {
129129
newattrs.ia_mode = new_mode;
130130
newattrs.ia_valid = ATTR_MODE;
131-
ret = ceph_setattr(dentry, &newattrs);
131+
ret = __ceph_setattr(dentry, &newattrs);
132132
if (ret)
133133
goto out_dput;
134134
}
@@ -138,7 +138,7 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)
138138
if (new_mode != old_mode) {
139139
newattrs.ia_mode = old_mode;
140140
newattrs.ia_valid = ATTR_MODE;
141-
ceph_setattr(dentry, &newattrs);
141+
__ceph_setattr(dentry, &newattrs);
142142
}
143143
goto out_dput;
144144
}

fs/ceph/inode.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ static const struct inode_operations ceph_symlink_iops = {
17731773
/*
17741774
* setattr
17751775
*/
1776-
int ceph_setattr(struct dentry *dentry, struct iattr *attr)
1776+
int __ceph_setattr(struct dentry *dentry, struct iattr *attr)
17771777
{
17781778
struct inode *inode = d_inode(dentry);
17791779
struct ceph_inode_info *ci = ceph_inode(inode);
@@ -1975,11 +1975,6 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr)
19751975
if (inode_dirty_flags)
19761976
__mark_inode_dirty(inode, inode_dirty_flags);
19771977

1978-
if (ia_valid & ATTR_MODE) {
1979-
err = posix_acl_chmod(inode, attr->ia_mode);
1980-
if (err)
1981-
goto out_put;
1982-
}
19831978

19841979
if (mask) {
19851980
req->r_inode = inode;
@@ -1993,13 +1988,23 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr)
19931988
ceph_cap_string(dirtied), mask);
19941989

19951990
ceph_mdsc_put_request(req);
1996-
if (mask & CEPH_SETATTR_SIZE)
1997-
__ceph_do_pending_vmtruncate(inode);
19981991
ceph_free_cap_flush(prealloc_cf);
1992+
1993+
if (err >= 0 && (mask & CEPH_SETATTR_SIZE))
1994+
__ceph_do_pending_vmtruncate(inode);
1995+
19991996
return err;
2000-
out_put:
2001-
ceph_mdsc_put_request(req);
2002-
ceph_free_cap_flush(prealloc_cf);
1997+
}
1998+
1999+
int ceph_setattr(struct dentry *dentry, struct iattr *attr)
2000+
{
2001+
int err;
2002+
2003+
err = __ceph_setattr(dentry, attr);
2004+
2005+
if (err >= 0 && (attr->ia_valid & ATTR_MODE))
2006+
err = posix_acl_chmod(d_inode(dentry), attr->ia_mode);
2007+
20032008
return err;
20042009
}
20052010

fs/ceph/super.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ static inline int ceph_do_getattr(struct inode *inode, int mask, bool force)
788788
return __ceph_do_getattr(inode, NULL, mask, force);
789789
}
790790
extern int ceph_permission(struct inode *inode, int mask);
791+
extern int __ceph_setattr(struct dentry *dentry, struct iattr *attr);
791792
extern int ceph_setattr(struct dentry *dentry, struct iattr *attr);
792793
extern int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry,
793794
struct kstat *stat);

0 commit comments

Comments
 (0)