Skip to contentSkip to conversation

f2fs: switch to new fscrypt helper functions

PATCH In review Eric Biggers 2 participants 7 messages Nov 29, 2017 – Dec 1, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover f2fs: switch to new fscrypt helper functions

From: Eric Biggers <[email protected]>

This series switches f2fs to use the fscrypt helper functions for open/link/rename/lookup/setattr introduced in v4.15.

These patches were originally sent in "[PATCH 00/25] fscrypt: add some higher-level helper functions". I've rebased them onto v4.15-rc1.

Eric Biggers (5):
f2fs: switch to fscrypt_file_open()
f2fs: switch to fscrypt_prepare_link()
f2fs: switch to fscrypt_prepare_rename()
f2fs: switch to fscrypt_prepare_lookup()
f2fs: switch to fscrypt_prepare_setattr()

 fs/f2fs/file.c  | 30 +++++++-----------------------
 fs/f2fs/namei.c | 54 +++++++++++++-----------------------------------------
 2 files changed, 20 insertions(+), 64 deletions(-)
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
#1 lore raw

PATCH v2 1/5 f2fs: switch to fscrypt_file_open()

From: Eric Biggers <[email protected]>

---
 fs/f2fs/file.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
fs/f2fs/file.c +3 -15
index 7874bbd7311d..ae2cf96190e4 100644
@@ -472,22 +472,10 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
 
 static int f2fs_file_open(struct inode *inode, struct file *filp)
 {
-	struct dentry *dir;
+	int err = fscrypt_file_open(inode, filp);
 
-	if (f2fs_encrypted_inode(inode)) {
-		int ret = fscrypt_get_encryption_info(inode);
-		if (ret)
-			return -EACCES;
-		if (!fscrypt_has_encryption_key(inode))
-			return -ENOKEY;
-	}
-	dir = dget_parent(file_dentry(filp));
-	if (f2fs_encrypted_inode(d_inode(dir)) &&
-			!fscrypt_has_permitted_context(d_inode(dir), inode)) {
-		dput(dir);
-		return -EPERM;
-	}
-	dput(dir);
+	if (err)
+		return err;
 	return dquot_file_open(inode, filp);
 }
 
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
#2 lore raw

PATCH v2 2/5 f2fs: switch to fscrypt_prepare_link()

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

---
 fs/f2fs/namei.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/namei.c +3 -3
index 28bdf8828e73..dcf5c3a97059 100644
@@ -240,9 +240,9 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
 	if (unlikely(f2fs_cp_error(sbi)))
 		return -EIO;
 
-	if (f2fs_encrypted_inode(dir) &&
-			!fscrypt_has_permitted_context(dir, inode))
-		return -EPERM;
+	err = fscrypt_prepare_link(old_dentry, dir, dentry);
+	if (err)
+		return err;
 
 	if (is_inode_flag_set(dir, FI_PROJ_INHERIT) &&
 			(!projid_eq(F2FS_I(dir)->i_projid,
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
#3 lore raw

PATCH v2 3/5 f2fs: switch to fscrypt_prepare_rename()

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

---
 fs/f2fs/namei.c | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)
fs/f2fs/namei.c +7 -24
index dcf5c3a97059..e910d2ebe0c6 100644
@@ -800,18 +800,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
 	if (unlikely(f2fs_cp_error(sbi)))
 		return -EIO;
 
-	if ((f2fs_encrypted_inode(old_dir) &&
-			!fscrypt_has_encryption_key(old_dir)) ||
-			(f2fs_encrypted_inode(new_dir) &&
-			!fscrypt_has_encryption_key(new_dir)))
-		return -ENOKEY;
-
-	if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) &&
-			!fscrypt_has_permitted_context(new_dir, old_inode)) {
-		err = -EPERM;
-		goto out;
-	}
-
 	if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
 			(!projid_eq(F2FS_I(new_dir)->i_projid,
 			F2FS_I(old_dentry->d_inode)->i_projid)))
@@ -1002,18 +990,6 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
 	if (unlikely(f2fs_cp_error(sbi)))
 		return -EIO;
 
