Skip to content

Commit fe26569

Browse files
eaferjankara
authored andcommitted
ext2: preserve i_mode if ext2_set_acl() fails
When changing a file's acl mask, ext2_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. [JK: Rebased on top of "ext2: Don't clear SGID when inheriting ACLs"] Signed-off-by: Ernesto A. Fernández <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent a992f2d commit fe26569

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

fs/ext2/acl.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,22 @@ int
218218
ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
219219
{
220220
int error;
221+
int update_mode = 0;
222+
umode_t mode = inode->i_mode;
221223

222224
if (type == ACL_TYPE_ACCESS && acl) {
223-
error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
225+
error = posix_acl_update_mode(inode, &mode, &acl);
224226
if (error)
225227
return error;
228+
update_mode = 1;
229+
}
230+
error = __ext2_set_acl(inode, acl, type);
231+
if (!error && update_mode) {
232+
inode->i_mode = mode;
226233
inode->i_ctime = current_time(inode);
227234
mark_inode_dirty(inode);
228235
}
229-
return __ext2_set_acl(inode, acl, type);
236+
return error;
230237
}
231238

232239
/*

0 commit comments

Comments
 (0)