Skip to content

Commit 309e8cd

Browse files
eaferAstralBob
authored andcommitted
gfs2: preserve i_mode if __gfs2_set_acl() fails
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]> Signed-off-by: Bob Peterson <[email protected]>
1 parent 54aae14 commit 309e8cd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

fs/gfs2/acl.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
116116
struct gfs2_holder gh;
117117
bool need_unlock = false;
118118
int ret;
119+
umode_t mode;
119120

120121
if (acl && acl->a_count > GFS2_ACL_MAX_ENTRIES(GFS2_SB(inode)))
121122
return -E2BIG;
@@ -130,17 +131,19 @@ int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
130131
return ret;
131132
need_unlock = true;
132133
}
133-
if (type == ACL_TYPE_ACCESS && acl) {
134-
umode_t mode = inode->i_mode;
135134

136-
ret = posix_acl_update_mode(inode, &inode->i_mode, &acl);
135+
mode = inode->i_mode;
136+
if (type == ACL_TYPE_ACCESS && acl) {
137+
ret = posix_acl_update_mode(inode, &mode, &acl);
137138
if (ret)
138139
goto unlock;
139-
if (mode != inode->i_mode)
140-
mark_inode_dirty(inode);
141140
}
142141

143142
ret = __gfs2_set_acl(inode, acl, type);
143+
if (!ret && mode != inode->i_mode) {
144+
inode->i_mode = mode;
145+
mark_inode_dirty(inode);
146+
}
144147
unlock:
145148
if (need_unlock)
146149
gfs2_glock_dq_uninit(&gh);

0 commit comments

Comments
 (0)