]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ecryptfs: Replace memcpy + manual NUL termination with strscpy
authorThorsten Blum <thorsten.blum@linux.dev>
Thu, 5 Feb 2026 12:51:00 +0000 (13:51 +0100)
committerTyler Hicks <code@tyhicks.com>
Thu, 26 Mar 2026 03:39:27 +0000 (22:39 -0500)
Use strscpy() to copy the NUL-terminated '->token.password.signature'
and 'sig' to the destination buffers instead of using memcpy() followed
by manual NUL terminations.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Tyler Hicks <code@tyhicks.com>
fs/ecryptfs/debug.c
fs/ecryptfs/keystore.c

index c185a8cb5fe23427d2c9417bff9f9c623698c293..42643702457cb872d08bb24fffcbad1e485f61f7 100644 (file)
@@ -7,6 +7,7 @@
  *   Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
  */
 
+#include <linux/string.h>
 #include "ecryptfs_kernel.h"
 
 /*
@@ -33,9 +34,7 @@ void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok)
                    ECRYPTFS_PERSISTENT_PASSWORD) {
                        ecryptfs_printk(KERN_DEBUG, " * persistent\n");
                }
-               memcpy(sig, auth_tok->token.password.signature,
-                      ECRYPTFS_SIG_SIZE_HEX);
-               sig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
+               strscpy(sig, auth_tok->token.password.signature);
                ecryptfs_printk(KERN_DEBUG, " * signature = [%s]\n", sig);
        }
        ecryptfs_printk(KERN_DEBUG, " * session_key.flags = [0x%x]\n",
index e8494903bb426aedb3e63aabda4b33693383ffdf..0be746493e560f5f2585685f48099616897cc840 100644 (file)
@@ -2458,8 +2458,7 @@ int ecryptfs_add_keysig(struct ecryptfs_crypt_stat *crypt_stat, char *sig)
        if (!new_key_sig)
                return -ENOMEM;
 
-       memcpy(new_key_sig->keysig, sig, ECRYPTFS_SIG_SIZE_HEX);
-       new_key_sig->keysig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
+       strscpy(new_key_sig->keysig, sig);
        /* Caller must hold keysig_list_mutex */
        list_add(&new_key_sig->crypt_stat_list, &crypt_stat->keysig_list);
 
@@ -2479,9 +2478,8 @@ ecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
        if (!new_auth_tok)
                return -ENOMEM;
 
-       memcpy(new_auth_tok->sig, sig, ECRYPTFS_SIG_SIZE_HEX);
+       strscpy(new_auth_tok->sig, sig);
        new_auth_tok->flags = global_auth_tok_flags;
-       new_auth_tok->sig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
        mutex_lock(&mount_crypt_stat->global_auth_tok_list_mutex);
        list_add(&new_auth_tok->mount_crypt_stat_list,
                 &mount_crypt_stat->global_auth_tok_list);