Commit ee31ec07 authored by Jan Kara's avatar Jan Kara Committed by Greg Kroah-Hartman

ext2: Don't clear SGID when inheriting ACLs

commit a992f2d3 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 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: 07393101
CC: linux-ext4@vger.kernel.org
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 08196c1c
...@@ -175,11 +175,8 @@ ext2_get_acl(struct inode *inode, int type) ...@@ -175,11 +175,8 @@ ext2_get_acl(struct inode *inode, int type)
return acl; return acl;
} }
/* static int
* inode->i_mutex: down __ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
*/
int
ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
{ {
int name_index; int name_index;
void *value = NULL; void *value = NULL;
...@@ -189,13 +186,6 @@ ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type) ...@@ -189,13 +186,6 @@ ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
switch(type) { switch(type) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS; name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
if (acl) {
error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
if (error)
return error;
inode->i_ctime = current_time(inode);
mark_inode_dirty(inode);
}
break; break;
case ACL_TYPE_DEFAULT: case ACL_TYPE_DEFAULT:
...@@ -221,6 +211,24 @@ ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type) ...@@ -221,6 +211,24 @@ ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
return error; return error;
} }
/*
* inode->i_mutex: down
*/
int
ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
{
int error;
if (type == ACL_TYPE_ACCESS && acl) {
error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
if (error)
return error;
inode->i_ctime = current_time(inode);
mark_inode_dirty(inode);
}
return __ext2_set_acl(inode, acl, type);
}
/* /*
* Initialize the ACLs of a new inode. Called from ext2_new_inode. * Initialize the ACLs of a new inode. Called from ext2_new_inode.
* *
...@@ -238,12 +246,12 @@ ext2_init_acl(struct inode *inode, struct inode *dir) ...@@ -238,12 +246,12 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
return error; return error;
if (default_acl) { if (default_acl) {
error = ext2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT); error = __ext2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
posix_acl_release(default_acl); posix_acl_release(default_acl);
} }
if (acl) { if (acl) {
if (!error) if (!error)
error = ext2_set_acl(inode, acl, ACL_TYPE_ACCESS); error = __ext2_set_acl(inode, acl, ACL_TYPE_ACCESS);
posix_acl_release(acl); posix_acl_release(acl);
} }
return error; return error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment