Commit 4d1f97eb59a472a11982d6fff9a722b681225e1a

Authored by Jan Kara
Committed by Greg Kroah-Hartman
1 parent 0fa705dc61

ext2: Don't clear SGID when inheriting ACLs

commit a992f2d38e4ce17b8c7d1f7f67b2de0eebdea069 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: 073931017b49d9458aa351605b43a7e34598caef
CC: linux-ext4@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 22 additions and 14 deletions Side-by-side Diff

... ... @@ -175,11 +175,8 @@
175 175 return acl;
176 176 }
177 177  
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)
183 180 {
184 181 int name_index;
185 182 void *value = NULL;
... ... @@ -189,13 +186,6 @@
189 186 switch(type) {
190 187 case ACL_TYPE_ACCESS:
191 188 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   - }
199 189 break;
200 190  
201 191 case ACL_TYPE_DEFAULT:
... ... @@ -222,6 +212,24 @@
222 212 }
223 213  
224 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 +
  232 +/*
225 233 * Initialize the ACLs of a new inode. Called from ext2_new_inode.
226 234 *
227 235 * dir->i_mutex: down
228 236  
... ... @@ -238,12 +246,12 @@
238 246 return error;
239 247  
240 248 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);
242 250 posix_acl_release(default_acl);
243 251 }
244 252 if (acl) {
245 253 if (!error)
246   - error = ext2_set_acl(inode, acl, ACL_TYPE_ACCESS);
  254 + error = __ext2_set_acl(inode, acl, ACL_TYPE_ACCESS);
247 255 posix_acl_release(acl);
248 256 }
249 257 return error;