Skip to contentSkip to conversation

Check for eCryptfs cipher support at mount time.

PATCH In review Tim Sally 2 participants 5 messages Jul 11, 2012 – Jul 14, 2012 Ecrypt file system

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/1 eCryptfs: check for eCryptfs cipher support at mount

In reply to Tim Sally

The issue occurs when eCryptfs is mounted with a cipher supported by the crypto subsystem but not by eCryptfs. The mount succeeds and an error does not occur until a write. This change checks for eCryptfs cipher support at mount time.

Resolves Launchpad issue #338914, reported by Tyler Hicks in 03/2009.
https://bugs.launchpad.net/ecryptfs/+bug/338914

---
 fs/ecryptfs/main.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
fs/ecryptfs/main.c +24 -0
index df217dc..4eb1fc6 100644
@@ -279,6 +279,8 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
 	char *fnek_src;
 	char *cipher_key_bytes_src;
 	char *fn_cipher_key_bytes_src;
+	struct ecryptfs_key_tfm *key_tfm = NULL;
+	u8 cipher_code;
 
 	*check_ruid = 0;
 
@@ -456,6 +458,28 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
 			goto out;
 		}
 	}
+
+	if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
+					&key_tfm)) {
+		ecryptfs_printk(KERN_ERR,
+				"Cipher %s was not initalized correctly.\n",
+				mount_crypt_stat->global_default_cipher_name);
+		rc = -EINVAL;
+		mutex_unlock(&key_tfm_list_mutex);
+		goto out;
+	}
+
+	cipher_code = ecryptfs_code_for_cipher_string(key_tfm->cipher_name,
+						key_tfm->key_size);
+	if (!cipher_code) {
+		ecryptfs_printk(KERN_ERR,
+				"eCryptfs doesn't support: %s blocksize %zu.\n",
+				key_tfm->cipher_name, key_tfm->key_size);
+		rc = -EINVAL;
+		mutex_unlock(&key_tfm_list_mutex);
+		goto out;
+	}
+
 	mutex_unlock(&key_tfm_list_mutex);
 	rc = ecryptfs_init_global_auth_toks(mount_crypt_stat);
 	if (rc)
Signature · 1 line
1.7.10.4

Tim Sally

author
#0 lore raw

cover Check for eCryptfs cipher support at mount time.

eCryptfs will mount with any cipher supported by the crypto subsystem, even if the cipher is not supported by eCryptfs itself. An error will not occur until a write. This change checks for eCryptfs cipher support at mount time and will not mount the filesystem if the cipher is not supported.

The cipher name and blocksize are retrieved from ecryptfs_key_tfm because it will assign a default block size upon creation if none is specified in the mount options.

This issue originally reported by Tyler Hicks in 03/2009.
https://bugs.launchpad.net/ecryptfs/+bug/338914

Thanks,

Tim

Tim Sally (1):
eCryptfs: check for eCryptfs cipher support at mount

 fs/ecryptfs/main.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH 1/1] eCryptfs: check for eCryptfs cipher support at mount

In reply to Tim Sally
Quoted 7 lines · Tim Sally

The issue occurs when eCryptfs is mounted with a cipher supported by the crypto subsystem but not by eCryptfs. The mount succeeds and an error does not occur until a write. This change checks for eCryptfs cipher support at mount time.

Resolves Launchpad issue #338914, reported by Tyler Hicks in 03/2009.
https://bugs.launchpad.net/ecryptfs/+bug/338914

Hey Tim - Thanks for digging this one out of the bug tracker. :)

Quoted 23 lines
---
 fs/ecryptfs/main.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
fs/ecryptfs/main.c +2 -0
index df217dc..4eb1fc6 100644
@@ -279,6 +279,8 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
 	char *fnek_src;
 	char *cipher_key_bytes_src;
 	char *fn_cipher_key_bytes_src;
+	struct ecryptfs_key_tfm *key_tfm = NULL;
+	u8 cipher_code;
 
 	*check_ruid = 0;
 
@@ -456,6 +458,28 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
 			goto out;
 		}
 	}

fs/ecryptfs/main.c static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options, · line 470

Quoted 10 lines
fs/ecryptfs/main.c +10 -0
+
+	if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
+					&key_tfm)) {
+		ecryptfs_printk(KERN_ERR,
+				"Cipher %s was not initalized correctly.\n",
+				mount_crypt_stat->global_default_cipher_name);
+		rc = -EINVAL;
+		mutex_unlock(&key_tfm_list_mutex);
+		goto out;
+	}

We already know that the tfm exists because we already checked for its existence and added it if it didn't exist. We shouldn't need to do it again here.

fs/ecryptfs/main.c static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options, · line 481

