Skip to content

Commit 233a0c0

Browse files
committed
Merge tag 'ecryptfs-7.0-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs
Pull ecryptfs updates from Tyler Hicks: "This consists of some really minor typo fixes that fell through the cracks and some more recent code cleanups: - Comment typo fixes - Removal of an unused function declaration - Use strscpy() instead of the deprecated strcpy() - Use string copying helpers instead of memcpy() and manually terminating strings" * tag 'ecryptfs-7.0-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs: ecryptfs: Replace memcpy + NUL termination in ecryptfs_copy_filename ecryptfs: Drop redundant NUL terminations after calling ecryptfs_to_hex ecryptfs: Replace memcpy + NUL termination in ecryptfs_new_file_context ecryptfs: Replace strcpy with strscpy in ecryptfs_validate_options ecryptfs: Replace strcpy with strscpy in ecryptfs_cipher_code_to_string ecryptfs: Replace strcpy with strscpy in ecryptfs_set_default_crypt_stat_vals ecryptfs: simplify list initialization in ecryptfs_parse_packet_set() ecryptfs: Remove unused declartion ecryptfs_fill_zeros() ecryptfs: Fix packet format comment in parse_tag_67_packet() ecryptfs: comment typo fix ecryptfs: keystore: Fix typo 'the the' in comment
2 parents 219d766 + 99853d9 commit 233a0c0

5 files changed

Lines changed: 29 additions & 41 deletions

File tree

fs/ecryptfs/crypto.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/file.h>
2121
#include <linux/scatterlist.h>
2222
#include <linux/slab.h>
23+
#include <linux/string.h>
2324
#include <linux/unaligned.h>
2425
#include <linux/kernel.h>
2526
#include <linux/xattr.h>
@@ -645,7 +646,7 @@ static void ecryptfs_set_default_crypt_stat_vals(
645646
ecryptfs_copy_mount_wide_flags_to_inode_flags(crypt_stat,
646647
mount_crypt_stat);
647648
ecryptfs_set_default_sizes(crypt_stat);
648-
strcpy(crypt_stat->cipher, ECRYPTFS_DEFAULT_CIPHER);
649+
strscpy(crypt_stat->cipher, ECRYPTFS_DEFAULT_CIPHER);
649650
crypt_stat->key_size = ECRYPTFS_DEFAULT_KEY_BYTES;
650651
crypt_stat->flags &= ~(ECRYPTFS_KEY_VALID);
651652
crypt_stat->file_version = ECRYPTFS_FILE_VERSION;
@@ -678,7 +679,6 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
678679
struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
679680
&ecryptfs_superblock_to_private(
680681
ecryptfs_inode->i_sb)->mount_crypt_stat;
681-
int cipher_name_len;
682682
int rc = 0;
683683

684684
ecryptfs_set_default_crypt_stat_vals(crypt_stat, mount_crypt_stat);
@@ -692,12 +692,8 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
692692
"to the inode key sigs; rc = [%d]\n", rc);
693693
goto out;
694694
}
695-
cipher_name_len =
696-
strlen(mount_crypt_stat->global_default_cipher_name);
697-
memcpy(crypt_stat->cipher,
698-
mount_crypt_stat->global_default_cipher_name,
699-
cipher_name_len);
700-
crypt_stat->cipher[cipher_name_len] = '\0';
695+
strscpy(crypt_stat->cipher,
696+
mount_crypt_stat->global_default_cipher_name);
701697
crypt_stat->key_size =
702698
mount_crypt_stat->global_default_cipher_key_size;
703699
ecryptfs_generate_new_key(crypt_stat);
@@ -861,19 +857,21 @@ u8 ecryptfs_code_for_cipher_string(char *cipher_name, size_t key_bytes)
861857
/**
862858
* ecryptfs_cipher_code_to_string
863859
* @str: Destination to write out the cipher name
860+
* @size: Destination buffer size
864861
* @cipher_code: The code to convert to cipher name string
865862
*
866863
* Returns zero on success
867864
*/
868-
int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code)
865+
int ecryptfs_cipher_code_to_string(char *str, size_t size, u8 cipher_code)
869866
{
870867
int rc = 0;
871868
int i;
872869

873870
str[0] = '\0';
874871
for (i = 0; i < ARRAY_SIZE(ecryptfs_cipher_code_str_map); i++)
875872
if (cipher_code == ecryptfs_cipher_code_str_map[i].cipher_code)
876-
strcpy(str, ecryptfs_cipher_code_str_map[i].cipher_str);
873+
strscpy(str, ecryptfs_cipher_code_str_map[i].cipher_str,
874+
size);
877875
if (str[0] == '\0') {
878876
ecryptfs_printk(KERN_WARNING, "Cipher code not recognized: "
879877
"[%d]\n", cipher_code);
@@ -1220,7 +1218,7 @@ static int ecryptfs_read_headers_virt(char *page_virt,
12201218

12211219
/**
12221220
* ecryptfs_read_xattr_region
1223-
* @page_virt: The vitual address into which to read the xattr data
1221+
* @page_virt: The virtual address into which to read the xattr data
12241222
* @ecryptfs_inode: The eCryptfs inode
12251223
*
12261224
* Attempts to read the crypto metadata from the extended attribute
@@ -1420,21 +1418,11 @@ ecryptfs_encrypt_filename(struct ecryptfs_filename *filename,
14201418
static int ecryptfs_copy_filename(char **copied_name, size_t *copied_name_size,
14211419
const char *name, size_t name_size)
14221420
{
1423-
int rc = 0;
1424-
1425-
(*copied_name) = kmalloc((name_size + 1), GFP_KERNEL);
1426-
if (!(*copied_name)) {
1427-
rc = -ENOMEM;
1428-
goto out;
1429-
}
1430-
memcpy((void *)(*copied_name), (void *)name, name_size);
1431-
(*copied_name)[(name_size)] = '\0'; /* Only for convenience
1432-
* in printing out the
1433-
* string in debug
1434-
* messages */
1421+
(*copied_name) = kmemdup_nul(name, name_size, GFP_KERNEL);
1422+
if (!(*copied_name))
1423+
return -ENOMEM;
14351424
(*copied_name_size) = name_size;
1436-
out:
1437-
return rc;
1425+
return 0;
14381426
}
14391427

14401428
/**

fs/ecryptfs/debug.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok)
2828
ecryptfs_printk(KERN_DEBUG, " * passphrase type\n");
2929
ecryptfs_to_hex(salt, auth_tok->token.password.salt,
3030
ECRYPTFS_SALT_SIZE);
31-
salt[ECRYPTFS_SALT_SIZE * 2] = '\0';
3231
ecryptfs_printk(KERN_DEBUG, " * salt = [%s]\n", salt);
3332
if (auth_tok->token.password.flags &
3433
ECRYPTFS_PERSISTENT_PASSWORD) {

fs/ecryptfs/ecryptfs_kernel.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ int ecryptfs_decode_and_decrypt_filename(char **decrypted_name,
543543
size_t *decrypted_name_size,
544544
struct super_block *sb,
545545
const char *name, size_t name_size);
546-
int ecryptfs_fill_zeros(struct file *file, loff_t new_length);
547546
int ecryptfs_encrypt_and_encode_filename(
548547
char **encoded_name,
549548
size_t *encoded_name_size,
@@ -573,7 +572,7 @@ int ecryptfs_read_and_validate_header_region(struct inode *inode);
573572
int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry,
574573
struct inode *inode);
575574
u8 ecryptfs_code_for_cipher_string(char *cipher_name, size_t key_bytes);
576-
int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code);
575+
int ecryptfs_cipher_code_to_string(char *str, size_t size, u8 cipher_code);
577576
void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat);
578577
int ecryptfs_generate_key_packet_set(char *dest_base,
579578
struct ecryptfs_crypt_stat *crypt_stat,

fs/ecryptfs/keystore.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ parse_tag_67_packet(struct ecryptfs_key_record *key_rec,
354354
int rc;
355355

356356
/*
357-
* ***** TAG 65 Packet Format *****
357+
* ***** TAG 67 Packet Format *****
358358
* | Content Type | 1 byte |
359359
* | Status Indicator | 1 byte |
360360
* | Encrypted File Encryption Key Size | 1 or 2 bytes |
@@ -837,7 +837,7 @@ struct ecryptfs_parse_tag_70_packet_silly_stack {
837837
* @filename: This function kmalloc's the memory for the filename
838838
* @filename_size: This function sets this to the amount of memory
839839
* kmalloc'd for the filename
840-
* @packet_size: This function sets this to the the number of octets
840+
* @packet_size: This function sets this to the number of octets
841841
* in the packet parsed
842842
* @mount_crypt_stat: The mount-wide cryptographic context
843843
* @data: The memory location containing the start of the tag 70
@@ -908,10 +908,11 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
908908
(*packet_size) += s->packet_size_len;
909909
ecryptfs_to_hex(s->fnek_sig_hex, &data[(*packet_size)],
910910
ECRYPTFS_SIG_SIZE);
911-
s->fnek_sig_hex[ECRYPTFS_SIG_SIZE_HEX] = '\0';
912911
(*packet_size) += ECRYPTFS_SIG_SIZE;
913912
s->cipher_code = data[(*packet_size)++];
914-
rc = ecryptfs_cipher_code_to_string(s->cipher_string, s->cipher_code);
913+
rc = ecryptfs_cipher_code_to_string(s->cipher_string,
914+
sizeof(s->cipher_string),
915+
s->cipher_code);
915916
if (rc) {
916917
printk(KERN_WARNING "%s: Cipher code [%d] is invalid\n",
917918
__func__, s->cipher_code);
@@ -1129,7 +1130,9 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
11291130
memcpy(crypt_stat->key, auth_tok->session_key.decrypted_key,
11301131
auth_tok->session_key.decrypted_key_size);
11311132
crypt_stat->key_size = auth_tok->session_key.decrypted_key_size;
1132-
rc = ecryptfs_cipher_code_to_string(crypt_stat->cipher, cipher_code);
1133+
rc = ecryptfs_cipher_code_to_string(crypt_stat->cipher,
1134+
sizeof(crypt_stat->cipher),
1135+
cipher_code);
11331136
if (rc) {
11341137
ecryptfs_printk(KERN_ERR, "Cipher code [%d] is invalid\n",
11351138
cipher_code);
@@ -1395,6 +1398,7 @@ parse_tag_3_packet(struct ecryptfs_crypt_stat *crypt_stat,
13951398
goto out_free;
13961399
}
13971400
rc = ecryptfs_cipher_code_to_string(crypt_stat->cipher,
1401+
sizeof(crypt_stat->cipher),
13981402
(u16)data[(*packet_size)]);
13991403
if (rc)
14001404
goto out_free;
@@ -1716,7 +1720,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
17161720
size_t i = 0;
17171721
size_t found_auth_tok;
17181722
size_t next_packet_is_auth_tok_packet;
1719-
struct list_head auth_tok_list;
1723+
LIST_HEAD(auth_tok_list);
17201724
struct ecryptfs_auth_tok *matching_auth_tok;
17211725
struct ecryptfs_auth_tok *candidate_auth_tok;
17221726
char *candidate_auth_tok_sig;
@@ -1729,7 +1733,6 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
17291733
struct key *auth_tok_key = NULL;
17301734
int rc = 0;
17311735

1732-
INIT_LIST_HEAD(&auth_tok_list);
17331736
/* Parse the header to find as many packets as we can; these will be
17341737
* added the our &auth_tok_list */
17351738
next_packet_is_auth_tok_packet = 1;
@@ -1777,8 +1780,6 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
17771780
}
17781781
ecryptfs_to_hex(new_auth_tok->token.password.signature,
17791782
sig_tmp_space, tag_11_contents_size);
1780-
new_auth_tok->token.password.signature[
1781-
ECRYPTFS_PASSWORD_SIG_SIZE] = '\0';
17821783
crypt_stat->flags |= ECRYPTFS_ENCRYPTED;
17831784
break;
17841785
case ECRYPTFS_TAG_1_PACKET_TYPE:

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)