Skip to content

Commit 70fb261

Browse files
committed
fscrypt: don't call no-key names "ciphertext names"
Currently we're using the term "ciphertext name" ambiguously because it can mean either the actual ciphertext filename, or the encoded filename that is shown when an encrypted directory is listed without its key. The latter we're now usually calling the "no-key name"; and while it's derived from the ciphertext name, it's not the same thing. To avoid this ambiguity, rename fscrypt_name::is_ciphertext_name to fscrypt_name::is_nokey_name, and update comments that say "ciphertext name" (or "encrypted name") to say "no-key name" instead when warranted. Link: https://lore.kernel.org/r/20200924042624.98439-2-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
1 parent 0c6a113 commit 70fb261

4 files changed

Lines changed: 19 additions & 20 deletions

File tree

‎fs/crypto/fname.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ EXPORT_SYMBOL(fscrypt_fname_disk_to_usr);
382382
* directory's encryption key, then @iname is the plaintext, so we encrypt it to
383383
* get the disk_name.
384384
*
385-
* Else, for keyless @lookup operations, @iname is the presented ciphertext, so
386-
* we decode it to get the fscrypt_nokey_name. Non-@lookup operations will be
387-
* impossible in this case, so we fail them with ENOKEY.
385+
* Else, for keyless @lookup operations, @iname should be a no-key name, so we
386+
* decode it to get the struct fscrypt_nokey_name. Non-@lookup operations will
387+
* be impossible in this case, so we fail them with ENOKEY.
388388
*
389389
* If successful, fscrypt_free_filename() must be called later to clean up.
390390
*
@@ -429,7 +429,7 @@ int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname,
429429
}
430430
if (!lookup)
431431
return -ENOKEY;
432-
fname->is_ciphertext_name = true;
432+
fname->is_nokey_name = true;
433433

434434
/*
435435
* We don't have the key and we are doing a lookup; decode the
@@ -538,17 +538,17 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags)
538538

539539
/*
540540
* Plaintext names are always valid, since fscrypt doesn't support
541-
* reverting to ciphertext names without evicting the directory's inode
541+
* reverting to no-key names without evicting the directory's inode
542542
* -- which implies eviction of the dentries in the directory.
543543
*/
544544
if (!(dentry->d_flags & DCACHE_ENCRYPTED_NAME))
545545
return 1;
546546

547547
/*
548-
* Ciphertext name; valid if the directory's key is still unavailable.
548+
* No-key name; valid if the directory's key is still unavailable.
549549
*
550-
* Although fscrypt forbids rename() on ciphertext names, we still must
551-
* use dget_parent() here rather than use ->d_parent directly. That's
550+
* Although fscrypt forbids rename() on no-key names, we still must use
551+
* dget_parent() here rather than use ->d_parent directly. That's
552552
* because a corrupted fs image may contain directory hard links, which
553553
* the VFS handles by moving the directory's dentry tree in the dcache
554554
* each time ->lookup() finds the directory and it already has a dentry

‎fs/crypto/hooks.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int __fscrypt_prepare_link(struct inode *inode, struct inode *dir,
6060
if (err)
6161
return err;
6262

63-
/* ... in case we looked up ciphertext name before key was added */
63+
/* ... in case we looked up no-key name before key was added */
6464
if (dentry->d_flags & DCACHE_ENCRYPTED_NAME)
6565
return -ENOKEY;
6666

@@ -85,7 +85,7 @@ int __fscrypt_prepare_rename(struct inode *old_dir, struct dentry *old_dentry,
8585
if (err)
8686
return err;
8787

88-
/* ... in case we looked up ciphertext name(s) before key was added */
88+
/* ... in case we looked up no-key name(s) before key was added */
8989
if ((old_dentry->d_flags | new_dentry->d_flags) &
9090
DCACHE_ENCRYPTED_NAME)
9191
return -ENOKEY;
@@ -114,7 +114,7 @@ int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
114114
if (err && err != -ENOENT)
115115
return err;
116116

117-
if (fname->is_ciphertext_name) {
117+
if (fname->is_nokey_name) {
118118
spin_lock(&dentry->d_lock);
119119
dentry->d_flags |= DCACHE_ENCRYPTED_NAME;
120120
spin_unlock(&dentry->d_lock);

‎fs/f2fs/dir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int __f2fs_setup_filename(const struct inode *dir,
111111
#ifdef CONFIG_FS_ENCRYPTION
112112
fname->crypto_buf = crypt_name->crypto_buf;
113113
#endif
114-
if (crypt_name->is_ciphertext_name) {
114+
if (crypt_name->is_nokey_name) {
115115
/* hash was decoded from the no-key name */
116116
fname->hash = cpu_to_le32(crypt_name->hash);
117117
} else {

‎include/linux/fscrypt.h‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct fscrypt_name {
3535
u32 hash;
3636
u32 minor_hash;
3737
struct fscrypt_str crypto_buf;
38-
bool is_ciphertext_name;
38+
bool is_nokey_name;
3939
};
4040

4141
#define FSTR_INIT(n, l) { .name = n, .len = l }
@@ -730,17 +730,16 @@ static inline int fscrypt_prepare_rename(struct inode *old_dir,
730730
* @fname: (output) the name to use to search the on-disk directory
731731
*
732732
* Prepare for ->lookup() in a directory which may be encrypted by determining
733-
* the name that will actually be used to search the directory on-disk. Lookups
734-
* can be done with or without the directory's encryption key; without the key,
735-
* filenames are presented in encrypted form. Therefore, we'll try to set up
736-
* the directory's encryption key, but even without it the lookup can continue.
733+
* the name that will actually be used to search the directory on-disk. If the
734+
* directory's encryption key is available, then the lookup is assumed to be by
735+
* plaintext name; otherwise, it is assumed to be by no-key name.
737736
*
738737
* This also installs a custom ->d_revalidate() method which will invalidate the
739738
* dentry if it was created without the key and the key is later added.
740739
*
741-
* Return: 0 on success; -ENOENT if key is unavailable but the filename isn't a
742-
* correctly formed encoded ciphertext name, so a negative dentry should be
743-
* created; or another -errno code.
740+
* Return: 0 on success; -ENOENT if the directory's key is unavailable but the
741+
* filename isn't a valid no-key name, so a negative dentry should be created;
742+
* or another -errno code.
744743
*/
745744
static inline int fscrypt_prepare_lookup(struct inode *dir,
746745
struct dentry *dentry,

0 commit comments

Comments
 (0)