add patch remove-unused-mode-parameter
[ext4-patch-queue.git] / dont-clear-sgid-when-inheriting-ACLs
blobf8c2f1ed3fd7e4303f368e22d5ab3c39f1fb0a9f
1 ext4: Don't clear SGID when inheriting ACLs
3 From: Jan Kara <jack@suse.cz>
5 When new directory 'DIR1' is created in a directory 'DIR0' with SGID bit
6 set, DIR1 is expected to have SGID bit set (and owning group equal to
7 the owning group of 'DIR0'). However when 'DIR0' also has some default
8 ACLs that 'DIR1' inherits, setting these ACLs will result in SGID bit on
9 'DIR1' to get cleared if user is not member of the owning group.
11 Fix the problem by moving posix_acl_update_mode() out of
12 __ext4_set_acl() into ext4_set_acl(). That way the function will not be
13 called when inheriting ACLs which is what we want as it prevents SGID
14 bit clearing and the mode has been properly set by posix_acl_create()
15 anyway.
17 Fixes: 073931017b49d9458aa351605b43a7e34598caef
18 CC: stable@vger.kernel.org
19 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 Signed-off-by: Jan Kara <jack@suse.cz>
21 Reviewed-by: Andreas Gruenbacher <agruenba@redhat.com>
22 ---
23  fs/ext4/acl.c | 28 +++++++++++++++-------------
24  1 file changed, 15 insertions(+), 13 deletions(-)
26 diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
27 index 2985cd0a640d..46ff2229ff5e 100644
28 --- a/fs/ext4/acl.c
29 +++ b/fs/ext4/acl.c
30 @@ -189,18 +189,10 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type,
31         void *value = NULL;
32         size_t size = 0;
33         int error;
34 -       int update_mode = 0;
35 -       umode_t mode = inode->i_mode;
37         switch (type) {
38         case ACL_TYPE_ACCESS:
39                 name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
40 -               if (acl) {
41 -                       error = posix_acl_update_mode(inode, &mode, &acl);
42 -                       if (error)
43 -                               return error;
44 -                       update_mode = 1;
45 -               }
46                 break;
48         case ACL_TYPE_DEFAULT:
49 @@ -224,11 +216,6 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type,
50         kfree(value);
51         if (!error) {
52                 set_cached_acl(inode, type, acl);
53 -               if (update_mode) {
54 -                       inode->i_mode = mode;
55 -                       inode->i_ctime = current_time(inode);
56 -                       ext4_mark_inode_dirty(handle, inode);
57 -               }
58         }
60         return error;
61 @@ -240,6 +227,8 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)
62         handle_t *handle;
63         int error, credits, retries = 0;
64         size_t acl_size = acl ? ext4_acl_size(acl->a_count) : 0;
65 +       umode_t mode = inode->i_mode;
66 +       int update_mode = 0;
68         error = dquot_initialize(inode);
69         if (error)
70 @@ -254,7 +243,20 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)
71         if (IS_ERR(handle))
72                 return PTR_ERR(handle);
74 +       if ((type == ACL_TYPE_ACCESS) && acl) {
75 +               error = posix_acl_update_mode(inode, &mode, &acl);
76 +               if (error)
77 +                       goto out_stop;
78 +               update_mode = 1;
79 +       }
81         error = __ext4_set_acl(handle, inode, type, acl, 0 /* xattr_flags */);
82 +       if (!error && update_mode) {
83 +               inode->i_mode = mode;
84 +               inode->i_ctime = current_time(inode);
85 +               ext4_mark_inode_dirty(handle, inode);
86 +       }
87 +out_stop:
88         ext4_journal_stop(handle);
89         if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
90                 goto retry;