summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2019-03-20 14:39:11 -0400
committerTheodore Ts'o <tytso@mit.edu>2019-04-17 10:05:51 -0400
commit0bf3d5c1604ecbbd4e49e9f5b3c79152b87adb0d (patch)
tree97a5f5cedec9b310490df829e03997036869c9fa
parent968dd6d0c6d6b6a989c6ddb9e2584a031b83e7b5 (diff)
fs, fscrypt: clear DCACHE_ENCRYPTED_NAME when unaliasing directory
Make __d_move() clear DCACHE_ENCRYPTED_NAME on the source dentry. This is needed for when d_splice_alias() moves a directory's encrypted alias to its decrypted alias as a result of the encryption key being added. Otherwise, the decrypted alias will incorrectly be invalidated on the next lookup, causing problems such as unmounting a mount the user just mount()ed there. Note that we don't have to support arbitrary moves of this flag because fscrypt doesn't allow dentries with DCACHE_ENCRYPTED_NAME to be the source or target of a rename(). Fixes: 28b4c263961c ("ext4 crypto: revalidate dentry after adding or removing the key") Reported-by: Sarthak Kukreti <sarthakkukreti@chromium.org> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--fs/dcache.c2
-rw-r--r--include/linux/fscrypt.h16
2 files changed, 18 insertions, 0 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index aac41adf4743..647e6ed426e2 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -18,6 +18,7 @@
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <linux/fs.h> 20#include <linux/fs.h>
21#include <linux/fscrypt.h>
21#include <linux/fsnotify.h> 22#include <linux/fsnotify.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
23#include <linux/init.h> 24#include <linux/init.h>
@@ -2795,6 +2796,7 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
2795 list_move(&dentry->d_child, &dentry->d_parent->d_subdirs); 2796 list_move(&dentry->d_child, &dentry->d_parent->d_subdirs);
2796 __d_rehash(dentry); 2797 __d_rehash(dentry);
2797 fsnotify_update_flags(dentry); 2798 fsnotify_update_flags(dentry);
2799 fscrypt_handle_d_move(dentry);
2798 2800
2799 write_seqcount_end(&target->d_seq); 2801 write_seqcount_end(&target->d_seq);
2800 write_seqcount_end(&dentry->d_seq); 2802 write_seqcount_end(&dentry->d_seq);
diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
index 855f743c226e..76c518f1e4c7 100644
--- a/include/linux/fscrypt.h
+++ b/include/linux/fscrypt.h
@@ -89,6 +89,18 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
89 inode->i_sb->s_cop->dummy_context(inode); 89 inode->i_sb->s_cop->dummy_context(inode);
90} 90}
91 91
92/*
93 * When d_splice_alias() moves a directory's encrypted alias to its decrypted
94 * alias as a result of the encryption key being added, DCACHE_ENCRYPTED_NAME
95 * must be cleared. Note that we don't have to support arbitrary moves of this
96 * flag because fscrypt doesn't allow encrypted aliases to be the source or
97 * target of a rename().
98 */
99static inline void fscrypt_handle_d_move(struct dentry *dentry)
100{
101 dentry->d_flags &= ~DCACHE_ENCRYPTED_NAME;
102}
103
92/* crypto.c */ 104/* crypto.c */
93extern void fscrypt_enqueue_decrypt_work(struct work_struct *); 105extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
94extern struct fscrypt_ctx *fscrypt_get_ctx(gfp_t); 106extern struct fscrypt_ctx *fscrypt_get_ctx(gfp_t);
@@ -244,6 +256,10 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
244 return false; 256 return false;
245} 257}
246 258
259static inline void fscrypt_handle_d_move(struct dentry *dentry)
260{
261}
262
247/* crypto.c */ 263/* crypto.c */
248static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work) 264static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
249{ 265{