Skip to content

Commit a992f2d

Browse files
committed
ext2: 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 creating __ext2_set_acl() function that does not call posix_acl_update_mode() and use it when inheriting ACLs. That prevents SGID bit clearing and the mode has been properly set by posix_acl_create() anyway. Fixes: 0739310 CC: [email protected] CC: [email protected] Signed-off-by: Jan Kara <[email protected]>
1 parent 6883cd7 commit a992f2d

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

fs/ext2/acl.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,8 @@ ext2_get_acl(struct inode *inode, int type)
175175
return acl;
176176
}
177177

178-
/*
179-
* inode->i_mutex: down
180-
*/
181-
int
182-
ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
178+
static int
179+
__ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
183180
{
184181
int name_index;
185182
void *value = NULL;
@@ -189,13 +186,6 @@ ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
189186
switch(type) {
190187
case ACL_TYPE_ACCESS:
191188
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
192-
if (acl) {
193-
error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
194-
if (error)
195-
return error;
196-
inode->i_ctime = current_time(inode);
197-
mark_inode_dirty(inode);
198-
}
199189
break;
200190

201191
case ACL_TYPE_DEFAULT:
@@ -221,6 +211,24 @@ ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
221211
return error;
222212
}
223213

214+
/*
215+
* inode->i_mutex: down
216+
*/
217+
int
218+
ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
219+
{
220+
int error;
221+
222+
if (type == ACL_TYPE_ACCESS && acl) {
223+
error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
224+
if (error)
225+
return error;
226+
inode->i_ctime = current_time(inode);
227+
mark_inode_dirty(inode);
228+
}
229+
return __ext2_set_acl(inode, acl, type);
230+
}
231+
224232
/*
225233
* Initialize the ACLs of a new inode. Called from ext2_new_inode.
226234
*
@@ -238,12 +246,12 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
238246
return error;
239247

240248
if (default_acl) {
241-
error = ext2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
249+
error = __ext2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
242250
posix_acl_release(default_acl);
243251
}
244252
if (acl) {
245253
if (!error)
246-
error = ext2_set_acl(inode, acl, ACL_TYPE_ACCESS);
254+
error = __ext2_set_acl(inode, acl, ACL_TYPE_ACCESS);
247255
posix_acl_release(acl);
248256
}
249257
return error;

0 commit comments

Comments
 (0)