aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Rosenberg2020-11-19 00:09:03 -0600
committerJaegeuk Kim2020-12-21 15:33:13 -0600
commit39c8e0ea669518f928a691b44e15241c4bccc264 (patch)
treece5abc2055fc6a2d7cb0f827ffd6424c92f64556
parentc35a25795ed5cbcdf1ca93959ae8e5ec49822ace (diff)
downloadkernel-39c8e0ea669518f928a691b44e15241c4bccc264.tar.gz
kernel-39c8e0ea669518f928a691b44e15241c4bccc264.tar.xz
kernel-39c8e0ea669518f928a691b44e15241c4bccc264.zip
fscrypt: Have filesystems handle their d_ops
This shifts the responsibility of setting up dentry operations from fscrypt to the individual filesystems, allowing them to have their own operations while still setting fscrypt's d_revalidate as appropriate. Most filesystems can just use generic_set_encrypted_ci_d_ops, unless they have their own specific dentry operations as well. That operation will set the minimal d_ops required under the circumstances. Since the fscrypt d_ops are set later on, we must set all d_ops there, since we cannot adjust those later on. This should not result in any change in behavior. Signed-off-by: Daniel Rosenberg <drosen@google.com> Acked-by: Theodore Ts'o <tytso@mit.edu> Acked-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/crypto/fname.c4
-rw-r--r--fs/crypto/fscrypt_private.h1
-rw-r--r--fs/crypto/hooks.c1
-rw-r--r--fs/ext4/dir.c7
-rw-r--r--fs/ext4/ext4.h4
-rw-r--r--fs/ext4/namei.c1
-rw-r--r--fs/ext4/super.c5
-rw-r--r--fs/f2fs/dir.c7
-rw-r--r--fs/f2fs/f2fs.h3
-rw-r--r--fs/f2fs/namei.c1
-rw-r--r--fs/f2fs/super.c1
-rw-r--r--fs/ubifs/dir.c1
-rw-r--r--include/linux/fscrypt.h7
13 files changed, 8 insertions, 35 deletions
diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c
index 1fbe6c24d705..cb3cfa6329ba 100644
--- a/fs/crypto/fname.c
+++ b/fs/crypto/fname.c
@@ -570,7 +570,3 @@ int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags)
570 return valid; 570 return valid;
571} 571}
572EXPORT_SYMBOL_GPL(fscrypt_d_revalidate); 572EXPORT_SYMBOL_GPL(fscrypt_d_revalidate);
573
574const struct dentry_operations fscrypt_d_ops = {
575 .d_revalidate = fscrypt_d_revalidate,
576};
diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
index 4f5806a3b73d..df9c48c1fbf7 100644
--- a/fs/crypto/fscrypt_private.h
+++ b/fs/crypto/fscrypt_private.h
@@ -294,7 +294,6 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname,
294bool fscrypt_fname_encrypted_size(const union fscrypt_policy *policy, 294bool fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,
295 u32 orig_len, u32 max_len, 295 u32 orig_len, u32 max_len,
296 u32 *encrypted_len_ret); 296 u32 *encrypted_len_ret);
297extern const struct dentry_operations fscrypt_d_ops;
298 297
299/* hkdf.c */ 298/* hkdf.c */
300 299
diff --git a/fs/crypto/hooks.c b/fs/crypto/hooks.c
index 20b0df47fe6a..9006fa983335 100644
--- a/fs/crypto/hooks.c
+++ b/fs/crypto/hooks.c
@@ -117,7 +117,6 @@ int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
117 spin_lock(&dentry->d_lock); 117 spin_lock(&dentry->d_lock);
118 dentry->d_flags |= DCACHE_NOKEY_NAME; 118 dentry->d_flags |= DCACHE_NOKEY_NAME;
119 spin_unlock(&dentry->d_lock); 119 spin_unlock(&dentry->d_lock);
120 d_set_d_op(dentry, &fscrypt_d_ops);
121 } 120 }
122 return err; 121 return err;
123} 122}
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index ca50c90adc4c..e757319a4472 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -667,10 +667,3 @@ const struct file_operations ext4_dir_operations = {
667 .open = ext4_dir_open, 667 .open = ext4_dir_open,
668 .release = ext4_release_dir, 668 .release = ext4_release_dir,
669}; 669};
670
671#ifdef CONFIG_UNICODE
672const struct dentry_operations ext4_dentry_ops = {
673 .d_hash = generic_ci_d_hash,
674 .d_compare = generic_ci_d_compare,
675};
676#endif
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 65ecaf96d0a4..c64ea8f59ea7 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3381,10 +3381,6 @@ static inline void ext4_unlock_group(struct super_block *sb,
3381/* dir.c */ 3381/* dir.c */
3382extern const struct file_operations ext4_dir_operations; 3382extern const struct file_operations ext4_dir_operations;
3383 3383
3384#ifdef CONFIG_UNICODE
3385extern const struct dentry_operations ext4_dentry_ops;
3386#endif
3387
3388/* file.c */ 3384/* file.c */
3389extern const struct inode_operations ext4_file_inode_operations; 3385extern const struct inode_operations ext4_file_inode_operations;
3390extern const struct file_operations ext4_file_operations; 3386extern const struct file_operations ext4_file_operations;
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 33509266f5a0..12a417ff5648 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1614,6 +1614,7 @@ static struct buffer_head *ext4_lookup_entry(struct inode *dir,
1614 struct buffer_head *bh; 1614 struct buffer_head *bh;
1615 1615
1616 err = ext4_fname_prepare_lookup(dir, dentry, &fname); 1616 err = ext4_fname_prepare_lookup(dir, dentry, &fname);
1617 generic_set_encrypted_ci_d_ops(dentry);
1617 if (err == -ENOENT) 1618 if (err == -ENOENT)
1618 return NULL; 1619 return NULL;
1619 if (err) 1620 if (err)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 94472044f4c1..2d111aa7f722 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4964,11 +4964,6 @@ no_journal:
4964 goto failed_mount4; 4964 goto failed_mount4;
4965 } 4965 }
4966 4966
4967#ifdef CONFIG_UNICODE
4968 if (sb->s_encoding)
4969 sb->s_d_op = &ext4_dentry_ops;
4970#endif
4971
4972 sb->s_root = d_make_root(root); 4967 sb->s_root = d_make_root(root);
4973 if (!sb->s_root) { 4968 if (!sb->s_root) {
4974 ext4_msg(sb, KERN_ERR, "get root dentry failed"); 4969 ext4_msg(sb, KERN_ERR, "get root dentry failed");
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 4b9ef8bbfa4a..71fdf5076461 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -1099,10 +1099,3 @@ const struct file_operations f2fs_dir_operations = {
1099 .compat_ioctl = f2fs_compat_ioctl, 1099 .compat_ioctl = f2fs_compat_ioctl,
1100#endif 1100#endif
1101}; 1101};
1102
1103#ifdef CONFIG_UNICODE
1104const struct dentry_operations f2fs_dentry_ops = {
1105 .d_hash = generic_ci_d_hash,
1106 .d_compare = generic_ci_d_compare,
1107};
1108#endif
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 99bcf4b44a9c..01fd42843e49 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3688,9 +3688,6 @@ static inline void f2fs_update_sit_info(struct f2fs_sb_info *sbi) {}
3688#endif 3688#endif
3689 3689
3690extern const struct file_operations f2fs_dir_operations; 3690extern const struct file_operations f2fs_dir_operations;
3691#ifdef CONFIG_UNICODE
3692extern const struct dentry_operations f2fs_dentry_ops;
3693#endif
3694extern const struct file_operations f2fs_file_operations; 3691extern const struct file_operations f2fs_file_operations;
3695extern const struct inode_operations f2fs_file_inode_operations; 3692extern const struct inode_operations f2fs_file_inode_operations;
3696extern const struct address_space_operations f2fs_dblock_aops; 3693extern const struct address_space_operations f2fs_dblock_aops;
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 8fa37d1434de..6edb1ab579a1 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -497,6 +497,7 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
497 } 497 }
498 498
499 err = f2fs_prepare_lookup(dir, dentry, &fname); 499 err = f2fs_prepare_lookup(dir, dentry, &fname);
500 generic_set_encrypted_ci_d_ops(dentry);
500 if (err == -ENOENT) 501 if (err == -ENOENT)
501 goto out_splice; 502 goto out_splice;
502 if (err) 503 if (err)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 0ec292d7fcdb..08e63c8caa1e 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -3426,7 +3426,6 @@ static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
3426 3426
3427 sbi->sb->s_encoding = encoding; 3427 sbi->sb->s_encoding = encoding;
3428 sbi->sb->s_encoding_flags = encoding_flags; 3428 sbi->sb->s_encoding_flags = encoding_flags;
3429 sbi->sb->s_d_op = &f2fs_dentry_ops;
3430 } 3429 }
3431#else 3430#else
3432 if (f2fs_sb_has_casefold(sbi)) { 3431 if (f2fs_sb_has_casefold(sbi)) {
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 155521e51ac5..7a920434d741 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -203,6 +203,7 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
203 dbg_gen("'%pd' in dir ino %lu", dentry, dir->i_ino); 203 dbg_gen("'%pd' in dir ino %lu", dentry, dir->i_ino);
204 204
205 err = fscrypt_prepare_lookup(dir, dentry, &nm); 205 err = fscrypt_prepare_lookup(dir, dentry, &nm);
206 generic_set_encrypted_ci_d_ops(dentry);
206 if (err == -ENOENT) 207 if (err == -ENOENT)
207 return d_splice_alias(NULL, dentry); 208 return d_splice_alias(NULL, dentry);
208 if (err) 209 if (err)
diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
index a8f7a43f031b..e72f80482671 100644
--- a/include/linux/fscrypt.h
+++ b/include/linux/fscrypt.h
@@ -741,8 +741,11 @@ static inline int fscrypt_prepare_rename(struct inode *old_dir,
741 * directory's encryption key is available, then the lookup is assumed to be by 741 * directory's encryption key is available, then the lookup is assumed to be by
742 * plaintext name; otherwise, it is assumed to be by no-key name. 742 * plaintext name; otherwise, it is assumed to be by no-key name.
743 * 743 *
744 * This also installs a custom ->d_revalidate() method which will invalidate the 744 * This will set DCACHE_NOKEY_NAME on the dentry if the lookup is by no-key
745 * dentry if it was created without the key and the key is later added. 745 * name. In this case the filesystem must assign the dentry a dentry_operations
746 * which contains fscrypt_d_revalidate (or contains a d_revalidate method that
747 * calls fscrypt_d_revalidate), so that the dentry will be invalidated if the
748 * directory's encryption key is later added.
746 * 749 *
747 * Return: 0 on success; -ENOENT if the directory's key is unavailable but the 750 * Return: 0 on success; -ENOENT if the directory's key is unavailable but the
748 * filename isn't a valid no-key name, so a negative dentry should be created; 751 * filename isn't a valid no-key name, so a negative dentry should be created;