fscrypt: add some higher-level helper functions
Subsystems (6)
cover fscrypt: add some higher-level helper functions
From: Eric Biggers <[email protected]>
This series reduces code duplication among ext4, f2fs, and ubifs by introducing a S_ENCRYPTED inode flag (so we don't have to call back into the filesystem to test the filesystem-specific inode flag), then introducing new helper functions that are called at the beginning of the open, link, rename, lookup, and setattr operations.
In the future we maybe should even call these new helpers from the VFS so that each individual filesystem doesn't have to do it. But that's not possible currently because fs/crypto/ can be built as a module.
Making changes like this is a bit challenging due to interdependencies between fscrypt and the individual filesystems, all of which have different maintainers. For now my intent is that patches 1-10 be taken through the fscrypt tree --- though it's not perfect since patches 1-4 do make some changes to each filesystem, as everyone must set S_ENCRYPTED before we can use it everywhere in the shared code. But afterwards, patches 11-25 can be picked up by the individual filesystems to switch to the new helpers.
Eric Biggers (25):
fs, fscrypt: add an S_ENCRYPTED inode flag
fscrypt: switch from ->is_encrypted() to IS_ENCRYPTED()
fscrypt: remove ->is_encrypted()
fscrypt: remove unneeded empty fscrypt_operations structs
fscrypt: new helper function - fscrypt_require_key()
fscrypt: new helper function - fscrypt_file_open()
fscrypt: new helper function - fscrypt_prepare_link()
fscrypt: new helper function - fscrypt_prepare_rename()
fscrypt: new helper function - fscrypt_prepare_lookup()
fscrypt: new helper function - fscrypt_prepare_setattr()
ext4: switch to fscrypt_file_open()
ext4: switch to fscrypt_prepare_link()
ext4: switch to fscrypt_prepare_rename()
ext4: switch to fscrypt_prepare_lookup()
ext4: switch to fscrypt_prepare_setattr()
f2fs: switch to fscrypt_file_open()
f2fs: switch to fscrypt_prepare_link()
f2fs: switch to fscrypt_prepare_rename()
f2fs: switch to fscrypt_prepare_lookup()
f2fs: switch to fscrypt_prepare_setattr()
ubifs: switch to fscrypt_file_open()
ubifs: switch to fscrypt_prepare_link()
ubifs: switch to fscrypt_prepare_rename()
ubifs: switch to fscrypt_prepare_lookup()
ubifs: switch to fscrypt_prepare_setattr()
fs/crypto/Makefile | 2 +- fs/crypto/crypto.c | 2 +- fs/crypto/fname.c | 3 +- fs/crypto/hooks.c | 112 +++++++++++++++++++++++++++++ fs/crypto/keyinfo.c | 2 +- fs/crypto/policy.c | 6 +- fs/ext4/file.c | 23 ++---- fs/ext4/inode.c | 19 +++-- fs/ext4/namei.c | 62 +++++----------- fs/ext4/super.c | 15 ++-- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 30 ++------ fs/f2fs/inode.c | 5 +- fs/f2fs/namei.c | 54 ++++---------- fs/f2fs/super.c | 7 +- fs/ubifs/crypto.c | 1 - fs/ubifs/dir.c | 43 ++++------- fs/ubifs/file.c | 41 ++--------- fs/ubifs/ioctl.c | 5 +- fs/ubifs/super.c | 8 +-- fs/ubifs/ubifs.h | 9 +-- fs/ubifs/xattr.c | 1 + include/linux/fs.h | 2 + include/linux/fscrypt_common.h | 1 - include/linux/fscrypt_notsupp.h | 54 +++++++++++++- include/linux/fscrypt_supp.h | 153 ++++++++++++++++++++++++++++++++++++++++ 26 files changed, 418 insertions(+), 243 deletions(-) create mode 100644 fs/crypto/hooks.c
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
PATCH 1/25 fs, fscrypt: add an S_ENCRYPTED inode flag
From: Eric Biggers <[email protected]>
Introduce a flag S_ENCRYPTED which can be set in ->i_flags to indicate that the inode is encrypted using the fscrypt (fs/crypto/) mechanism.
Checking this flag will give the same information that inode->i_sb->s_cop->is_encrypted(inode) currently does, but will be more efficient. This will be useful for adding higher-level helper functions for filesystems to use. For example we'll be able to replace this:
if (ext4_encrypted_inode(inode)) {
ret = fscrypt_get_encryption_info(inode);
if (ret)
return ret;
if (!fscrypt_has_encryption_key(inode))
return -ENOKEY;
}with this:
ret = fscrypt_require_key(inode); if (ret) return ret;
... since we'll be able to retain the fast path for unencrypted files as a single flag check, using an inline function. This wasn't possible before because we'd have had to frequently call through the ->i_sb->s_cop->is_encrypted function pointer, even when the encryption support was disabled or not being used.
Note: we don't define S_ENCRYPTED to 0 if CONFIG_FS_ENCRYPTION is disabled because we want to continue to return an error if an encrypted file is accessed without encryption support, rather than pretending that it is unencrypted.
--- fs/ext4/inode.c | 7 +++++-- fs/ext4/super.c | 8 ++++++-- fs/f2fs/f2fs.h | 1 + fs/f2fs/inode.c | 5 ++++- fs/ubifs/ioctl.c | 5 ++++- fs/ubifs/xattr.c | 1 + include/linux/fs.h | 2 ++ 7 files changed, 23 insertions(+), 6 deletions(-)
fs/ext4/inode.c +5 -2
@@ -4589,10 +4589,13 @@ void ext4_set_inode_flags(struct inode *inode) new_fl |=S_DIRSYNC ;if (test_opt (inode->i_sb,DAX ) &&S_ISREG (inode->i_mode) && !ext4_should_journal_data (inode) && !ext4_has_inline_data (inode) && - !ext4_encrypted_inode (inode)) + !(flags &EXT4_ENCRYPT_FL )) new_fl |=S_DAX ; +if (flags &EXT4_ENCRYPT_FL ) + new_fl |=S_ENCRYPTED ;inode_set_flags (inode, new_fl, -S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME |S_DIRSYNC |S_DAX ); +S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME |S_DIRSYNC |S_DAX | +S_ENCRYPTED ); } static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
fs/ext4/super.c +6 -2
@@ -1181,7 +1181,8 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,ext4_clear_inode_state (inode,EXT4_STATE_MAY_INLINE_DATA );/* -* Update inode->i_flags - e.g. S_DAX may get disabled +* Update inode->i_flags - S_ENCRYPTED will be enabled, +* S_DAX may be disabled */ ext4_set_inode_flags (inode); }
@@ -1206,7 +1207,10 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, ctx, len, 0);if (!res) {ext4_set_inode_flag (inode,EXT4_INODE_ENCRYPT ); -/* Update inode->i_flags - e.g. S_DAX may get disabled */ +/* +* Update inode->i_flags - S_ENCRYPTED will be enabled, +* S_DAX may be disabled +*/ ext4_set_inode_flags (inode); res =ext4_mark_inode_dirty (handle, inode);if (res)
fs/f2fs/f2fs.h +1 -0
@@ -2949,6 +2949,7 @@ static inline void f2fs_set_encrypted_inode(struct inode *inode) {#ifdef CONFIG_F2FS_FS_ENCRYPTION file_set_encrypt (inode); + inode->i_flags |=S_ENCRYPTED ;#endif }
fs/f2fs/inode.c +4 -1
@@ -43,8 +43,11 @@ void f2fs_set_inode_flags(struct inode *inode) new_fl |=S_NOATIME ;if (flags &FS_DIRSYNC_FL ) new_fl |=S_DIRSYNC ; +if (f2fs_encrypted_inode (inode)) + new_fl |=S_ENCRYPTED ;inode_set_flags (inode, new_fl, -S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME |S_DIRSYNC ); +S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME |S_DIRSYNC | +S_ENCRYPTED ); }static void __get_inode_rdev (struct inode *inode,struct f2fs_inode *ri)
fs/ubifs/ioctl.c +4 -1
@@ -38,7 +38,8 @@ void ubifs_set_inode_flags(struct inode *inode) {unsigned int flags =ubifs_inode (inode)->flags; - inode->i_flags &= ~(S_SYNC |S_APPEND |S_IMMUTABLE |S_DIRSYNC ); + inode->i_flags &= ~(S_SYNC |S_APPEND |S_IMMUTABLE |S_DIRSYNC | +S_ENCRYPTED );if (flags &UBIFS_SYNC_FL ) inode->i_flags |=S_SYNC ;if (flags &UBIFS_APPEND_FL )
@@ -47,6 +48,8 @@ void ubifs_set_inode_flags(struct inode *inode) inode->i_flags |=S_IMMUTABLE ;if (flags &UBIFS_DIRSYNC_FL ) inode->i_flags |=S_DIRSYNC ; +if (flags &UBIFS_CRYPT_FL ) + inode->i_flags |=S_ENCRYPTED ; }/*
fs/ubifs/xattr.c +1 -0
@@ -170,6 +170,7 @@ static int create_xattr(struct ubifs_info *c, struct inode *host, err =ubifs_jnl_update (c, host, nm, inode,0 ,1 );if (err) goto out_cancel; +ubifs_set_inode_flags (host);mutex_unlock (&host_ui->ui_mutex);ubifs_release_budget (c, &req);
include/linux/fs.h +2 -0
@@ -1853,6 +1853,7 @@ struct super_operations {#else #define S_DAX 0/* Make all the DAX code disappear */ #endif +#define S_ENCRYPTED 16384/* Encrypted file (using fs/crypto/) */ /* * Note that nosuid etc flags are inode-specific: setting some file-system
@@ -1892,6 +1893,7 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags#define IS_AUTOMOUNT (inode) ((inode)->i_flags & S_AUTOMOUNT)#define IS_NOSEC (inode) ((inode)->i_flags & S_NOSEC)#define IS_DAX (inode) ((inode)->i_flags & S_DAX) +#define IS_ENCRYPTED (inode) ((inode)->i_flags & S_ENCRYPTED)#define IS_WHITEOUT (inode) (S_ISCHR(inode->i_mode) && \ (inode)->i_rdev == WHITEOUT_DEV)
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
PATCH 2/25 fscrypt: switch from ->is_encrypted() to IS_ENCRYPTED()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
IS_ENCRYPTED() now gives the same information as i_sb->s_cop->is_encrypted() but is more efficient, since IS_ENCRYPTED() is just a simple flag check. Prepare to remove ->is_encrypted() by switching all callers to IS_ENCRYPTED().
--- fs/crypto/crypto.c | 2 +- fs/crypto/fname.c | 3 +-- fs/crypto/keyinfo.c | 2 +- fs/crypto/policy.c | 6 +++--- include/linux/fscrypt_notsupp.h | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-)
fs/crypto/crypto.c +1 -1
@@ -340,7 +340,7 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags)return -ECHILD ; dir =dget_parent (dentry); -if (!d_inode (dir)->i_sb->s_cop->is_encrypted (d_inode (dir))) { +if (!IS_ENCRYPTED (d_inode (dir))) {dput (dir);return 0 ; }
fs/crypto/fname.c +1 -2
@@ -382,8 +382,7 @@ int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname,memset (fname,0 ,sizeof (struct fscrypt_name )); fname->usr_fname = iname; -if (!dir->i_sb->s_cop->is_encrypted (dir) || -fscrypt_is_dot_dotdot (iname)) { +if (!IS_ENCRYPTED (dir) ||fscrypt_is_dot_dotdot (iname)) { fname->disk_name.name = (unsigned char *)iname->name; fname->disk_name.len = iname->len;return 0 ;
fs/crypto/keyinfo.c +1 -1
@@ -268,7 +268,7 @@ int fscrypt_get_encryption_info(struct inode *inode) res = inode->i_sb->s_cop->get_context (inode, &ctx,sizeof (ctx));if (res <0 ) {if (!fscrypt_dummy_context_enabled (inode) || - inode->i_sb->s_cop->is_encrypted (inode)) +IS_ENCRYPTED (inode))return res;/* Fake up a context for an unencrypted directory */ memset (&ctx,0 ,sizeof (ctx));
fs/crypto/policy.c +3 -3
@@ -109,7 +109,7 @@ int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)struct fscrypt_policy policy;int res; -if (!inode->i_sb->s_cop->is_encrypted (inode)) +if (!IS_ENCRYPTED (inode))return -ENODATA ; res = inode->i_sb->s_cop->get_context (inode, &ctx,sizeof (ctx));
@@ -166,11 +166,11 @@ int fscrypt_has_permitted_context(struct inode *parent, struct inode *child)return 1 ;/* No restrictions if the parent directory is unencrypted */ -if (!cops->is_encrypted (parent)) +if (!IS_ENCRYPTED (parent))return 1 ;/* Encrypted directories must not contain unencrypted files */ -if (!cops->is_encrypted (child)) +if (!IS_ENCRYPTED (child))return 0 ;/*
include/linux/fscrypt_notsupp.h +1 -1
@@ -97,7 +97,7 @@ static inline int fscrypt_setup_filename(struct inode *dir,const struct qstr *iname, int lookup, struct fscrypt_name *fname) { - if (dir->i_sb->s_cop->is_encrypted(dir)) + if (IS_ENCRYPTED(dir)) return -EOPNOTSUPP; memset(fname, 0, sizeof(struct fscrypt_name));
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 3/25 fscrypt: remove ->is_encrypted()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Now that all callers of fscrypt_operations.is_encrypted() have been switched to IS_ENCRYPTED(), remove ->is_encrypted().
--- fs/ext4/super.c | 2 -- fs/f2fs/super.c | 2 -- fs/ubifs/crypto.c | 1 - fs/ubifs/super.c | 1 - fs/ubifs/ubifs.h | 9 ++------- include/linux/fscrypt_common.h | 1 - 6 files changed, 2 insertions(+), 14 deletions(-)
fs/ext4/super.c +0 -2
@@ -1241,13 +1241,11 @@ static const struct fscrypt_operations ext4_cryptops = { .get_context = ext4_get_context, .set_context = ext4_set_context, .dummy_context = ext4_dummy_context, - .is_encrypted = ext4_encrypted_inode, .empty_dir = ext4_empty_dir, .max_namelen = ext4_max_namelen, };#else static const struct fscrypt_operations ext4_cryptops = { - .is_encrypted = ext4_encrypted_inode, };#endif
fs/f2fs/super.c +0 -2
@@ -1594,13 +1594,11 @@ static const struct fscrypt_operations f2fs_cryptops = { .key_prefix = "f2fs:", .get_context = f2fs_get_context, .set_context = f2fs_set_context, - .is_encrypted = f2fs_encrypted_inode, .empty_dir = f2fs_empty_dir, .max_namelen = f2fs_max_namelen, };#else static const struct fscrypt_operations f2fs_cryptops = { - .is_encrypted = f2fs_encrypted_inode, };#endif
fs/ubifs/crypto.c +0 -1
@@ -87,7 +87,6 @@ const struct fscrypt_operations ubifs_crypt_operations = { .key_prefix = "ubifs:", .get_context = ubifs_crypt_get_context, .set_context = ubifs_crypt_set_context, - .is_encrypted = __ubifs_crypt_is_encrypted, .empty_dir = ubifs_crypt_empty_dir, .max_namelen = ubifs_crypt_max_namelen, };
fs/ubifs/super.c +0 -1
@@ -2009,7 +2009,6 @@ static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi)#ifndef CONFIG_UBIFS_FS_ENCRYPTION const struct fscrypt_operations ubifs_crypt_operations = { - .is_encrypted = __ubifs_crypt_is_encrypted, };#endif
fs/ubifs/ubifs.h +2 -6
@@ -1835,18 +1835,13 @@ int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,extern const struct fscrypt_operations ubifs_crypt_operations; -static inline bool __ubifs_crypt_is_encrypted (struct inode *inode) +static inline bool ubifs_crypt_is_encrypted (const struct inode *inode) { -struct ubifs_inode *ui =ubifs_inode (inode); +const struct ubifs_inode *ui =ubifs_inode (inode);return ui->flags &UBIFS_CRYPT_FL ; } -static inline bool ubifs_crypt_is_encrypted (const struct inode *inode) -{ -return __ubifs_crypt_is_encrypted ((struct inode *)inode); -}
PATCH 4/25 fscrypt: remove unneeded empty fscrypt_operations structs
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
In the case where a filesystem has been configured without encryption support, there is no longer any need to initialize ->s_cop at all, since none of the methods are ever called.
--- fs/ext4/super.c | 5 ++--- fs/f2fs/super.c | 5 ++--- fs/ubifs/super.c | 7 ++----- 3 files changed, 6 insertions(+), 11 deletions(-)
fs/ext4/super.c +2 -3
@@ -1244,9 +1244,6 @@ static const struct fscrypt_operations ext4_cryptops = { .empty_dir = ext4_empty_dir, .max_namelen = ext4_max_namelen, }; -#else -static const struct fscrypt_operations ext4_cryptops = { -};#endif #ifdef CONFIG_QUOTA
@@ -3998,7 +3995,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sb->s_op = &ext4_sops; sb->s_export_op = &ext4_export_ops; sb->s_xattr = ext4_xattr_handlers; +#ifdef CONFIG_EXT4_FS_ENCRYPTION sb->s_cop = &ext4_cryptops; +#endif #ifdef CONFIG_QUOTA sb->dq_op = &ext4_quota_operations;if (ext4_has_feature_quota (sb))
fs/f2fs/super.c +2 -3
@@ -1597,9 +1597,6 @@ static const struct fscrypt_operations f2fs_cryptops = { .empty_dir = f2fs_empty_dir, .max_namelen = f2fs_max_namelen, }; -#else -static const struct fscrypt_operations f2fs_cryptops = { -};#endif static struct inode *f2fs_nfs_get_inode(struct super_block *sb,
@@ -2318,7 +2315,9 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)#endif sb->s_op = &f2fs_sops; +#ifdef CONFIG_F2FS_FS_ENCRYPTION sb->s_cop = &f2fs_cryptops; +#endif sb->s_xattr = f2fs_xattr_handlers; sb->s_export_op = &f2fs_export_ops; sb->s_magic =F2FS_SUPER_MAGIC ;
fs/ubifs/super.c +2 -5
@@ -2007,11 +2007,6 @@ static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi)return c; } -#ifndef CONFIG_UBIFS_FS_ENCRYPTION -const struct fscrypt_operations ubifs_crypt_operations = { -}; -#endif -static int ubifs_fill_super (struct super_block *sb,void *data,int silent) {struct ubifs_info *c = sb->s_fs_info;
@@ -2054,7 +2049,9 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent) sb->s_maxbytes = c->max_inode_sz =MAX_LFS_FILESIZE ; sb->s_op = &ubifs_super_operations; sb->s_xattr = ubifs_xattr_handlers; +#ifdef CONFIG_UBIFS_FS_ENCRYPTION sb->s_cop = &ubifs_crypt_operations; +#endif mutex_lock (&c->umount_mutex); err =mount_ubifs (c);
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 5/25 fscrypt: new helper function - fscrypt_require_key()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Add a helper function which checks if an inode is encrypted, and if so, tries to set up its encryption key. This is a pattern which is duplicated in multiple places in each of ext4, f2fs, and ubifs --- for example, when a regular file is asked to be opened or truncated.
--- include/linux/fscrypt_notsupp.h | 8 ++++++++ include/linux/fscrypt_supp.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
include/linux/fscrypt_notsupp.h +8 -0
@@ -174,4 +174,12 @@ static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, return -EOPNOTSUPP; } +/* hooks.c */ +static inline int fscrypt_require_key (struct inode *inode) +{ +if (IS_ENCRYPTED (inode)) +return -EOPNOTSUPP ; +return 0 ; +} +#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
include/linux/fscrypt_supp.h +28 -0
@@ -142,4 +142,32 @@ extern void fscrypt_pullback_bio_page(struct page **, bool);extern int fscrypt_zeroout_range (const struct inode *,pgoff_t ,sector_t ,unsigned int ); +/* hooks.c */ + +/** +* fscrypt_require_key - require an inode's encryption key +* @inode: the inode we need the key for +* +* If the inode is encrypted, set up its encryption key if not already done. +* Then require that the key be present and return -ENOKEY otherwise. +* +* No locks are needed, and currently the key will live as long as the struct +* inode --- so it won't go away from under you. +* +* Return: 0 on success, -ENOKEY if the key is missing, or another -errno code +* if a problem occurred while setting up the encryption key. +*/ +static inline int fscrypt_require_key (struct inode *inode) +{ +if (IS_ENCRYPTED (inode)) { +int err =fscrypt_get_encryption_info (inode); + +if (err) +return err; +if (!fscrypt_has_encryption_key (inode)) +return -ENOKEY ; + } +return 0 ; +} +#endif /* _LINUX_FSCRYPT_SUPP_H */
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 6/25 fscrypt: new helper function - fscrypt_file_open()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Add a helper function which prepares to open a regular file which may be encrypted. It handles setting up the file's encryption key, then checking that the file's encryption policy matches that of its parent directory (if the parent directory is encrypted). It may be set as the ->open() method or it can be called from another ->open() method.
--- fs/crypto/Makefile | 2 +- fs/crypto/hooks.c | 49 +++++++++++++++++++++++++++++++++++++++++ include/linux/fscrypt_notsupp.h | 7 ++++++ include/linux/fscrypt_supp.h | 2 ++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 fs/crypto/hooks.c
fs/crypto/Makefile +1 -1
@@ -1,4 +1,4 @@ obj-$(CONFIG_FS_ENCRYPTION) += fscrypto.o -fscrypto-y := crypto.o fname.o policy.o keyinfo.o +fscrypto-y := crypto.o fname.o hooks.o keyinfo.o policy.o fscrypto-$(CONFIG_BLOCK) += bio.o
fs/crypto/hooks.c new file +49 -0
49 lines not on this page · raw message
include/linux/fscrypt_notsupp.h +7 -0
@@ -182,4 +182,11 @@ static inline int fscrypt_require_key(struct inode *inode) return 0; } +static inline int fscrypt_file_open (struct inode *inode,struct file *filp) +{ +if (IS_ENCRYPTED (inode)) +return -EOPNOTSUPP ; +return 0 ; +} +#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
include/linux/fscrypt_supp.h +2 -0
@@ -170,4 +170,6 @@ static inline int fscrypt_require_key(struct inode *inode) return 0; } +extern int fscrypt_file_open (struct inode *inode,struct file *filp); +#endif /* _LINUX_FSCRYPT_SUPP_H */
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 7/25 fscrypt: new helper function - fscrypt_prepare_link()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Introduce a helper function which prepares to link an inode into a possibly-encrypted directory. It handles setting up the target directory's encryption key, then verifying that the link won't violate the constraint that all files in an encrypted directory tree use the same encryption policy.
--- fs/crypto/hooks.c | 15 +++++++++++++++ include/linux/fscrypt_notsupp.h | 9 +++++++++ include/linux/fscrypt_supp.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+)
fs/crypto/hooks.c +15 -0
@@ -47,3 +47,18 @@ int fscrypt_file_open(struct inode *inode, struct file *filp)return err; }EXPORT_SYMBOL_GPL (fscrypt_file_open); + +int __fscrypt_prepare_link (struct inode *inode,struct inode *dir) +{ +int err; + + err =fscrypt_require_key (dir); +if (err) +return err; + +if (!fscrypt_has_permitted_context (dir, inode)) +return -EPERM ; + +return 0 ; +} +EXPORT_SYMBOL_GPL (__fscrypt_prepare_link);
include/linux/fscrypt_notsupp.h +9 -0
@@ -189,4 +189,13 @@ static inline int fscrypt_file_open(struct inode *inode, struct file *filp) return 0; } +static inline int fscrypt_prepare_link (struct dentry *old_dentry, +struct inode *dir, +struct dentry *dentry) +{ +if (IS_ENCRYPTED (dir)) +return -EOPNOTSUPP ; +return 0 ; +} +#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
include/linux/fscrypt_supp.h +29 -0
@@ -172,4 +172,33 @@ static inline int fscrypt_require_key(struct inode *inode)extern int fscrypt_file_open (struct inode *inode,struct file *filp); +extern int __fscrypt_prepare_link (struct inode *inode,struct inode *dir); + +/** +* fscrypt_prepare_link - prepare to link an inode into a possibly-encrypted directory +* @old_dentry: an existing dentry for the inode being linked +* @dir: the target directory +* @dentry: negative dentry for the target filename +* +* A new link can only be added to an encrypted directory if the directory's +* encryption key is available --- since otherwise we'd have no way to encrypt +* the filename. Therefore, we first set up the directory's encryption key (if +* not already done) and return an error if it's unavailable. +* +* We also verify that the link will not violate the constraint that all files +* in an encrypted directory tree use the same encryption policy. +* +* Return: 0 on success, -ENOKEY if the directory's encryption key is missing, +* -EPERM if the link would result in an inconsistent encryption policy, or +* another -errno code. +*/ +static inline int fscrypt_prepare_link (struct dentry *old_dentry, +struct inode *dir, +struct dentry *dentry) +{ +if (IS_ENCRYPTED (dir)) +return __fscrypt_prepare_link (d_inode (old_dentry), dir); +return 0 ; +} +#endif /* _LINUX_FSCRYPT_SUPP_H */
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
PATCH 8/25 fscrypt: new helper function - fscrypt_prepare_rename()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Introduce a helper function which prepares to rename a file into a possibly encrypted directory. It handles loading the encryption keys for the source and target directories if needed, and it handles enforcing that if the target directory (and the source directory for a cross-rename) is encrypted, then the file being moved into the directory has the same encryption policy as its containing directory.
--- fs/crypto/hooks.c | 30 ++++++++++++++++++++++++++++++ include/linux/fscrypt_notsupp.h | 11 +++++++++++ include/linux/fscrypt_supp.h | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+)
fs/crypto/hooks.c +30 -0
@@ -62,3 +62,33 @@ int __fscrypt_prepare_link(struct inode *inode, struct inode *dir)return 0 ; }EXPORT_SYMBOL_GPL (__fscrypt_prepare_link); + +int __fscrypt_prepare_rename (struct inode *old_dir,struct dentry *old_dentry, +struct inode *new_dir,struct dentry *new_dentry, +unsigned int flags) +{ +int err; + + err =fscrypt_require_key (old_dir); +if (err) +return err; + + err =fscrypt_require_key (new_dir); +if (err) +return err; + +if (old_dir != new_dir) { +if (IS_ENCRYPTED (new_dir) && + !fscrypt_has_permitted_context (new_dir, +d_inode (old_dentry))) +return -EPERM ; + +if ((flags &RENAME_EXCHANGE ) && +IS_ENCRYPTED (old_dir) && + !fscrypt_has_permitted_context (old_dir, +d_inode (new_dentry))) +return -EPERM ; + } +return 0 ; +} +EXPORT_SYMBOL_GPL (__fscrypt_prepare_rename);
include/linux/fscrypt_notsupp.h +11 -0
@@ -198,4 +198,15 @@ static inline int fscrypt_prepare_link(struct dentry *old_dentry, return 0; } +static inline int fscrypt_prepare_rename (struct inode *old_dir, +struct dentry *old_dentry, +struct inode *new_dir, +struct dentry *new_dentry, +unsigned int flags) +{ +if (IS_ENCRYPTED (old_dir) ||IS_ENCRYPTED (new_dir)) +return -EOPNOTSUPP ; +return 0 ; +} +#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
include/linux/fscrypt_supp.h +39 -0
@@ -201,4 +201,43 @@ static inline int fscrypt_prepare_link(struct dentry *old_dentry, return 0; } +extern int __fscrypt_prepare_rename (struct inode *old_dir, +struct dentry *old_dentry, +struct inode *new_dir, +struct dentry *new_dentry, +unsigned int flags); + +/** +* fscrypt_prepare_rename - prepare for a rename between possibly-encrypted directories +* @old_dir: source directory +* @old_dentry: dentry for source file +* @new_dir: target directory +* @new_dentry: dentry for target location (may be negative unless exchanging) +* @flags: rename flags (we care at least about %RENAME_EXCHANGE) +* +* Prepare for ->rename() where the source and/or target directories may be +* encrypted. A new link can only be added to an encrypted directory if the +* directory's encryption key is available --- since otherwise we'd have no way +* to encrypt the filename. A rename to an existing name, on the other hand, +* *is* cryptographically possible without the key. However, we take the more +* conservative approach and just forbid all no-key renames. +* +* We also verify that the rename will not violate the constraint that all files +* in an encrypted directory tree use the same encryption policy. +* +* Return: 0 on success, -ENOKEY if an encryption key is missing, -EPERM if the +* rename would cause inconsistent encryption policies, or another -errno code. +*/ +static inline int fscrypt_prepare_rename (struct inode *old_dir, +struct dentry *old_dentry, +struct inode *new_dir, +struct dentry *new_dentry, +unsigned int flags) +{ +if (IS_ENCRYPTED (old_dir) ||IS_ENCRYPTED (new_dir)) +return __fscrypt_prepare_rename (old_dir, old_dentry, + new_dir, new_dentry, flags); +return 0 ; +} +#endif /* _LINUX_FSCRYPT_SUPP_H */
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
PATCH 9/25 fscrypt: new helper function - fscrypt_prepare_lookup()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Introduce a helper function which prepares to look up the given dentry in the given directory. If the directory is encrypted, it handles loading the directory's encryption key, setting the dentry's ->d_op to fscrypt_d_ops, and setting DCACHE_ENCRYPTED_WITH_KEY if the directory's encryption key is available.
Note: once all filesystems switch over to this, we'll be able to move fscrypt_d_ops and fscrypt_set_encrypted_dentry() to fscrypt_private.h.
--- fs/crypto/hooks.c | 18 ++++++++++++++++++ include/linux/fscrypt_notsupp.h | 9 +++++++++ include/linux/fscrypt_supp.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+)
fs/crypto/hooks.c +18 -0
@@ -92,3 +92,21 @@ int __fscrypt_prepare_rename(struct inode *old_dir, struct dentry *old_dentry,return 0 ; }EXPORT_SYMBOL_GPL (__fscrypt_prepare_rename); + +int __fscrypt_prepare_lookup (struct inode *dir,struct dentry *dentry) +{ +int err =fscrypt_get_encryption_info (dir); + +if (err) +return err; + +if (fscrypt_has_encryption_key (dir)) { +spin_lock (&dentry->d_lock); + dentry->d_flags |=DCACHE_ENCRYPTED_WITH_KEY ; +spin_unlock (&dentry->d_lock); + } + +d_set_d_op (dentry, &fscrypt_d_ops); +return 0 ; +} +EXPORT_SYMBOL_GPL (__fscrypt_prepare_lookup);
include/linux/fscrypt_notsupp.h +9 -0
@@ -209,4 +209,13 @@ static inline int fscrypt_prepare_rename(struct inode *old_dir, return 0; } +static inline int fscrypt_prepare_lookup (struct inode *dir, +struct dentry *dentry, +unsigned int flags) +{ +if (IS_ENCRYPTED (dir)) +return -EOPNOTSUPP ; +return 0 ; +} +#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
include/linux/fscrypt_supp.h +30 -0
@@ -240,4 +240,34 @@ static inline int fscrypt_prepare_rename(struct inode *old_dir, return 0; } +extern int __fscrypt_prepare_lookup (struct inode *dir,struct dentry *dentry); + +/** +* fscrypt_prepare_lookup - prepare to lookup a name in a possibly-encrypted directory +* @dir: directory being searched +* @dentry: filename being looked up +* @flags: lookup flags +* +* Prepare for ->lookup() in a directory which may be encrypted. Lookups can be +* done with or without the directory's encryption key; without the key, +* filenames are presented in encrypted form. Therefore, we'll try to set up +* the directory's encryption key, but even without it the lookup can continue. +* +* To allow invalidating stale dentries if the directory's encryption key is +* added later, we also install a custom ->d_revalidate() method and use the +* DCACHE_ENCRYPTED_WITH_KEY flag to indicate whether a given dentry is a +* plaintext name (flag set) or a ciphertext name (flag cleared). +* +* Return: 0 on success, -errno if a problem occurred while setting up the +* encryption key +*/ +static inline int fscrypt_prepare_lookup (struct inode *dir, +struct dentry *dentry, +unsigned int flags) +{ +if (IS_ENCRYPTED (dir)) +return __fscrypt_prepare_lookup (dir, dentry); +return 0 ; +} +#endif /* _LINUX_FSCRYPT_SUPP_H */
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 10/25 fscrypt: new helper function - fscrypt_prepare_setattr()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Introduce a helper function for filesystems to call when processing ->setattr() on a possibly-encrypted inode. It handles enforcing that an encrypted file can only be truncated if its encryption key is available.
--- include/linux/fscrypt_notsupp.h | 8 ++++++++ include/linux/fscrypt_supp.h | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/linux/fscrypt_notsupp.h +8 -0
@@ -218,4 +218,12 @@ static inline int fscrypt_prepare_lookup(struct inode *dir, return 0; } +static inline int fscrypt_prepare_setattr (struct dentry *dentry, +struct iattr *attr) +{ +if (IS_ENCRYPTED (d_inode (dentry)) && (attr->ia_valid &ATTR_SIZE )) +return -EOPNOTSUPP ; +return 0 ; +} +#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
include/linux/fscrypt_supp.h +25 -0
@@ -270,4 +270,29 @@ static inline int fscrypt_prepare_lookup(struct inode *dir, return 0; } +/** +* fscrypt_prepare_setattr - prepare to change a possibly-encrypted inode's attributes +* @dentry: dentry through which the inode is being changed +* @attr: attributes to change +* +* Prepare for ->setattr() on a possibly-encrypted inode. On an encrypted file, +* most attribute changes are allowed even without the encryption key. However, +* without the encryption key we do have to forbid truncates. This is needed +* because the size being truncated to may not be a multiple of the filesystem +* block size, and in that case we'd have to decrypt the final block, zero the +* portion past i_size, and re-encrypt it. (We *could* allow truncating to a +* filesystem block boundary, but it's simpler to just forbid all truncates --- +* and we already forbid all other contents modifications without the key.) +* +* Return: 0 on success, -ENOKEY if the key is missing, or another -errno code +* if a problem occurred while setting up the encryption key. +*/ +static inline int fscrypt_prepare_setattr (struct dentry *dentry, +struct iattr *attr) +{ +if (IS_ENCRYPTED (d_inode (dentry)) && (attr->ia_valid &ATTR_SIZE )) +return fscrypt_require_key (d_inode (dentry)); +return 0 ; +} +#endif /* _LINUX_FSCRYPT_SUPP_H */
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 11/25 ext4: switch to fscrypt_file_open()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ext4/file.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-)
fs/ext4/file.c +4 -19
@@ -364,7 +364,6 @@ static int ext4_file_open(struct inode * inode, struct file * filp)struct super_block *sb = inode->i_sb;struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);struct vfsmount *mnt = filp->f_path.mnt; -struct dentry *dir;struct path path;char buf[64 ], *cp;int ret;
@@ -404,25 +403,11 @@ static int ext4_file_open(struct inode * inode, struct file * filp)ext4_journal_stop (handle); } } -if (ext4_encrypted_inode (inode)) { - ret =fscrypt_get_encryption_info (inode); -if (ret) -return -EACCES ; -if (!fscrypt_has_encryption_key (inode)) -return -ENOKEY ; - } - dir =dget_parent (file_dentry (filp)); -if (ext4_encrypted_inode (d_inode (dir)) && - !fscrypt_has_permitted_context (d_inode (dir), inode)) { -ext4_warning (inode->i_sb, -"Inconsistent encryption contexts: %lu/%lu" , - (unsigned long )d_inode (dir)->i_ino, - (unsigned long ) inode->i_ino); -dput (dir); -return -EPERM ; - } -dput (dir); + ret =fscrypt_file_open (inode, filp); +if (ret) +return ret; +/* * Set up the jbd2_inode if we are opening the inode for * writing and the journal is present
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 12/25 ext4: switch to fscrypt_prepare_link()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ext4/namei.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/ext4/namei.c +4 -3
@@ -3221,9 +3221,10 @@ static int ext4_link(struct dentry *old_dentry,if (inode->i_nlink >=EXT4_LINK_MAX )return -EMLINK ; -if (ext4_encrypted_inode (dir) && - !fscrypt_has_permitted_context (dir, inode)) -return -EPERM ; + + err =fscrypt_prepare_link (old_dentry, dir, dentry); +if (err) +return err; if ((ext4_test_inode_flag(dir, EXT4_INODE_PROJINHERIT)) && (!projid_eq(EXT4_I(dir)->i_projid,
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 13/25 ext4: switch to fscrypt_prepare_rename()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ext4/namei.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-)
fs/ext4/namei.c +7 -26
@@ -3516,12 +3516,6 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, EXT4_I(old_dentry->d_inode)->i_projid)))return -EXDEV ; -if ((ext4_encrypted_inode (old_dir) && - !fscrypt_has_encryption_key (old_dir)) || - (ext4_encrypted_inode (new_dir) && - !fscrypt_has_encryption_key (new_dir))) -return -ENOKEY ; - retval =dquot_initialize (old.dir);if (retval)return retval;
@@ -3550,13 +3544,6 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,if (!old.bh ||le32_to_cpu (old.de->inode) != old.inode->i_ino) goto end_rename; -if ((old.dir != new.dir) && -ext4_encrypted_inode (new.dir) && - !fscrypt_has_permitted_context (new.dir, old.inode)) { - retval = -EPERM ; - goto end_rename; - } - new.bh =ext4_find_entry (new.dir, &new.dentry->d_name, &new.de, &new.inlined);if (IS_ERR (new.bh)) {
@@ -3722,19 +3709,6 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,int retval;struct timespec ctime; -if ((ext4_encrypted_inode (old_dir) && - !fscrypt_has_encryption_key (old_dir)) || - (ext4_encrypted_inode (new_dir) && - !fscrypt_has_encryption_key (new_dir))) -return -ENOKEY ; - -if ((ext4_encrypted_inode (old_dir) || -ext4_encrypted_inode (new_dir)) && - (old_dir != new_dir) && - (!fscrypt_has_permitted_context (new_dir, old.inode) || - !fscrypt_has_permitted_context (old_dir, new.inode))) -return -EPERM ; - if ((ext4_test_inode_flag(new_dir, EXT4_INODE_PROJINHERIT) && !projid_eq(EXT4_I(new_dir)->i_projid, EXT4_I(old_dentry->d_inode)->i_projid)) ||
@@ -3861,12 +3835,19 @@ static int ext4_rename2(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) { + int err; +if (unlikely (ext4_forced_shutdown (EXT4_SB (old_dir->i_sb))))return -EIO ;if (flags & ~(RENAME_NOREPLACE |RENAME_EXCHANGE |RENAME_WHITEOUT ))return -EINVAL ; + err =fscrypt_prepare_rename (old_dir, old_dentry, new_dir, new_dentry, + flags); +if (err) +return err; +if (flags &RENAME_EXCHANGE ) {return ext4_cross_rename (old_dir, old_dentry, new_dir, new_dentry);
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 14/25 ext4: switch to fscrypt_prepare_lookup()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ext4/namei.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
fs/ext4/namei.c +6 -16
@@ -1538,24 +1538,14 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsistruct inode *inode;struct ext4_dir_entry_2 *de;struct buffer_head *bh; +int err; -if (ext4_encrypted_inode (dir)) { -int res =fscrypt_get_encryption_info (dir); - -/* -* DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is -* created while the directory was encrypted and we -* have access to the key. -*/ -if (fscrypt_has_encryption_key (dir)) -fscrypt_set_encrypted_dentry (dentry); -fscrypt_set_d_op (dentry); -if (res && res != -ENOKEY ) -return ERR_PTR (res); - } + err =fscrypt_prepare_lookup (dir, dentry, flags); +if (err) +return ERR_PTR (err); -if (dentry->d_name.len >EXT4_NAME_LEN ) -return ERR_PTR (-ENAMETOOLONG ); +if (dentry->d_name.len >EXT4_NAME_LEN ) +return ERR_PTR (-ENAMETOOLONG ); bh =ext4_find_entry (dir, &dentry->d_name, &de,NULL );if (IS_ERR (bh))
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 15/25 ext4: switch to fscrypt_prepare_setattr()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ext4/inode.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
fs/ext4/inode.c +4 -8
@@ -5311,6 +5311,10 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)if (error)return error; + error =fscrypt_prepare_setattr (dentry, attr); +if (error) +return error; +if (is_quota_modification (inode, attr)) { error =dquot_initialize (inode);if (error)
@@ -5356,14 +5360,6 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)loff_t oldsize = inode->i_size;int shrink = (attr->ia_size <= inode->i_size); -if (ext4_encrypted_inode (inode)) { - error =fscrypt_get_encryption_info (inode); -if (error) -return error; -if (!fscrypt_has_encryption_key (inode)) -return -ENOKEY ; - } -if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) {struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 16/25 f2fs: switch to fscrypt_file_open()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/f2fs/file.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-)
fs/f2fs/file.c +3 -15
@@ -455,22 +455,10 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)static int f2fs_file_open (struct inode *inode,struct file *filp) { -struct dentry *dir; +int err =fscrypt_file_open (inode, filp); -if (f2fs_encrypted_inode (inode)) { -int ret =fscrypt_get_encryption_info (inode); -if (ret) -return -EACCES ; -if (!fscrypt_has_encryption_key (inode)) -return -ENOKEY ; - } - dir =dget_parent (file_dentry (filp)); -if (f2fs_encrypted_inode (d_inode (dir)) && - !fscrypt_has_permitted_context (d_inode (dir), inode)) { -dput (dir); -return -EPERM ; - } -dput (dir); +if (err) +return err;return dquot_file_open (inode, filp); }
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
PATCH 17/25 f2fs: switch to fscrypt_prepare_link()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/f2fs/namei.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/namei.c +3 -3
@@ -221,9 +221,9 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,struct f2fs_sb_info *sbi =F2FS_I_SB (dir);int err; -if (f2fs_encrypted_inode (dir) && - !fscrypt_has_permitted_context (dir, inode)) -return -EPERM ; + err =fscrypt_prepare_link (old_dentry, dir, dentry); +if (err) +return err; if (is_inode_flag_set(dir, FI_PROJ_INHERIT) && (!projid_eq(F2FS_I(dir)->i_projid,
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 18/25 f2fs: switch to fscrypt_prepare_rename()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/f2fs/namei.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-)
fs/f2fs/namei.c +7 -24
@@ -742,18 +742,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,bool is_old_inline =f2fs_has_inline_dentry (old_dir);int err = -ENOENT ; -if ((f2fs_encrypted_inode (old_dir) && - !fscrypt_has_encryption_key (old_dir)) || - (f2fs_encrypted_inode (new_dir) && - !fscrypt_has_encryption_key (new_dir))) -return -ENOKEY ; - -if ((old_dir != new_dir) &&f2fs_encrypted_inode (new_dir) && - !fscrypt_has_permitted_context (new_dir, old_inode)) { - err = -EPERM ; - goto out; - } -if (is_inode_flag_set (new_dir,FI_PROJ_INHERIT ) && (!projid_eq (F2FS_I (new_dir)->i_projid,F2FS_I (old_dentry->d_inode)->i_projid)))
@@ -935,18 +923,6 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,int old_nlink =0 , new_nlink =0 ;int err = -ENOENT ; -if ((f2fs_encrypted_inode (old_dir) && - !fscrypt_has_encryption_key (old_dir)) || - (f2fs_encrypted_inode (new_dir) && - !fscrypt_has_encryption_key (new_dir))) -return -ENOKEY ; - -if ((f2fs_encrypted_inode (old_dir) ||f2fs_encrypted_inode (new_dir)) && - (old_dir != new_dir) && - (!fscrypt_has_permitted_context (new_dir, old_inode) || - !fscrypt_has_permitted_context (old_dir, new_inode))) -return -EPERM ; - if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && !projid_eq(F2FS_I(new_dir)->i_projid, F2FS_I(old_dentry->d_inode)->i_projid)) ||
@@ -1086,9 +1062,16 @@ static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) { + int err; +if (flags & ~(RENAME_NOREPLACE |RENAME_EXCHANGE |RENAME_WHITEOUT ))return -EINVAL ; + err =fscrypt_prepare_rename (old_dir, old_dentry, new_dir, new_dentry, + flags); +if (err) +return err; +if (flags &RENAME_EXCHANGE ) {return f2fs_cross_rename (old_dir, old_dentry, new_dir, new_dentry);
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
PATCH 19/25 f2fs: switch to fscrypt_prepare_lookup()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/f2fs/namei.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
fs/f2fs/namei.c +3 -14
@@ -335,20 +335,9 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,int err =0 ;unsigned int root_ino =F2FS_ROOT_INO (F2FS_I_SB (dir)); -if (f2fs_encrypted_inode (dir)) { -int res =fscrypt_get_encryption_info (dir); - -/* -* DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is -* created while the directory was encrypted and we -* don't have access to the key. -*/ -if (fscrypt_has_encryption_key (dir)) -fscrypt_set_encrypted_dentry (dentry); -fscrypt_set_d_op (dentry); -if (res && res != -ENOKEY ) -return ERR_PTR (res); - } + err =fscrypt_prepare_lookup (dir, dentry, flags); +if (err) +return ERR_PTR (err);if (dentry->d_name.len >F2FS_NAME_LEN )return ERR_PTR (-ENAMETOOLONG );
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 20/25 f2fs: switch to fscrypt_prepare_setattr()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/f2fs/file.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
fs/f2fs/file.c +4 -8
@@ -714,6 +714,10 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)if (err)return err; + err =fscrypt_prepare_setattr (dentry, attr); +if (err) +return err; +if (is_quota_modification (inode, attr)) { err =dquot_initialize (inode);if (err)
@@ -729,14 +733,6 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) }if (attr->ia_valid &ATTR_SIZE ) { -if (f2fs_encrypted_inode (inode)) { - err =fscrypt_get_encryption_info (inode); -if (err) -return err; -if (!fscrypt_has_encryption_key (inode)) -return -ENOKEY ; - } -if (attr->ia_size <=i_size_read (inode)) {down_write (&F2FS_I (inode)->i_mmap_sem);truncate_setsize (inode, attr->ia_size);
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 21/25 ubifs: switch to fscrypt_file_open()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ubifs/file.c | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-)
fs/ubifs/file.c +1 -30
@@ -1629,35 +1629,6 @@ static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma)return 0 ; } -static int ubifs_file_open (struct inode *inode,struct file *filp) -{ -int ret; -struct dentry *dir; -struct ubifs_info *c = inode->i_sb->s_fs_info; - -if (ubifs_crypt_is_encrypted (inode)) { - ret =fscrypt_get_encryption_info (inode); -if (ret) -return -EACCES ; -if (!fscrypt_has_encryption_key (inode)) -return -ENOKEY ; - } - - dir =dget_parent (file_dentry (filp)); -if (ubifs_crypt_is_encrypted (d_inode (dir)) && - !fscrypt_has_permitted_context (d_inode (dir), inode)) { -ubifs_err (c,"Inconsistent encryption contexts: %lu/%lu" , - (unsigned long )d_inode (dir)->i_ino, - (unsigned long ) inode->i_ino); -dput (dir); -ubifs_ro_mode (c, -EPERM ); -return -EPERM ; - } -dput (dir); - -return 0 ; -} -static const char *ubifs_get_link (struct dentry *dentry,struct inode *inode,struct delayed_call *done)
@@ -1746,7 +1717,7 @@ const struct file_operations ubifs_file_operations = { .unlocked_ioctl = ubifs_ioctl, .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, - .open = ubifs_file_open, + .open = fscrypt_file_open,#ifdef CONFIG_COMPAT .compat_ioctl = ubifs_compat_ioctl,#endif
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 22/25 ubifs: switch to fscrypt_prepare_link()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ubifs/dir.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ubifs/dir.c +3 -3
@@ -743,9 +743,9 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir,ubifs_assert (inode_is_locked (dir));ubifs_assert (inode_is_locked (inode)); -if (ubifs_crypt_is_encrypted (dir) && - !fscrypt_has_permitted_context (dir, inode)) -return -EPERM ; + err =fscrypt_prepare_link (old_dentry, dir, dentry); +if (err) +return err; err =fscrypt_setup_filename (dir, &dentry->d_name,0 , &nm);if (err)
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 23/25 ubifs: switch to fscrypt_prepare_rename()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ubifs/dir.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
fs/ubifs/dir.c +7 -13
@@ -1353,12 +1353,6 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,if (unlink)ubifs_assert (inode_is_locked (new_inode)); -if (old_dir != new_dir) { -if (ubifs_crypt_is_encrypted (new_dir) && - !fscrypt_has_permitted_context (new_dir, old_inode)) -return -EPERM ; - } -if (unlink && is_dir) { err =ubifs_check_dir_empty (new_inode);if (err)
@@ -1573,13 +1567,6 @@ static int ubifs_xrename(struct inode *old_dir, struct dentry *old_dentry,ubifs_assert (fst_inode && snd_inode); -if ((ubifs_crypt_is_encrypted (old_dir) || -ubifs_crypt_is_encrypted (new_dir)) && - (old_dir != new_dir) && - (!fscrypt_has_permitted_context (new_dir, fst_inode) || - !fscrypt_has_permitted_context (old_dir, snd_inode))) -return -EPERM ; - err =fscrypt_setup_filename (old_dir, &old_dentry->d_name,0 , &fst_nm);if (err)return err;
@@ -1624,12 +1611,19 @@ static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) { + int err; +if (flags & ~(RENAME_NOREPLACE |RENAME_WHITEOUT |RENAME_EXCHANGE ))return -EINVAL ;ubifs_assert (inode_is_locked (old_dir));ubifs_assert (inode_is_locked (new_dir)); + err =fscrypt_prepare_rename (old_dir, old_dentry, new_dir, new_dentry, + flags); +if (err) +return err; +if (flags &RENAME_EXCHANGE )return ubifs_xrename (old_dir, old_dentry, new_dir, new_dentry);
Signature · 6 lines
2.14.1.821.g8fa685d3b7-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 24/25 ubifs: switch to fscrypt_prepare_lookup()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ubifs/dir.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
fs/ubifs/dir.c +3 -14
@@ -220,20 +220,9 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,dbg_gen ("'%pd' in dir ino %lu" , dentry, dir->i_ino); -if (ubifs_crypt_is_encrypted (dir)) { - err =fscrypt_get_encryption_info (dir); - -/* -* DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is -* created while the directory was encrypted and we -* have access to the key. -*/ -if (fscrypt_has_encryption_key (dir)) -fscrypt_set_encrypted_dentry (dentry); -fscrypt_set_d_op (dentry); -if (err && err != -ENOKEY ) -return ERR_PTR (err); - } + err =fscrypt_prepare_lookup (dir, dentry, flags); +if (err) +return ERR_PTR (err); err =fscrypt_setup_filename (dir, &dentry->d_name,1 , &nm);if (err)
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
PATCH 25/25 ubifs: switch to fscrypt_prepare_setattr()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
--- fs/ubifs/file.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
fs/ubifs/file.c +3 -7
@@ -1284,13 +1284,9 @@ int ubifs_setattr(struct dentry *dentry, struct iattr *attr)if (err)return err; -if (ubifs_crypt_is_encrypted (inode) && (attr->ia_valid &ATTR_SIZE )) { - err =fscrypt_get_encryption_info (inode); -if (err) -return err; -if (!fscrypt_has_encryption_key (inode)) -return -ENOKEY ; - } + err =fscrypt_prepare_setattr (dentry, attr); +if (err) +return err;if ((attr->ia_valid &ATTR_SIZE ) && attr->ia_size < inode->i_size)/* Truncation to a smaller size */
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
Quoted 12 lines · Eric Biggers
From: Eric Biggers <[email protected]>
This series reduces code duplication among ext4, f2fs, and ubifs by introducing a
S_ENCRYPTEDinode flag (so we don't have to call back into the filesystem to test the filesystem-specific inode flag), then introducing new helper functions that are called at the beginning of the open, link, rename, lookup, and setattr operations.In the future we maybe should even call these new helpers from the VFS so that each individual filesystem doesn't have to do it. But that's not possible currently because
fs/crypto/can be built as a module.
Quoted 8 lines
Making changes like this is a bit challenging due to interdependencies between fscrypt and the individual filesystems, all of which have different maintainers. For now my intent is that patches 1-10 be taken through the fscrypt tree --- though it's not perfect since patches 1-4 do make some changes to each filesystem, as everyone must set
S_ENCRYPTEDbefore we can use it everywhere in the shared code. But afterwards, patches 11-25 can be picked up by the individual filesystems to switch to the new helpers.
This all looks much nicer. Having just been looking at this stuff, it makes the code much simpler to understand. So:
While I'm here, the fscrypt header file includes are clunky and nasty. I worte a quick patch a couple of days ago to clean it up. See below....
Cheers,
Dave.
Signature · 31 lines
Dave Chinner [email protected] fscrypto: clean up include file mess From: Dave Chinner <[email protected]> Filesystems have to include different header files based on whether they are compiled with encryption support or not. That's nasty and messy. Instead, rationalise the headers so we have a single include fscrypt.h and let it decide what internal implementation to include based on the __FS_HAS_ENCRYPTION define. Filesystems set __FS_HAS_ENCRYPTION before including linux/fscrypt.h if they are built with encryption support. Add guards to prevent fscrypt_supp.h and fscrypt_notsupp.h from being directly included by filesystems. Signed-Off-By: Dave Chinner <[email protected]> --- fs/crypto/fscrypt_private.h | 3 +- fs/ext4/ext4.h | 11 +++---- fs/f2fs/f2fs.h | 8 +++--- fs/ubifs/ubifs.h | 9 +++--- include/linux/{fscrypt_common.h => fscrypt.h} | 41 ++++++++++++++++++--------- include/linux/fscrypt_notsupp.h | 7 +++-- include/linux/fscrypt_supp.h | 7 +++-- 7 files changed, 54 insertions(+), 32 deletions(-)
fs/crypto/fscrypt_private.h +2 -1
@@ -11,7 +11,8 @@#ifndef _FSCRYPT_PRIVATE_H#define _FSCRYPT_PRIVATE_H -#include <linux/fscrypt_supp.h> +#define __FS_HAS_ENCRYPTION 1 +#include <linux/fscrypt.h> #include <crypto/hash.h> /* Encryption parameters */
fs/ext4/ext4.h +6 -5
@@ -33,17 +33,18 @@#include <linux/percpu_counter.h> #include <linux/ratelimit.h> #include <crypto/hash.h> -#ifdef CONFIG_EXT4_FS_ENCRYPTION -#include <linux/fscrypt_supp.h> -#else -#include <linux/fscrypt_notsupp.h> -#endif +#include <linux/falloc.h> #include <linux/percpu-rwsem.h> #ifdef __KERNEL__#include <linux/compat.h> #endif +#ifdef CONFIG_EXT4_FS_ENCRYPTION +#define __FS_HAS_ENCRYPTION 1 +#endif +#include <linux/fscrypt.h> +/* * The fourth extended filesystem constants/structures */
fs/f2fs/f2fs.h +4 -4
@@ -23,12 +23,12 @@#include <linux/bio.h> #include <linux/blkdev.h> #include <linux/quotaops.h> +#include <crypto/hash.h> +#ifdef CONFIG_F2FS_FS_ENCRYPTION -#include <linux/fscrypt_supp.h> -#else -#include <linux/fscrypt_notsupp.h> +#define __FS_HAS_ENCRYPTION 1#endif -#include <crypto/hash.h> +#include <linux/fscrypt.h> #ifdef CONFIG_F2FS_CHECK_FS #define f2fs_bug_on (sbi, condition) BUG_ON(condition)
fs/ubifs/ubifs.h +5 -4
@@ -38,12 +38,13 @@#include <linux/backing-dev.h> #include <linux/security.h> #include <linux/xattr.h> +#include <linux/random.h> +#ifdef CONFIG_UBIFS_FS_ENCRYPTION -#include <linux/fscrypt_supp.h> -#else -#include <linux/fscrypt_notsupp.h> +#define __FS_HAS_ENCRYPTION 1#endif -#include <linux/random.h> +#include <linux/fscrypt.h> +#include "ubifs-media.h" /* Version of this UBIFS implementation */
include/linux/fscrypt.h renamed from include/linux/fscrypt_common.h +28 -13
65 lines not on this page · raw message
include/linux/fscrypt_notsupp.h +5 -2
@@ -3,13 +3,16 @@* * This stubs out the fscrypt functions for filesystems configured without * encryption support. +* +* Do not include this file directly. Use fscrypt.h instead! */ +#ifndef _LINUX_FSCRYPT_H +#error "Incorrect include of linux/fscrypt_notsupp.h!" +#endif #ifndef _LINUX_FSCRYPT_NOTSUPP_H#define _LINUX_FSCRYPT_NOTSUPP_H -#include <linux/fscrypt_common.h> -/* crypto.c */ static inline struct fscrypt_ctx *fscrypt_get_ctx (const struct inode *inode,gfp_t gfp_flags)
include/linux/fscrypt_supp.h +4 -3
@@ -1,14 +1,15 @@/* * fscrypt_supp.h * -* This is included by filesystems configured with encryption support. +* Do not include this file directly. Use fscrypt.h instead! */ +#ifndef _LINUX_FSCRYPT_H +#error "Incorrect include of linux/fscrypt_supp.h!" +#endif #ifndef _LINUX_FSCRYPT_SUPP_H#define _LINUX_FSCRYPT_SUPP_H -#include <linux/fscrypt_common.h> -/* crypto.c */ extern struct kmem_cache *fscrypt_info_cachep;extern struct fscrypt_ctx *fscrypt_get_ctx (const struct inode *,gfp_t );
Hi Dave,
Quoted 8 lines · Dave Chinner
fscrypto: clean up include file mess
From: Dave Chinner <[email protected]>
Filesystems have to include different header files based on whether they are compiled with encryption support or not. That's nasty and messy.
Quoted 8 lines
Instead, rationalise the headers so we have a single include
fscrypt.hand let it decide what internal implementation to include based on the__FS_HAS_ENCRYPTIONdefine. Filesystems set__FS_HAS_ENCRYPTIONbefore includinglinux/fscrypt.hif they are built with encryption support.Add guards to prevent
fscrypt_supp.handfscrypt_notsupp.hfrom being directly included by filesystems.
This looks good; we probably should have done it that way originally. This will allow us to have the inline functions like fscrypt_prepare_rename() defined in fscrypt.h, and then have supp/notsupp versions of __fscrypt_prepare_rename() instead --- so common checks like for IS_ENCRYPTED() will be in one place only.
One nit:
fs/ext4/ext4.h line 46
Quoted 4 lines
fs/ext4/ext4.h +4
-0+#ifdef CONFIG_EXT4_FS_ENCRYPTION +#define __FS_HAS_ENCRYPTION 1 +#endif +#include <linux/fscrypt.h>
How about doing
#define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_EXT4_FS_ENCRYPTION)
(and likewise for f2fs and ubifs), then checking '#if __FS_HAS_ENCRYPTION' rather than '#ifdef __FS_HAS_ENCRYPTION'?
Eric
Quoted 17 lines · Eric Biggers
Hi Dave,
Quoted 14 lines · Dave Chinner
fscrypto: clean up include file mess
From: Dave Chinner <[email protected]>
Filesystems have to include different header files based on whether they are compiled with encryption support or not. That's nasty and messy.
Instead, rationalise the headers so we have a single include
fscrypt.hand let it decide what internal implementation to include based on the__FS_HAS_ENCRYPTIONdefine. Filesystems set__FS_HAS_ENCRYPTIONbefore includinglinux/fscrypt.hif they are built with encryption support.
Quoted 7 lines
Quoted 2 lines
Add guards to prevent
fscrypt_supp.handfscrypt_notsupp.hfrom being directly included by filesystems.This looks good; we probably should have done it that way originally. This will allow us to have the inline functions like
fscrypt_prepare_rename()defined infscrypt.h, and then have supp/notsupp versions of__fscrypt_prepare_rename()instead --- so common checks like forIS_ENCRYPTED()will be in one place only.
*nod*
Quoted 9 lines
One nit:
fs/ext4/ext4.h line 46
Quoted 4 lines
fs/ext4/ext4.h +4
-0+#ifdef CONFIG_EXT4_FS_ENCRYPTION +#define __FS_HAS_ENCRYPTION 1 +#endif +#include <linux/fscrypt.h> How about doing
Quoted 4 lines
#define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_EXT4_FS_ENCRYPTION)(and likewise for f2fs and ubifs), then checking '#if
__FS_HAS_ENCRYPTION' rather than '#ifdef__FS_HAS_ENCRYPTION'?
Yeah, that's cleaner. I'll modify it and resend as a standalone patch.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 12 lines · Eric Biggers
From: Eric Biggers <[email protected]>
This series reduces code duplication among ext4, f2fs, and ubifs by introducing a
S_ENCRYPTEDinode flag (so we don't have to call back into the filesystem to test the filesystem-specific inode flag), then introducing new helper functions that are called at the beginning of the open, link, rename, lookup, and setattr operations.In the future we maybe should even call these new helpers from the VFS so that each individual filesystem doesn't have to do it. But that's not possible currently because
fs/crypto/can be built as a module.
Quoted 8 lines
Making changes like this is a bit challenging due to interdependencies between fscrypt and the individual filesystems, all of which have different maintainers. For now my intent is that patches 1-10 be taken through the fscrypt tree --- though it's not perfect since patches 1-4 do make some changes to each filesystem, as everyone must set
S_ENCRYPTEDbefore we can use it everywhere in the shared code. But afterwards, patches 11-25 can be picked up by the individual filesystems to switch to the new helpers.
For all patches touching f2fs, looks good to me, feel free to add:
Quoted 57 lines
Eric Biggers (25):
fs, fscrypt: add anS_ENCRYPTEDinode flag
fscrypt: switch from ->is_encrypted() toIS_ENCRYPTED()
fscrypt: remove ->is_encrypted()
fscrypt: remove unneeded emptyfscrypt_operationsstructs
fscrypt: new helper function -fscrypt_require_key()
fscrypt: new helper function -fscrypt_file_open()
fscrypt: new helper function -fscrypt_prepare_link()
fscrypt: new helper function -fscrypt_prepare_rename()
fscrypt: new helper function -fscrypt_prepare_lookup()
fscrypt: new helper function -fscrypt_prepare_setattr()
ext4: switch tofscrypt_file_open()
ext4: switch tofscrypt_prepare_link()
ext4: switch tofscrypt_prepare_rename()
ext4: switch tofscrypt_prepare_lookup()
ext4: switch tofscrypt_prepare_setattr()
f2fs: switch tofscrypt_file_open()
f2fs: switch tofscrypt_prepare_link()
f2fs: switch tofscrypt_prepare_rename()
f2fs: switch tofscrypt_prepare_lookup()
f2fs: switch tofscrypt_prepare_setattr()
ubifs: switch tofscrypt_file_open()
ubifs: switch tofscrypt_prepare_link()
ubifs: switch tofscrypt_prepare_rename()
ubifs: switch tofscrypt_prepare_lookup()
ubifs: switch tofscrypt_prepare_setattr()fs/crypto/Makefile | 2 +- fs/crypto/crypto.c | 2 +- fs/crypto/fname.c | 3 +- fs/crypto/hooks.c | 112 +++++++++++++++++++++++++++++ fs/crypto/keyinfo.c | 2 +- fs/crypto/policy.c | 6 +- fs/ext4/file.c | 23 ++---- fs/ext4/inode.c | 19 +++-- fs/ext4/namei.c | 62 +++++----------- fs/ext4/super.c | 15 ++-- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 30 ++------ fs/f2fs/inode.c | 5 +- fs/f2fs/namei.c | 54 ++++---------- fs/f2fs/super.c | 7 +- fs/ubifs/crypto.c | 1 - fs/ubifs/dir.c | 43 ++++------- fs/ubifs/file.c | 41 ++--------- fs/ubifs/ioctl.c | 5 +- fs/ubifs/super.c | 8 +-- fs/ubifs/ubifs.h | 9 +-- fs/ubifs/xattr.c | 1 + include/linux/fs.h | 2 + include/linux/fscrypt_common.h | 1 - include/linux/fscrypt_notsupp.h | 54 +++++++++++++- include/linux/fscrypt_supp.h | 153 ++++++++++++++++++++++++++++++++++++++++ 26 files changed, 418 insertions(+), 243 deletions(-) create mode 100644 fs/crypto/hooks.c