-	if ((f2fs_encrypted_inode(old_dir) &&
-			!fscrypt_has_encryption_key(old_dir)) ||
-			(f2fs_encrypted_inode(new_dir) &&
-			!fscrypt_has_encryption_key(new_dir)))
-		return -ENOKEY;
-
-	if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
-			(old_dir != new_dir) &&
-			(!fscrypt_has_permitted_context(new_dir, old_inode) ||
-			 !fscrypt_has_permitted_context(old_dir, new_inode)))
-		return -EPERM;
-
 	if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
 			!projid_eq(F2FS_I(new_dir)->i_projid,
 			F2FS_I(old_dentry->d_inode)->i_projid)) ||
@@ -1153,9 +1129,16 @@ static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
 			struct inode *new_dir, struct dentry *new_dentry,
 			unsigned int flags)
 {
+	int err;
+
 	if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
 		return -EINVAL;
 
+	err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry,
+				     flags);
+	if (err)
+		return err;
+
 	if (flags & RENAME_EXCHANGE) {
 		return f2fs_cross_rename(old_dir, old_dentry,
 					 new_dir, new_dentry);
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
#4 lore raw

PATCH v2 4/5 f2fs: switch to fscrypt_prepare_lookup()

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

---
 fs/f2fs/namei.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
fs/f2fs/namei.c +3 -14
index e910d2ebe0c6..bbb3fc1e2bef 100644
@@ -357,20 +357,9 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
 
 	trace_f2fs_lookup_start(dir, dentry, flags);
 
-	if (f2fs_encrypted_inode(dir)) {
-		err = fscrypt_get_encryption_info(dir);
-
-		/*
-		 * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is
-		 * created while the directory was encrypted and we
-		 * don't have access to the key.
-		 */
-		if (fscrypt_has_encryption_key(dir))
-			fscrypt_set_encrypted_dentry(dentry);
-		fscrypt_set_d_op(dentry);
-		if (err && err != -ENOKEY)
-			goto out;
-	}
+	err = fscrypt_prepare_lookup(dir, dentry, flags);
+	if (err)
+		goto out;
 
 	if (dentry->d_name.len > F2FS_NAME_LEN) {
 		err = -ENAMETOOLONG;
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
#5 lore raw

PATCH v2 5/5 f2fs: switch to fscrypt_prepare_setattr()

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

---
 fs/f2fs/file.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
fs/f2fs/file.c +4 -8
index ae2cf96190e4..52b8f95b9bee 100644
@@ -743,6 +743,10 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 	if (err)
 		return err;
 
+	err = fscrypt_prepare_setattr(dentry, attr);
+	if (err)
+		return err;
+
 	if (is_quota_modification(inode, attr)) {
 		err = dquot_initialize(inode);
 		if (err)
@@ -758,14 +762,6 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 	}
 
 	if (attr->ia_valid & ATTR_SIZE) {
-		if (f2fs_encrypted_inode(inode)) {
-			err = fscrypt_get_encryption_info(inode);
-			if (err)
-				return err;
-			if (!fscrypt_has_encryption_key(inode))
-				return -ENOKEY;
-		}
-
 		if (attr->ia_size <= i_size_read(inode)) {
 			down_write(&F2FS_I(inode)->i_mmap_sem);
 			truncate_setsize(inode, attr->ia_size);
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
maintainer
#6 lore raw
In reply to Eric Biggers

Thanks, merged.

Quoted 21 lines · Eric Biggers

From: Eric Biggers <[email protected]>

This series switches f2fs to use the fscrypt helper functions for open/link/rename/lookup/setattr introduced in v4.15.

These patches were originally sent in "[PATCH 00/25] fscrypt: add some higher-level helper functions". I've rebased them onto v4.15-rc1.

Eric Biggers (5):
f2fs: switch to fscrypt_file_open()
f2fs: switch to fscrypt_prepare_link()
f2fs: switch to fscrypt_prepare_rename()
f2fs: switch to fscrypt_prepare_lookup()
f2fs: switch to fscrypt_prepare_setattr()

 fs/f2fs/file.c  | 30 +++++++-----------------------
 fs/f2fs/namei.c | 54 +++++++++++++-----------------------------------------
 2 files changed, 20 insertions(+), 64 deletions(-)
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog