Skip to content

Commit 19ec8e4

Browse files
jankaratorvalds
authored andcommitted
ocfs2: 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 ocfs2_set_acl() into ocfs2_iop_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. Also posix_acl_chmod() that is calling ocfs2_set_acl() takes care of updating mode itself. Fixes: 0739310 ("posix_acl: Clear SGID bit when setting file permissions") Link: http://lkml.kernel.org/r/20170801141252.19675-3-jack@suse.cz Signed-off-by: Jan Kara <jack@suse.cz> Cc: Mark Fasheh <mfasheh@versity.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Joseph Qi <jiangqi903@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1ee1c3f commit 19ec8e4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

fs/ocfs2/acl.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,6 @@ int ocfs2_set_acl(handle_t *handle,
240240
switch (type) {
241241
case ACL_TYPE_ACCESS:
242242
name_index = OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS;
243-
if (acl) {
244-
umode_t mode;
245-
246-
ret = posix_acl_update_mode(inode, &mode, &acl);
247-
if (ret)
248-
return ret;
249-
250-
ret = ocfs2_acl_set_mode(inode, di_bh,
251-
handle, mode);
252-
if (ret)
253-
return ret;
254-
}
255243
break;
256244
case ACL_TYPE_DEFAULT:
257245
name_index = OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT;
@@ -289,7 +277,19 @@ int ocfs2_iop_set_acl(struct inode *inode, struct posix_acl *acl, int type)
289277
had_lock = ocfs2_inode_lock_tracker(inode, &bh, 1, &oh);
290278
if (had_lock < 0)
291279
return had_lock;
280+
if (type == ACL_TYPE_ACCESS && acl) {
281+
umode_t mode;
282+
283+
status = posix_acl_update_mode(inode, &mode, &acl);
284+
if (status)
285+
goto unlock;
286+
287+
status = ocfs2_acl_set_mode(inode, bh, NULL, mode);
288+
if (status)
289+
goto unlock;
290+
}
292291
status = ocfs2_set_acl(NULL, inode, bh, type, acl, NULL, NULL);
292+
unlock:
293293
ocfs2_inode_unlock_tracker(inode, 1, &oh, had_lock);
294294
brelse(bh);
295295
return status;

0 commit comments

Comments
 (0)