Skip to contentSkip to conversation

ceph: allow encrypting a directory while not having Ax caps

RFC PATCH In review Luís Henriques 2 participants 2 messages Nov 3, 2022 – Nov 7, 2022 Ceph client

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 ceph: allow encrypting a directory while not having Ax caps

If a client doesn't have Fx caps on a directory, it will get errors while trying encrypt it:

ceph: handle_cap_grant: cap grant attempt to change fscrypt_auth on non-I_NEW inode (old len 0 new len 48) fscrypt (ceph, inode 1099511627812): Error -105 getting encryption context

A simple way to reproduce this is to use two clients:

client1 # mkdir /mnt/mydir

client2 # ls /mnt/mydir

client1 # fscrypt encrypt /mnt/mydir
client1 # echo hello > /mnt/mydir/world

This happens because, in __ceph_setattr(), we only initialize ci->fscrypt_auth if we have Ax and ceph_fill_inode() won't use the fscrypt_auth received if the inode state isn't I_NEW. Fix it by allowing ceph_fill_inode() to also set ci->fscrypt_auth if the inode doesn't have it set already.

---
 fs/ceph/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ceph/inode.c +2 -1
index fb507d57cb26..c7831f801911 100644
@@ -1016,7 +1016,8 @@ int ceph_fill_inode(struct inode *inode, struct page *locked_page,
 	__ceph_update_quota(ci, iinfo->max_bytes, iinfo->max_files);
 
 #ifdef CONFIG_FS_ENCRYPTION
-	if (iinfo->fscrypt_auth_len && (inode->i_state & I_NEW)) {
+	if (iinfo->fscrypt_auth_len &&
+	    ((inode->i_state & I_NEW) || (ci->fscrypt_auth_len == 0))) {
 		kfree(ci->fscrypt_auth);
 		ci->fscrypt_auth_len = iinfo->fscrypt_auth_len;
 		ci->fscrypt_auth = iinfo->fscrypt_auth;
#1 lore raw
Quoted 32 lines · Luís Henriques

If a client doesn't have Fx caps on a directory, it will get errors while trying encrypt it:

ceph: handle_cap_grant: cap grant attempt to change fscrypt_auth on non-I_NEW inode (old len 0 new len 48) fscrypt (ceph, inode 1099511627812): Error -105 getting encryption context

A simple way to reproduce this is to use two clients:

client1 # mkdir /mnt/mydir

client2 # ls /mnt/mydir

client1 # fscrypt encrypt /mnt/mydir
client1 # echo hello > /mnt/mydir/world

This happens because, in __ceph_setattr(), we only initialize ci->fscrypt_auth if we have Ax and ceph_fill_inode() won't use the fscrypt_auth received if the inode state isn't I_NEW. Fix it by allowing ceph_fill_inode() to also set ci->fscrypt_auth if the inode doesn't have it set already.

---
  fs/ceph/inode.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/ceph/inode.c +0 -0
index fb507d57cb26..c7831f801911 100644

fs/ceph/inode.c int ceph_fill_inode(struct inode *inode, struct page *locked_page, · line 1023

Quoted 9 lines
fs/ceph/inode.c +2 -1
@@ -1016,7 +1016,8 @@ int ceph_fill_inode(struct inode *inode, struct page *locked_page,
  	__ceph_update_quota(ci, iinfo->max_bytes, iinfo->max_files);
 
  #ifdef CONFIG_FS_ENCRYPTION
-	if (iinfo->fscrypt_auth_len && (inode->i_state & I_NEW)) {
+	if (iinfo->fscrypt_auth_len &&
+	    ((inode->i_state & I_NEW) || (ci->fscrypt_auth_len == 0))) {
  		kfree(ci->fscrypt_auth);
  		ci->fscrypt_auth_len = iinfo->fscrypt_auth_len;
  		ci->fscrypt_auth = iinfo->fscrypt_auth;

Hi Luis,

This looks good to me.

I will test it and merge it if everything goes well.

Thanks!

- Xiubo