Sync ext4 encryption as of commit dffd334e4d7134
[ext4-patch-queue.git] / inherit-encryption-policies-on-inode-and-directory-create
blobdc716c653af73e45d70511ac3566a414314dc6f7
1 ext4 crypto: inherit encryption policies on inode and directory create
3 From: Michael Halcrow <mhalcrow@google.com>
5 Change-Id: Ibeeafc70352b39d1d5b3b17158a41d8fb54ed136
6 Signed-off-by: Michael Halcrow <mhalcrow@google.com>
7 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 ---
9  fs/ext4/namei.c | 16 ++++++++++++++++
10  1 file changed, 16 insertions(+)
12 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
13 index 12d2592..262aa1c 100644
14 --- a/fs/ext4/namei.c
15 +++ b/fs/ext4/namei.c
16 @@ -48,6 +48,8 @@
17  #define NAMEI_RA_BLOCKS  4
18  #define NAMEI_RA_SIZE       (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
20 +static int ext4_unlink(struct inode *dir, struct dentry *dentry);
22  static struct buffer_head *ext4_append(handle_t *handle,
23                                         struct inode *inode,
24                                         ext4_lblk_t *block)
25 @@ -2247,6 +2249,13 @@ retry:
26                 err = ext4_add_nondir(handle, dentry, inode);
27                 if (!err && IS_DIRSYNC(dir))
28                         ext4_handle_sync(handle);
29 +#ifdef CONFIG_EXT4_FS_ENCRYPTION
30 +               if (!err && ext4_encrypted_inode(dir)) {
31 +                       err = ext4_inherit_context(dir, inode);
32 +                       if (err)
33 +                               ext4_unlink(dir, dentry);
34 +               }
35 +#endif
36         }
37         if (handle)
38                 ext4_journal_stop(handle);
39 @@ -2445,6 +2454,13 @@ out_clear_inode:
40         d_instantiate(dentry, inode);
41         if (IS_DIRSYNC(dir))
42                 ext4_handle_sync(handle);
43 +#ifdef CONFIG_EXT4_FS_ENCRYPTION
44 +       if (ext4_encrypted_inode(dir)) {
45 +               err = ext4_inherit_context(dir, inode);
46 +               if (err)
47 +                       ext4_unlink(dir, dentry);
48 +       }
49 +#endif
51  out_stop:
52         if (handle)