Skip to content

Commit 4f22f07

Browse files
jankaragregkh
authored andcommitted
ext4: Don't clear SGID when inheriting ACLs
commit a3bb2d5587521eea6dab2d05326abb0afb460abd upstream. When new directory 'DIR1' is created in a directory 'DIR0' with SGID bit set, DIR1 is expected to have SGID bit set (and owning group equal to the owning group of 'DIR0'). However when 'DIR0' also has some default ACLs that 'DIR1' inherits, setting these ACLs will result in SGID bit on 'DIR1' to get cleared if user is not member of the owning group. Fix the problem by moving posix_acl_update_mode() out of __ext4_set_acl() into ext4_set_acl(). That way the function will not be called when inheriting ACLs which is what we want as it prevents SGID bit clearing and the mode has been properly set by posix_acl_create() anyway. Fixes: 073931017b49d9458aa351605b43a7e34598caef Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Jan Kara <jack@suse.cz> Reviewed-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 40c00e5 commit 4f22f07

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

fs/ext4/acl.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,6 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type,
195195
switch (type) {
196196
case ACL_TYPE_ACCESS:
197197
name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
198-
if (acl) {
199-
error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
200-
if (error)
201-
return error;
202-
inode->i_ctime = ext4_current_time(inode);
203-
ext4_mark_inode_dirty(handle, inode);
204-
}
205198
break;
206199

207200
case ACL_TYPE_DEFAULT:
@@ -234,14 +227,29 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)
234227
{
235228
handle_t *handle;
236229
int error, retries = 0;
230+
umode_t mode = inode->i_mode;
231+
int update_mode = 0;
237232

238233
retry:
239234
handle = ext4_journal_start(inode, EXT4_HT_XATTR,
240235
ext4_jbd2_credits_xattr(inode));
241236
if (IS_ERR(handle))
242237
return PTR_ERR(handle);
243238

239+
if ((type == ACL_TYPE_ACCESS) && acl) {
240+
error = posix_acl_update_mode(inode, &mode, &acl);
241+
if (error)
242+
goto out_stop;
243+
update_mode = 1;
244+
}
245+
244246
error = __ext4_set_acl(handle, inode, type, acl);
247+
if (!error && update_mode) {
248+
inode->i_mode = mode;
249+
inode->i_ctime = ext4_current_time(inode);
250+
ext4_mark_inode_dirty(handle, inode);
251+
}
252+
out_stop:
245253
ext4_journal_stop(handle);
246254
if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
247255
goto retry;

0 commit comments

Comments
 (0)