Quoted 11 lines
fs/ecryptfs/main.c +11 -0
+
+	cipher_code = ecryptfs_code_for_cipher_string(key_tfm->cipher_name,
+						key_tfm->key_size);
+	if (!cipher_code) {
+		ecryptfs_printk(KERN_ERR,
+				"eCryptfs doesn't support: %s blocksize %zu.\n",
+				key_tfm->cipher_name, key_tfm->key_size);
+		rc = -EINVAL;
+		mutex_unlock(&key_tfm_list_mutex);
+		goto out;
+	}

How about just calling

ecryptfs_code_for_cipher_string(mount_crypt_stat->global_default_cipher_name,

			mount_crypt_stat->global_default_cipher_key_size);

even before we lock the key_tfm_list_mutex a little above here? If that fails, we don't even need to check for the tfm's existence or do anything else besides error out.

Tyler

Quoted 11 lines
fs/ecryptfs/main.c +1 -0
+
 	mutex_unlock(&key_tfm_list_mutex);
 	rc = ecryptfs_init_global_auth_toks(mount_crypt_stat);
 	if (rc)
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe ecryptfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#3 lore raw

PATCH 1/1 eCryptfs: check for eCryptfs cipher support at mount

The issue occurs when eCryptfs is mounted with a cipher supported by the crypto subsystem but not by eCryptfs. The mount succeeds and an error does not occur until a write. This change checks for eCryptfs cipher support at mount time.

Resolves Launchpad issue #338914, reported by Tyler Hicks in 03/2009.
https://bugs.launchpad.net/ecryptfs/+bug/338914

---
 fs/ecryptfs/main.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)
fs/ecryptfs/main.c +13 -0
index df217dc..aee998d 100644
@@ -279,6 +279,7 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
 	char *fnek_src;
 	char *cipher_key_bytes_src;
 	char *fn_cipher_key_bytes_src;
+	u8 cipher_code;
 
 	*check_ruid = 0;
 
@@ -420,6 +421,18 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
 	    && !fn_cipher_key_bytes_set)
 		mount_crypt_stat->global_default_fn_cipher_key_bytes =
 			mount_crypt_stat->global_default_cipher_key_size;
+
+	cipher_code = ecryptfs_code_for_cipher_string(
+		mount_crypt_stat->global_default_cipher_name,
+		mount_crypt_stat->global_default_cipher_key_size);
+	if (!cipher_code) {
+		ecryptfs_printk(KERN_ERR,
+				"eCryptfs doesn't support cipher: %s.",
+				mount_crypt_stat->global_default_cipher_name);
+		rc = -EINVAL;
+		goto out;
+	}
+
 	mutex_lock(&key_tfm_list_mutex);
 	if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
 				 NULL)) {
Signature · 1 line
1.7.10.4
#4 lore raw

Re: [PATCH 1/1] eCryptfs: check for eCryptfs cipher support at mount

Quoted 9 lines · Tim Sally

The issue occurs when eCryptfs is mounted with a cipher supported by the crypto subsystem but not by eCryptfs. The mount succeeds and an error does not occur until a write. This change checks for eCryptfs cipher support at mount time.

Resolves Launchpad issue #338914, reported by Tyler Hicks in 03/2009.
https://bugs.launchpad.net/ecryptfs/+bug/338914

Looks good! I've pushed it to the eCryptfs -next branch and it will go in during the 3.6 merge window.

I'm looking forward to more eCryptfs patches from you. Thanks!

Tyler

Quoted 42 lines
---
 fs/ecryptfs/main.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)
fs/ecryptfs/main.c +13 -0
index df217dc..aee998d 100644
@@ -279,6 +279,7 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
 	char *fnek_src;
 	char *cipher_key_bytes_src;
 	char *fn_cipher_key_bytes_src;
+	u8 cipher_code;
 
 	*check_ruid = 0;
 
@@ -420,6 +421,18 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
 	    && !fn_cipher_key_bytes_set)
 		mount_crypt_stat->global_default_fn_cipher_key_bytes =
 			mount_crypt_stat->global_default_cipher_key_size;
+
+	cipher_code = ecryptfs_code_for_cipher_string(
+		mount_crypt_stat->global_default_cipher_name,
+		mount_crypt_stat->global_default_cipher_key_size);
+	if (!cipher_code) {
+		ecryptfs_printk(KERN_ERR,
+				"eCryptfs doesn't support cipher: %s.",
+				mount_crypt_stat->global_default_cipher_name);
+		rc = -EINVAL;
+		goto out;
+	}
+
 	mutex_lock(&key_tfm_list_mutex);
 	if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
 				 NULL)) {
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe ecryptfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html