From 132a56928baef1d7d7e9cfd86abd251e29b95007 Mon Sep 17 00:00:00 2001 From: Michael Halcrow Date: Wed, 8 Apr 2015 00:19:28 -0400 Subject: [PATCH] ext4 crypto: inherit encryption policies on inode and directory create Change-Id: Ibeeafc70352b39d1d5b3b17158a41d8fb54ed136 Signed-off-by: Michael Halcrow Signed-off-by: Theodore Ts'o --- fs/ext4/namei.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 30cd7dec2015..1db188ed783f 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -47,6 +47,8 @@ #define NAMEI_RA_BLOCKS 4 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS) +static int ext4_unlink(struct inode *dir, struct dentry *dentry); + static struct buffer_head *ext4_append(handle_t *handle, struct inode *inode, ext4_lblk_t *block) @@ -2251,6 +2253,13 @@ retry: err = ext4_add_nondir(handle, dentry, inode); if (!err && IS_DIRSYNC(dir)) ext4_handle_sync(handle); +#ifdef CONFIG_EXT4_FS_ENCRYPTION + if (!err && ext4_encrypted_inode(dir)) { + err = ext4_inherit_context(dir, inode); + if (err) + ext4_unlink(dir, dentry); + } +#endif } if (handle) ext4_journal_stop(handle); @@ -2452,6 +2461,13 @@ out_clear_inode: d_instantiate(dentry, inode); if (IS_DIRSYNC(dir)) ext4_handle_sync(handle); +#ifdef CONFIG_EXT4_FS_ENCRYPTION + if (ext4_encrypted_inode(dir)) { + err = ext4_inherit_context(dir, inode); + if (err) + ext4_unlink(dir, dentry); + } +#endif out_stop: if (handle) -- 2.39.5