summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2017-06-21 08:34:15 -0400
committerJan Kara <jack@suse.cz>2017-07-17 04:15:31 -0400
commita992f2d38e4ce17b8c7d1f7f67b2de0eebdea069 (patch)
tree0e8254a82951c1bacde59194ef86e0f604b2019f
parent6883cd7f68245e43e91e5ee583b7550abf14523f (diff)
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: 073931017b49d9458aa351605b43a7e34598caef CC: stable@vger.kernel.org CC: linux-ext4@vger.kernel.org Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--fs/ext2/acl.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/fs/ext2/acl.c b/fs/ext2/acl.c
index 79dafa71effd..069c0dceda01 100644
--- a/fs/ext2/acl.c
+++ b/fs/ext2/acl.c
@@ -175,11 +175,8 @@ ext2_get_acl(struct inode *inode, int type)
175 return acl; 175 return acl;
176} 176}
177 177
178/* 178static int
179 * inode->i_mutex: down 179__ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
180 */
181int
182ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
183{ 180{
184 int name_index; 181 int name_index;
185 void *value = NULL; 182 void *value = NULL;
@@ -189,13 +186,6 @@ ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
189 switch(type) { 186 switch(type) {
190 case ACL_TYPE_ACCESS: 187 case ACL_TYPE_ACCESS:
191 name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS; 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 break; 189 break;
200 190
201 case ACL_TYPE_DEFAULT: 191 case ACL_TYPE_DEFAULT:
@@ -222,6 +212,24 @@ ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
222} 212}
223 213
224/* 214/*
215 * inode->i_mutex: down
216 */
217int
218ext2_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 * Initialize the ACLs of a new inode. Called from ext2_new_inode. 233 * Initialize the ACLs of a new inode. Called from ext2_new_inode.
226 * 234 *
227 * dir->i_mutex: down 235 * dir->i_mutex: down
@@ -238,12 +246,12 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
238 return error; 246 return error;
239 247
240 if (default_acl) { 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 posix_acl_release(default_acl); 250 posix_acl_release(default_acl);
243 } 251 }
244 if (acl) { 252 if (acl) {
245 if (!error) 253 if (!error)
246 error = ext2_set_acl(inode, acl, ACL_TYPE_ACCESS); 254 error = __ext2_set_acl(inode, acl, ACL_TYPE_ACCESS);
247 posix_acl_release(acl); 255 posix_acl_release(acl);
248 } 256 }
249 return error; 257 return error;