ceph: set DCACHE_NOKEY_NAME flag in ceph_lookup/atomic_open()
authorJeff Layton <jlayton@kernel.org>
Tue, 26 Jan 2021 19:12:24 +0000 (14:12 -0500)
committerIlya Dryomov <idryomov@gmail.com>
Thu, 24 Aug 2023 09:24:34 +0000 (11:24 +0200)
This is required so that we know to invalidate these dentries when the
directory is unlocked.

Atomic open can act as a lookup if handed a dentry that is negative on
the MDS. Ensure that we set DCACHE_NOKEY_NAME on the dentry in
atomic_open, if we don't have the key for the parent. Otherwise, we can
end up validating the dentry inappropriately if someone later adds a
key.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Reviewed-and-tested-by: Luís Henriques <lhenriques@suse.de>
Reviewed-by: Milind Changire <mchangir@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/dir.c
fs/ceph/file.c

index 31fac21..cd2ca26 100644 (file)
@@ -760,6 +760,17 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
        if (dentry->d_name.len > NAME_MAX)
                return ERR_PTR(-ENAMETOOLONG);
 
+       if (IS_ENCRYPTED(dir)) {
+               err = __fscrypt_prepare_readdir(dir);
+               if (err)
+                       return ERR_PTR(err);
+               if (!fscrypt_has_encryption_key(dir)) {
+                       spin_lock(&dentry->d_lock);
+                       dentry->d_flags |= DCACHE_NOKEY_NAME;
+                       spin_unlock(&dentry->d_lock);
+               }
+       }
+
        /* can we conclude ENOENT locally? */
        if (d_really_is_negative(dentry)) {
                struct ceph_inode_info *ci = ceph_inode(dir);
index dddced5..9383ec3 100644 (file)
@@ -784,6 +784,13 @@ retry:
        req->r_args.open.mask = cpu_to_le32(mask);
        req->r_parent = dir;
        ihold(dir);
+       if (IS_ENCRYPTED(dir)) {
+               if (!fscrypt_has_encryption_key(dir)) {
+                       spin_lock(&dentry->d_lock);
+                       dentry->d_flags |= DCACHE_NOKEY_NAME;
+                       spin_unlock(&dentry->d_lock);
+               }
+       }
 
        if (flags & O_CREAT) {
                struct ceph_file_layout lo;