From: "Luís Henriques" <lhenriques@suse.de>
To: Xiubo Li <xiubli@redhat.com>, Ilya Dryomov <idryomov@gmail.com>,
Jeff Layton <jlayton@kernel.org>
Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
"Luís Henriques" <lhenriques@suse.de>
Subject: [PATCH v2] ceph: make sure directories aren't complete after setting crypt context
Date: Mon, 21 Nov 2022 18:00:04 +0000 [thread overview]
Message-ID: <20221121180004.8038-1-lhenriques@suse.de> (raw)
When setting a directory's crypt context, __ceph_dir_clear_complete() needs
to be used otherwise, if it was complete before, any old dentry that's still
around will be valid.
Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
Hi Xiubo!
I've added the __fscrypt_prepare_readdir() wrapper as you suggested, but I
had to change it slightly because we also need to handle the error cases.
Changes since v1:
- Moved the __ceph_dir_clear_complete() call from ceph_crypt_get_context()
to ceph_lookup().
- Added an __fscrypt_prepare_readdir() wrapper to check key status changes
fs/ceph/dir.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index edc2bf0aab83..2cac7e3ab352 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -763,6 +763,27 @@ static bool is_root_ceph_dentry(struct inode *inode, struct dentry *dentry)
strncmp(dentry->d_name.name, ".ceph", 5) == 0;
}
+/*
+ * Simple wrapper around __fscrypt_prepare_readdir() that will return:
+ *
+ * - '1' if directory was locked and key is now loaded (i.e. dir is unlocked),
+ * - '0' if directory is still locked, or
+ * - an error (< 0) if __fscrypt_prepare_readdir() fails.
+ */
+static int ceph_fscrypt_prepare_readdir(struct inode *dir)
+{
+ bool had_key = fscrypt_has_encryption_key(dir);
+ int err;
+
+ err = __fscrypt_prepare_readdir(dir);
+ if (err)
+ return err;
+ /* is directory now unlocked? */
+ if (!had_key && fscrypt_has_encryption_key(dir))
+ return 1;
+ return 0;
+}
+
/*
* Look up a single dir entry. If there is a lookup intent, inform
* the MDS so that it gets our 'caps wanted' value in a single op.
@@ -784,10 +805,14 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
return ERR_PTR(-ENAMETOOLONG);
if (IS_ENCRYPTED(dir)) {
- err = __fscrypt_prepare_readdir(dir);
- if (err)
+ err = ceph_fscrypt_prepare_readdir(dir);
+ if (err < 0)
return ERR_PTR(err);
- if (!fscrypt_has_encryption_key(dir)) {
+ if (err) {
+ /* directory just got unlocked */
+ __ceph_dir_clear_complete(ceph_inode(dir));
+ } else {
+ /* no encryption key */
spin_lock(&dentry->d_lock);
dentry->d_flags |= DCACHE_NOKEY_NAME;
spin_unlock(&dentry->d_lock);
next reply other threads:[~2022-11-21 18:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 18:00 Luís Henriques [this message]
2022-11-22 1:02 ` Xiubo Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221121180004.8038-1-lhenriques@suse.de \
--to=lhenriques@suse.de \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiubli@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®