@@ -233,21 +233,26 @@ int ll_setup_filename(struct inode *dir, const struct qstr *iname,
fid->f_ver = 0;
}
rc = fscrypt_setup_filename(dir, &dname, lookup, fname);
- if (rc == -ENOENT && lookup &&
- ((is_root_inode(dir) && iname->len == strlen(dot_fscrypt_name) &&
- strncmp(iname->name, dot_fscrypt_name, iname->len) == 0) ||
- (!fscrypt_has_encryption_key(dir) &&
- unlikely(filename_is_volatile(iname->name, iname->len, NULL))))) {
- /* In case of subdir mount of an encrypted directory, we allow
- * lookup of /.fscrypt directory.
- */
- /* For purpose of migration or mirroring without enc key, we
- * allow lookup of volatile file without enc context.
- */
- memset(fname, 0, sizeof(struct fscrypt_name));
- fname->disk_name.name = (unsigned char *)iname->name;
- fname->disk_name.len = iname->len;
- rc = 0;
+ if (rc == -ENOENT && lookup) {
+ if (((is_root_inode(dir) &&
+ iname->len == strlen(dot_fscrypt_name) &&
+ strncmp(iname->name, dot_fscrypt_name, iname->len) == 0) ||
+ (!fscrypt_has_encryption_key(dir) &&
+ unlikely(filename_is_volatile(iname->name,
+ iname->len, NULL))))) {
+ /* In case of subdir mount of an encrypted directory,
+ * we allow lookup of /.fscrypt directory.
+ */
+ /* For purpose of migration or mirroring without enc key,
+ * we allow lookup of volatile file without enc context.
+ */
+ memset(fname, 0, sizeof(struct fscrypt_name));
+ fname->disk_name.name = (unsigned char *)iname->name;
+ fname->disk_name.len = iname->len;
+ rc = 0;
+ } else if (!fscrypt_has_encryption_key(dir)) {
+ rc = -ENOKEY;
+ }
}
if (rc)
return rc;