Skip to content

Commit a3bb2d5

Browse files
jankaratytso
authored andcommitted
ext4: Don't clear SGID when inheriting ACLs
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: 0739310 CC: stable@vger.kernel.org Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Jan Kara <jack@suse.cz> Reviewed-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent 397e434 commit a3bb2d5

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

‎fs/ext4/acl.c‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,10 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type,
189189
void *value = NULL;
190190
size_t size = 0;
191191
int error;
192-
int update_mode = 0;
193-
umode_t mode = inode->i_mode;
194192

195193
switch (type) {
196194
case ACL_TYPE_ACCESS:
197195
name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
198-
if (acl) {
199-
error = posix_acl_update_mode(inode, &mode, &acl);
200-
if (error)
201-
return error;
202-
update_mode = 1;
203-
}
204196
break;
205197

206198
case ACL_TYPE_DEFAULT:
@@ -224,11 +216,6 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type,
224216
kfree(value);
225217
if (!error) {
226218
set_cached_acl(inode, type, acl);
227-
if (update_mode) {
228-
inode->i_mode = mode;
229-
inode->i_ctime = current_time(inode);
230-
ext4_mark_inode_dirty(handle, inode);
231-
}
232219
}
233220

234221
return error;
@@ -240,6 +227,8 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)
240227
handle_t *handle;
241228
int error, credits, retries = 0;
242229
size_t acl_size = acl ? ext4_acl_size(acl->a_count) : 0;
230+
umode_t mode = inode->i_mode;
231+
int update_mode = 0;
243232

244233
error = dquot_initialize(inode);
245234
if (error)
@@ -254,7 +243,20 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)
254243
if (IS_ERR(handle))
255244
return PTR_ERR(handle);
256245

246+
if ((type == ACL_TYPE_ACCESS) && acl) {
247+
error = posix_acl_update_mode(inode, &mode, &acl);
248+
if (error)
249+
goto out_stop;
250+
update_mode = 1;
251+
}
252+
257253
error = __ext4_set_acl(handle, inode, type, acl, 0 /* xattr_flags */);
254+
if (!error && update_mode) {
255+
inode->i_mode = mode;
256+
inode->i_ctime = current_time(inode);
257+
ext4_mark_inode_dirty(handle, inode);
258+
}
259+
out_stop:
258260
ext4_journal_stop(handle);
259261
if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
260262
goto retry;

0 commit comments

Comments
 (0)