Skip to content

Commit 0529a80

Browse files
tobluxtyhicks
authored andcommitted
ecryptfs: Replace strcpy with strscpy in ecryptfs_validate_options
strcpy() has been deprecated [1] because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the safer strscpy(). Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1] Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Tyler Hicks <code@tyhicks.com>
1 parent c82f77a commit 0529a80

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

fs/ecryptfs/main.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/fs_stack.h>
2424
#include <linux/sysfs.h>
2525
#include <linux/slab.h>
26+
#include <linux/string.h>
2627
#include <linux/magic.h>
2728
#include "ecryptfs_kernel.h"
2829

@@ -354,13 +355,13 @@ static int ecryptfs_validate_options(struct fs_context *fc)
354355
int cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER);
355356

356357
BUG_ON(cipher_name_len > ECRYPTFS_MAX_CIPHER_NAME_SIZE);
357-
strcpy(mount_crypt_stat->global_default_cipher_name,
358-
ECRYPTFS_DEFAULT_CIPHER);
358+
strscpy(mount_crypt_stat->global_default_cipher_name,
359+
ECRYPTFS_DEFAULT_CIPHER);
359360
}
360361
if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)
361362
&& !ctx->fn_cipher_name_set)
362-
strcpy(mount_crypt_stat->global_default_fn_cipher_name,
363-
mount_crypt_stat->global_default_cipher_name);
363+
strscpy(mount_crypt_stat->global_default_fn_cipher_name,
364+
mount_crypt_stat->global_default_cipher_name);
364365
if (!ctx->cipher_key_bytes_set)
365366
mount_crypt_stat->global_default_cipher_key_size = 0;
366367
if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)

0 commit comments

Comments
 (0)