@@ -104,6 +104,7 @@ static int ll_set_context(struct inode *inode, const void *ctx, size_t len,
return -EPERM;
dentry = (struct dentry *)fs_data;
+ set_bit(LLIF_SET_ENC_CTX, &ll_i2info(inode)->lli_flags);
rc = __vfs_setxattr(dentry, inode, LL_XATTR_NAME_ENCRYPTION_CONTEXT,
ctx, len, XATTR_CREATE);
if (rc)
@@ -4455,6 +4455,18 @@ int ll_migrate(struct inode *parent, struct file *file, struct lmv_user_md *lum,
goto out_iput;
}
+ if (IS_ENCRYPTED(child_inode)) {
+ rc = llcrypt_get_encryption_info(child_inode);
+ if (rc)
+ goto out_iput;
+ if (!llcrypt_has_encryption_key(child_inode)) {
+ CDEBUG(D_SEC, "no enc key for "DFID"\n",
+ PFID(ll_inode2fid(child_inode)));
+ rc = -ENOKEY;
+ goto out_iput;
+ }
+ }
+
op_data = ll_prep_md_op_data(NULL, parent, NULL, name, namelen,
child_inode->i_mode, LUSTRE_OPC_ANY, NULL);
if (IS_ERR(op_data)) {
@@ -97,12 +97,14 @@ enum ll_file_flags {
LLIF_FILE_RESTORING = 1,
/* Xattr cache is attached to the file */
LLIF_XATTR_CACHE = 2,
+ /* Project inherit */
+ LLIF_PROJECT_INHERIT = 3,
/* update atime from MDS no matter if it's older than
* local inode atime.
*/
- LLIF_UPDATE_ATIME,
- /* Project inherit */
- LLIF_PROJECT_INHERIT = 3,
+ LLIF_UPDATE_ATIME = 4,
+ /* setting encryption context in progress */
+ LLIF_SET_ENC_CTX = 6,
};
/* See comment on trunc_sem_down_read_nowait */
@@ -133,6 +133,17 @@ static int ll_xattr_set_common(const struct xattr_handler *handler,
return -EPERM;
}
+ /* Setting LL_XATTR_NAME_ENCRYPTION_CONTEXT xattr is only allowed
+ * when defining an encryption policy on a directory, ie when it
+ * comes from ll_set_context().
+ * When new files/dirs are created in an encrypted dir, the xattr
+ * is set directly in the create request.
+ */
+ if (handler->flags == XATTR_SECURITY_T &&
+ !strcmp(name, "c") &&
+ !test_and_clear_bit(LLIF_SET_ENC_CTX, &ll_i2info(inode)->lli_flags))
+ return -EPERM;
+
fullname = kasprintf(GFP_KERNEL, "%s%s", xattr_prefix(handler), name);
if (!fullname)
return -ENOMEM;