aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/ialloc.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2015-05-31 13:35:02 -0400
committerTheodore Ts'o <tytso@mit.edu>2015-05-31 13:35:02 -0400
commite709e9df64928a99d41da75910b844976a535db7 (patch)
tree3661c61b6709f910f5ef1d365890c120819ac380 /fs/ext4/ialloc.c
parent6bc445e0ff44c7e83225124c214d350407e68ccf (diff)
ext4 crypto: encrypt tmpfile located in encryption protected directory
Factor out calls to ext4_inherit_context() and move them to __ext4_new_inode(); this fixes a problem where ext4_tmpfile() wasn't calling calling ext4_inherit_context(), so the temporary file wasn't getting protected. Since the blocks for the tmpfile could end up on disk, they really should be protected if the tmpfile is created within the context of an encrypted directory. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/ialloc.c')
-rw-r--r--fs/ext4/ialloc.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index ddca1697ad86..173c1ae21395 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -726,11 +726,25 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
726 ext4_group_t i; 726 ext4_group_t i;
727 ext4_group_t flex_group; 727 ext4_group_t flex_group;
728 struct ext4_group_info *grp; 728 struct ext4_group_info *grp;
729 int encrypt = 0;
729 730
730 /* Cannot create files in a deleted directory */ 731 /* Cannot create files in a deleted directory */
731 if (!dir || !dir->i_nlink) 732 if (!dir || !dir->i_nlink)
732 return ERR_PTR(-EPERM); 733 return ERR_PTR(-EPERM);
733 734
735 if ((ext4_encrypted_inode(dir) ||
736 DUMMY_ENCRYPTION_ENABLED(EXT4_SB(dir->i_sb))) &&
737 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) {
738 err = ext4_get_encryption_info(dir);
739 if (err)
740 return ERR_PTR(err);
741 if (ext4_encryption_info(dir) == NULL)
742 return ERR_PTR(-EPERM);
743 if (!handle)
744 nblocks += EXT4_DATA_TRANS_BLOCKS(dir->i_sb);
745 encrypt = 1;
746 }
747
734 sb = dir->i_sb; 748 sb = dir->i_sb;
735 ngroups = ext4_get_groups_count(sb); 749 ngroups = ext4_get_groups_count(sb);
736 trace_ext4_request_inode(dir, mode); 750 trace_ext4_request_inode(dir, mode);
@@ -996,12 +1010,6 @@ got:
996 ei->i_block_group = group; 1010 ei->i_block_group = group;
997 ei->i_last_alloc_group = ~0; 1011 ei->i_last_alloc_group = ~0;
998 1012
999 /* If the directory encrypted, then we should encrypt the inode. */
1000 if ((S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode)) &&
1001 (ext4_encrypted_inode(dir) ||
1002 DUMMY_ENCRYPTION_ENABLED(sbi)))
1003 ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);
1004
1005 ext4_set_inode_flags(inode); 1013 ext4_set_inode_flags(inode);
1006 if (IS_DIRSYNC(inode)) 1014 if (IS_DIRSYNC(inode))
1007 ext4_handle_sync(handle); 1015 ext4_handle_sync(handle);
@@ -1063,6 +1071,12 @@ got:
1063 ei->i_datasync_tid = handle->h_transaction->t_tid; 1071 ei->i_datasync_tid = handle->h_transaction->t_tid;
1064 } 1072 }
1065 1073
1074 if (encrypt) {
1075 err = ext4_inherit_context(dir, inode);
1076 if (err)
1077 goto fail_free_drop;
1078 }
1079
1066 err = ext4_mark_inode_dirty(handle, inode); 1080 err = ext4_mark_inode_dirty(handle, inode);
1067 if (err) { 1081 if (err) {
1068 ext4_std_error(sb, err); 1082 ext4_std_error(sb, err);