History

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().

Eric Biggers committed 7 years ago

Commit 0bf3d5c1 parent 968dd6d2 files · +18 −0Browse files

Unified · Split

2 files
  1. fs/dcache.c +2 −0
  2. include/linux/fscrypt.h +16 −0
fs/dcache.c+2−0
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 #include <linux/string.h>
1919 #include <linux/mm.h>
2020 #include <linux/fs.h>
21+#include <linux/fscrypt.h>
2122 #include <linux/fsnotify.h>
2223 #include <linux/slab.h>
2324 #include <linux/init.h>
@@ -2795,6 +2796,7 @@ static void __d_move(struct dentry *dentry, struct dentry *target, · 2771 unmodified lines
27952796 list_move(&dentry->d_child, &dentry->d_parent->d_subdirs);
27962797 __d_rehash(dentry);
27972798 fsnotify_update_flags(dentry);
2799+ fscrypt_handle_d_move(dentry);
27982800
27992801 write_seqcount_end(&target->d_seq);
28002802 write_seqcount_end(&dentry->d_seq);
include/linux/fscrypt.h+16−0
@@ -89,6 +89,18 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode) · 88 unmodified lines
8989 inode->i_sb->s_cop->dummy_context(inode);
9090 }
9191
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+ */
99+static inline void fscrypt_handle_d_move(struct dentry *dentry)
100+{
101+ dentry->d_flags &= ~DCACHE_ENCRYPTED_NAME;
102+}
103+
92104 /* crypto.c */
93105 extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
94106 extern struct fscrypt_ctx *fscrypt_get_ctx(gfp_t);
@@ -244,6 +256,10 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode) · 149 unmodified lines
244256 return false;
245257 }
246258
259+static inline void fscrypt_handle_d_move(struct dentry *dentry)
260+{
261+}
262+
247263 /* crypto.c */
248264 static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
249265 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t