When changing a file's acl mask, __gfs2_set_acl() will first set the group bits of i_mode to the value of the mask, and only then set the actual extended attribute representing the new acl.
If the second part fails (due to lack of space, for example) and the file had no acl attribute to begin with, the system will from now on assume that the mask permission bits are actual group permission bits, potentially granting access to the wrong users. Prevent this by only changing the inode mode after the acl has been set. Signed-off-by: Ernesto A. Fernández <[email protected]> --- This issue affects several filesystems, some of them have already applied patches. See for example: - 397e434 ext4: preserve i_mode if __ext4_set_acl() fails - f070e5a jfs: preserve i_mode if __jfs_set_acl() fails - fcea8ae reiserfs: preserve i_mode if __reiserfs_set_acl() fails - fe26569 ext2: preserve i_mode if ext2_set_acl() fails fs/gfs2/acl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index 2524807..06bbb6b 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -85,18 +85,15 @@ int __gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type) int len; char *data; const char *name = gfs2_acl_name(type); + umode_t mode = inode->i_mode; if (acl && acl->a_count > GFS2_ACL_MAX_ENTRIES(GFS2_SB(inode))) return -E2BIG; if (type == ACL_TYPE_ACCESS) { - umode_t mode = inode->i_mode; - - error = posix_acl_update_mode(inode, &inode->i_mode, &acl); + error = posix_acl_update_mode(inode, &mode, &acl); if (error) return error; - if (mode != inode->i_mode) - mark_inode_dirty(inode); } if (acl) { @@ -118,6 +115,10 @@ int __gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type) if (error) goto out; set_cached_acl(inode, type, acl); + if (mode != inode->i_mode) { + inode->i_mode = mode; + mark_inode_dirty(inode); + } out: kfree(data); return error; -- 2.1.4
