public inbox for ecryptfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] ecryptfs: Replace memcpy + NUL termination in ecryptfs_new_file_context
@ 2025-12-19 21:32 Thorsten Blum
  2025-12-23 20:28 ` Tyler Hicks
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-12-19 21:32 UTC (permalink / raw)
  To: Tyler Hicks, Christian Brauner, Ard Biesheuvel, Eric Biggers
  Cc: Thorsten Blum, ecryptfs, linux-kernel

Use strscpy() to copy the NUL-terminated '->global_default_cipher_name'
to the destination buffer instead of using memcpy() followed by a manual
NUL termination. Remove the now-unused local variable 'cipher_name_len'.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 fs/ecryptfs/crypto.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 260f8a4938b0..5d9ec4a1e12d 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -678,7 +678,6 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
 	struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
 	    &ecryptfs_superblock_to_private(
 		    ecryptfs_inode->i_sb)->mount_crypt_stat;
-	int cipher_name_len;
 	int rc = 0;
 
 	ecryptfs_set_default_crypt_stat_vals(crypt_stat, mount_crypt_stat);
@@ -692,12 +691,8 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
 		       "to the inode key sigs; rc = [%d]\n", rc);
 		goto out;
 	}
-	cipher_name_len =
-		strlen(mount_crypt_stat->global_default_cipher_name);
-	memcpy(crypt_stat->cipher,
-	       mount_crypt_stat->global_default_cipher_name,
-	       cipher_name_len);
-	crypt_stat->cipher[cipher_name_len] = '\0';
+	strscpy(crypt_stat->cipher,
+		mount_crypt_stat->global_default_cipher_name);
 	crypt_stat->key_size =
 		mount_crypt_stat->global_default_cipher_key_size;
 	ecryptfs_generate_new_key(crypt_stat);
-- 
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RESEND] ecryptfs: Replace memcpy + NUL termination in ecryptfs_new_file_context
  2025-12-19 21:32 [PATCH RESEND] ecryptfs: Replace memcpy + NUL termination in ecryptfs_new_file_context Thorsten Blum
@ 2025-12-23 20:28 ` Tyler Hicks
  0 siblings, 0 replies; 2+ messages in thread
From: Tyler Hicks @ 2025-12-23 20:28 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Christian Brauner, Ard Biesheuvel, Eric Biggers, ecryptfs,
	linux-kernel

On 2025-12-19 22:32:33, Thorsten Blum wrote:
> Use strscpy() to copy the NUL-terminated '->global_default_cipher_name'
> to the destination buffer instead of using memcpy() followed by a manual
> NUL termination. Remove the now-unused local variable 'cipher_name_len'.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Thanks for the cleanup!

Acked-by: Tyler Hicks <code@tyhicks.com>

Tyler

> ---
>  fs/ecryptfs/crypto.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
> index 260f8a4938b0..5d9ec4a1e12d 100644
> --- a/fs/ecryptfs/crypto.c
> +++ b/fs/ecryptfs/crypto.c
> @@ -678,7 +678,6 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
>  	struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
>  	    &ecryptfs_superblock_to_private(
>  		    ecryptfs_inode->i_sb)->mount_crypt_stat;
> -	int cipher_name_len;
>  	int rc = 0;
>  
>  	ecryptfs_set_default_crypt_stat_vals(crypt_stat, mount_crypt_stat);
> @@ -692,12 +691,8 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
>  		       "to the inode key sigs; rc = [%d]\n", rc);
>  		goto out;
>  	}
> -	cipher_name_len =
> -		strlen(mount_crypt_stat->global_default_cipher_name);
> -	memcpy(crypt_stat->cipher,
> -	       mount_crypt_stat->global_default_cipher_name,
> -	       cipher_name_len);
> -	crypt_stat->cipher[cipher_name_len] = '\0';
> +	strscpy(crypt_stat->cipher,
> +		mount_crypt_stat->global_default_cipher_name);
>  	crypt_stat->key_size =
>  		mount_crypt_stat->global_default_cipher_key_size;
>  	ecryptfs_generate_new_key(crypt_stat);
> -- 
> Thorsten Blum <thorsten.blum@linux.dev>
> GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-23 20:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-19 21:32 [PATCH RESEND] ecryptfs: Replace memcpy + NUL termination in ecryptfs_new_file_context Thorsten Blum
2025-12-23 20:28 ` Tyler Hicks

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox