Skip to contentSkip to conversation

ecryptfs: fix string overflow on long cipher names

PATCH In review Eric Sandeen 2 participants 2 messages Dec 18, 2007 Ecrypt file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ecryptfs: fix string overflow on long cipher names

Passing a cipher name > 32 chars on mount results in an overflow when the cipher name is printed, because the last character in the struct ecryptfs_key_tfm's cipher_name string was never zeroed.

---

fs/ecryptfs/crypto.c +1 -0
Index: linux-2.6.24-rc3/fs/ecryptfs/crypto.c
===================================================================
@@ -1847,6 +1847,7 @@ ecryptfs_add_new_key_tfm(struct ecryptfs
 	mutex_init(&tmp_tfm->key_tfm_mutex);
 	strncpy(tmp_tfm->cipher_name, cipher_name,
 		ECRYPTFS_MAX_CIPHER_NAME_SIZE);
+	tmp_tfm->cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0';
 	tmp_tfm->key_size = key_size;
 	rc = ecryptfs_process_key_cipher(&tmp_tfm->key_tfm,
 					 tmp_tfm->cipher_name,
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Eric Sandeen

Passing a cipher name > 32 chars on mount results in an overflow when the cipher name is printed, because the last character in the struct ecryptfs_key_tfm's cipher_name string was never zeroed.

I don't think this causes any issues outside of a couple of printk's on error paths, but this should definitely go into the next -rc.

Quoted 17 lines

---

Index: linux-2.6.24-rc3/fs/ecryptfs/crypto.c
===================================================================

fs/ecryptfs/crypto.c +1 -0
@@ -1847,6 +1847,7 @@ ecryptfs_add_new_key_tfm(struct ecryptfs
 	mutex_init(&tmp_tfm->key_tfm_mutex);
 	strncpy(tmp_tfm->cipher_name, cipher_name,
 		ECRYPTFS_MAX_CIPHER_NAME_SIZE);
+	tmp_tfm->cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0';
 	tmp_tfm->key_size = key_size;
 	rc = ecryptfs_process_key_cipher(&tmp_tfm->key_tfm,
 					 tmp_tfm->cipher_name,