diff mbox series

[4/9] ext4: don't call fscrypt_get_encryption_info() from dx_show_leaf()

Message ID 20201125002336.274045-5-ebiggers@kernel.org (mailing list archive)
State New
Headers show
Series Allow deleting files with unsupported encryption policy | expand

Commit Message

Eric Biggers Nov. 25, 2020, 12:23 a.m. UTC
From: Eric Biggers <ebiggers@google.com>

The call to fscrypt_get_encryption_info() in dx_show_leaf() is too low
in the call tree; fscrypt_get_encryption_info() should have already been
called when starting the directory operation.  And indeed, it already
is.  Moreover, the encryption key is guaranteed to already be available
because dx_show_leaf() is only called when adding a new directory entry.

And even if the key wasn't available, dx_show_leaf() uses
fscrypt_fname_disk_to_usr() which knows how to create a no-key name.

So for the above reasons, and because it would be desirable to stop
exporting fscrypt_get_encryption_info() directly to filesystems, remove
the call to fscrypt_get_encryption_info() from dx_show_leaf().

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/ext4/namei.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

Comments

Andreas Dilger Dec. 2, 2020, 10:48 p.m. UTC | #1
On Nov 24, 2020, at 5:23 PM, Eric Biggers <ebiggers@kernel.org> wrote:
> 
> From: Eric Biggers <ebiggers@google.com>
> 
> The call to fscrypt_get_encryption_info() in dx_show_leaf() is too low
> in the call tree; fscrypt_get_encryption_info() should have already been
> called when starting the directory operation.  And indeed, it already
> is.  Moreover, the encryption key is guaranteed to already be available
> because dx_show_leaf() is only called when adding a new directory entry.
> 
> And even if the key wasn't available, dx_show_leaf() uses
> fscrypt_fname_disk_to_usr() which knows how to create a no-key name.
> 
> So for the above reasons, and because it would be desirable to stop
> exporting fscrypt_get_encryption_info() directly to filesystems, remove
> the call to fscrypt_get_encryption_info() from dx_show_leaf().
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> fs/ext4/namei.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 793fc7db9d28..7b31aea3e025 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -643,13 +643,7 @@ static struct stats dx_show_leaf(struct inode *dir,
> 
> 				name  = de->name;
> 				len = de->name_len;
> -				if (IS_ENCRYPTED(dir))
> -					res = fscrypt_get_encryption_info(dir);
> -				if (res) {
> -					printk(KERN_WARNING "Error setting up"
> -					       " fname crypto: %d\n", res);
> -				}
> -				if (!fscrypt_has_encryption_key(dir)) {
> +				if (!IS_ENCRYPTED(dir)) {
> 					/* Directory is not encrypted */
> 					ext4fs_dirhash(dir, de->name,
> 						de->name_len, &h);
> --
> 2.29.2
> 


Cheers, Andreas
diff mbox series

Patch

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 793fc7db9d28..7b31aea3e025 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -643,13 +643,7 @@  static struct stats dx_show_leaf(struct inode *dir,
 
 				name  = de->name;
 				len = de->name_len;
-				if (IS_ENCRYPTED(dir))
-					res = fscrypt_get_encryption_info(dir);
-				if (res) {
-					printk(KERN_WARNING "Error setting up"
-					       " fname crypto: %d\n", res);
-				}
-				if (!fscrypt_has_encryption_key(dir)) {
+				if (!IS_ENCRYPTED(dir)) {
 					/* Directory is not encrypted */
 					ext4fs_dirhash(dir, de->name,
 						de->name_len, &h);