add patch fix-warnings-about-stack-corruption
[ext4-patch-queue.git] / preserve-i_mode-if-ext4_set_acl-fails
blobe5e50484f9292fe87b7db3da4c25cad9614b028c
1 ext4: preserve i_mode if __ext4_set_acl() fails
3 From: "Ernesto A. Fernández" <ernesto.mnd.fernandez@gmail.com>
5 When changing a file's acl mask, __ext4_set_acl() will first set the group
6 bits of i_mode to the value of the mask, and only then set the actual
7 extended attribute representing the new acl.
9 If the second part fails (due to lack of space, for example) and the file
10 had no acl attribute to begin with, the system will from now on assume
11 that the mask permission bits are actual group permission bits, potentially
12 granting access to the wrong users.
14 Prevent this by only changing the inode mode after the acl has been set.
16 Signed-off-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
17 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
18 Reviewed-by: Jan Kara <jack@suse.cz>
19 ---
20  fs/ext4/acl.c | 15 +++++++++++----
21  1 file changed, 11 insertions(+), 4 deletions(-)
23 diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
24 index 09441ae..2985cd0 100644
25 --- a/fs/ext4/acl.c
26 +++ b/fs/ext4/acl.c
27 @@ -189,16 +189,17 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type,
28         void *value = NULL;
29         size_t size = 0;
30         int error;
31 +       int update_mode = 0;
32 +       umode_t mode = inode->i_mode;
34         switch (type) {
35         case ACL_TYPE_ACCESS:
36                 name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
37                 if (acl) {
38 -                       error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
39 +                       error = posix_acl_update_mode(inode, &mode, &acl);
40                         if (error)
41                                 return error;
42 -                       inode->i_ctime = current_time(inode);
43 -                       ext4_mark_inode_dirty(handle, inode);
44 +                       update_mode = 1;
45                 }
46                 break;
48 @@ -221,8 +222,14 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type,
49                                       value, size, xattr_flags);
51         kfree(value);
52 -       if (!error)
53 +       if (!error) {
54                 set_cached_acl(inode, type, acl);
55 +               if (update_mode) {
56 +                       inode->i_mode = mode;
57 +                       inode->i_ctime = current_time(inode);
58 +                       ext4_mark_inode_dirty(handle, inode);
59 +               }
60 +       }
62         return error;
63  }
64 -- 
65 2.1.4