eCryptfs: Crypto API updates and d_count fixes
cover eCryptfs: Crypto API updates and d_count fixes
The lower d_count is not being handled right in eCryptfs, preventing an unmount of the lower filesystem under some circumstances. This patch set should make the d_count values sane in the lower filesystem. It also includes changes to move from the deprecated crypto API calls. These are bugfixes and compiler warning fixes; I recommend merging them into 2.6.19.
PATCH 1/6 eCryptfs: Clean up crypto initialization
Clean up the crypto initialization code; let the crypto API take care of the key size checks.
---
fs/ecryptfs/crypto.c | 66 +++++++---------------------------------- fs/ecryptfs/ecryptfs_kernel.h | 4 +- fs/ecryptfs/keystore.c | 19 +++++------- fs/ecryptfs/main.c | 13 +------- 4 files changed, 24 insertions(+), 78 deletions(-)
4a2f411a7a2449b5dd09e5b9688dbd76e7b2b280
fs/ecryptfs/crypto.c +12 -54
@@ -1573,35 +1573,26 @@ out:/** * ecryptfs_process_cipher - Perform cipher initialization. -* @tfm: Crypto context set by this function * @key_tfm: Crypto context for key material, set by this function -* @cipher_name: Name of the cipher. -* @key_size: Size of the key in bytes. +* @cipher_name: Name of the cipher +* @key_size: Size of the key in bytes * * Returns zero on success. Any crypto_tfm structs allocated here * should be released by other functions, such as on a superblock put * event, regardless of whether this function succeeds for fails. */ int -ecryptfs_process_cipher (struct crypto_tfm **tfm,struct crypto_tfm **key_tfm, -char *cipher_name,size_t key_size) +ecryptfs_process_cipher (struct crypto_tfm **key_tfm,char *cipher_name, +size_t *key_size) {char dummy_key[ECRYPTFS_MAX_KEY_BYTES ];int rc; - *tfm = *key_tfm =NULL ; -if (key_size >ECRYPTFS_MAX_KEY_BYTES ) { + *key_tfm =NULL ; +if (*key_size >ECRYPTFS_MAX_KEY_BYTES ) { rc = -EINVAL ;printk (KERN_ERR "Requested key size is [%Zd] bytes; maximum " -"allowable is [%d]\n" , key_size,ECRYPTFS_MAX_KEY_BYTES ); - goto out; - } - *tfm =crypto_alloc_tfm (cipher_name, (ECRYPTFS_DEFAULT_CHAINING_MODE - |CRYPTO_TFM_REQ_WEAK_KEY )); -if (!(*tfm)) { - rc = -EINVAL ; -printk (KERN_ERR "Unable to allocate crypto cipher with name " -"[%s]\n" , cipher_name); +"allowable is [%d]\n" , *key_size,ECRYPTFS_MAX_KEY_BYTES ); goto out; } *key_tfm =crypto_alloc_tfm (cipher_name,CRYPTO_TFM_REQ_WEAK_KEY );
@@ -1611,46 +1602,13 @@ ecryptfs_process_cipher(struct crypto_tf "[%s]\n", cipher_name); goto out; } -if (key_size <crypto_tfm_alg_min_keysize (*tfm)) { - rc = -EINVAL ; -printk (KERN_ERR "Request key size is [%Zd]; minimum key size " -"supported by cipher [%s] is [%d]\n" , key_size, - cipher_name,crypto_tfm_alg_min_keysize (*tfm)); - goto out; - } -if (key_size <crypto_tfm_alg_min_keysize (*key_tfm)) { - rc = -EINVAL ; -printk (KERN_ERR "Request key size is [%Zd]; minimum key size " -"supported by cipher [%s] is [%d]\n" , key_size, - cipher_name,crypto_tfm_alg_min_keysize (*key_tfm)); - goto out; - } -if (key_size >crypto_tfm_alg_max_keysize (*tfm)) { - rc = -EINVAL ; -printk (KERN_ERR "Request key size is [%Zd]; maximum key size " -"supported by cipher [%s] is [%d]\n" , key_size, - cipher_name,crypto_tfm_alg_min_keysize (*tfm)); - goto out; - } -if (key_size >crypto_tfm_alg_max_keysize (*key_tfm)) { - rc = -EINVAL ; -printk (KERN_ERR "Request key size is [%Zd]; maximum key size " -"supported by cipher [%s] is [%d]\n" , key_size, - cipher_name,crypto_tfm_alg_min_keysize (*key_tfm)); - goto out; - } -get_random_bytes (dummy_key, key_size); - rc =crypto_cipher_setkey (*tfm, dummy_key, key_size); -if (rc) { -printk (KERN_ERR "Error attempting to set key of size [%Zd] for " -"cipher [%s]; rc = [%d]\n" , key_size, cipher_name, rc); - rc = -EINVAL ; - goto out; - } - rc =crypto_cipher_setkey (*key_tfm, dummy_key, key_size); +if (*key_size ==0 ) + *key_size =crypto_tfm_alg_max_keysize (*key_tfm); +get_random_bytes (dummy_key, *key_size); + rc =crypto_cipher_setkey (*key_tfm, dummy_key, *key_size);if (rc) {printk (KERN_ERR "Error attempting to set key of size [%Zd] for " -"cipher [%s]; rc = [%d]\n" , key_size, cipher_name, rc); +"cipher [%s]; rc = [%d]\n" , *key_size, cipher_name, rc); rc = -EINVAL ; goto out; }
fs/ecryptfs/ecryptfs_kernel.h +2 -2
@@ -473,8 +473,8 @@ ecryptfs_parse_packet_set(struct ecryptf unsigned char *src, struct dentry *ecryptfs_dentry);int ecryptfs_truncate (struct dentry *dentry,loff_t new_length);int -ecryptfs_process_cipher (struct crypto_tfm **tfm,struct crypto_tfm **key_tfm, -char *cipher_name,size_t key_size); +ecryptfs_process_cipher (struct crypto_tfm **key_tfm,char *cipher_name, +size_t *key_size);int ecryptfs_inode_test (struct inode *inode,void *candidate_lower_inode);int ecryptfs_inode_set (struct inode *inode,void *lower_inode);void ecryptfs_init_inode (struct inode *inode,struct inode *lower_inode);
fs/ecryptfs/keystore.c +8 -11
@@ -493,19 +493,16 @@ static int decrypt_session_key(struct ec goto out; } } -if (password_s_ptr->session_key_encryption_key_bytes - <crypto_tfm_alg_min_keysize (tfm)) { -printk (KERN_WARNING "Session key encryption key is [%d] bytes; " -"minimum keysize for selected cipher is [%d] bytes.\n" , - password_s_ptr->session_key_encryption_key_bytes, -crypto_tfm_alg_min_keysize (tfm)); - rc = -EINVAL ; - goto out; - }if (tfm_mutex)mutex_lock (tfm_mutex); -crypto_cipher_setkey (tfm, password_s_ptr->session_key_encryption_key, - crypt_stat->key_size); + rc =crypto_cipher_setkey (tfm, + password_s_ptr->session_key_encryption_key, + crypt_stat->key_size); +if (rc <0 ) { +printk (KERN_ERR "Error setting key for crypto context\n" ); + rc = -EINVAL ; + goto out_free_tfm; + }/* TODO: virt_to_scatterlist */ encrypted_session_key = (char *)__get_free_page (GFP_KERNEL );if (!encrypted_session_key) {
fs/ecryptfs/main.c +2 -11
@@ -208,7 +208,6 @@ static int ecryptfs_parse_options(structchar *cipher_name_dst;char *cipher_name_src;char *cipher_key_bytes_src; -struct crypto_tfm *tmp_tfm;int cipher_name_len;if (!options) {
@@ -305,20 +304,12 @@ static int ecryptfs_parse_options(struct = '\0'; }if (!cipher_key_bytes_set) { - mount_crypt_stat->global_default_cipher_key_size = -ECRYPTFS_DEFAULT_KEY_BYTES ; -ecryptfs_printk (KERN_DEBUG ,"Cipher key size was not " -"specified. Defaulting to [%d]\n" , - mount_crypt_stat-> - global_default_cipher_key_size); + mount_crypt_stat->global_default_cipher_key_size =0 ; } rc =ecryptfs_process_cipher ( - &tmp_tfm, &mount_crypt_stat->global_key_tfm, mount_crypt_stat->global_default_cipher_name, - mount_crypt_stat->global_default_cipher_key_size); -if (tmp_tfm) -crypto_free_tfm (tmp_tfm); + &mount_crypt_stat->global_default_cipher_key_size);if (rc) { printk(KERN_ERR "Error attempting to initialize cipher [%s] " "with key size [%Zd] bytes; rc = [%d]\n",
Signature · 1 line
1.3.3
PATCH 2/6 eCryptfs: Hash code to new crypto API
In reply to Michael HalcrowUpdate eCryptfs hash code to the new kernel crypto API.
---
fs/ecryptfs/crypto.c | 36 +++++++++++++++++++++--------------- fs/ecryptfs/ecryptfs_kernel.h | 7 ++++--- 2 files changed, 25 insertions(+), 18 deletions(-)
33eaa8582847bd8cef8b69537bee03f91fa5a28b
fs/ecryptfs/crypto.c +21 -15
@@ -94,25 +94,31 @@ static int ecryptfs_calculate_md5(char *struct ecryptfs_crypt_stat *crypt_stat, char *src, int len) { - int rc = 0; struct scatterlist sg; +struct hash_desc desc = { + .tfm = crypt_stat->hash_tfm, + .flags =CRYPTO_TFM_REQ_MAY_SLEEP + }; +int rc =0 ; -mutex_lock (&crypt_stat->cs_md5_tfm_mutex); +mutex_lock (&crypt_stat->cs_hash_tfm_mutex);sg_init_one (&sg, (u8 *)src, len); -if (!crypt_stat->md5_tfm) { - crypt_stat->md5_tfm = -crypto_alloc_tfm ("md5" ,CRYPTO_TFM_REQ_MAY_SLEEP ); -if (!crypt_stat->md5_tfm) { - rc = -ENOMEM ; +if (!desc.tfm) { + desc.tfm =crypto_alloc_hash (ECRYPTFS_DEFAULT_HASH ,0 , +CRYPTO_ALG_ASYNC ); +if (IS_ERR (desc.tfm)) { + rc =PTR_ERR (desc.tfm);ecryptfs_printk (KERN_ERR ,"Error attempting to " -"allocate crypto context\n" ); +"allocate crypto context; rc = [%d]\n" , + rc); goto out; } + crypt_stat->hash_tfm = desc.tfm; } -crypto_digest_init (crypt_stat->md5_tfm); -crypto_digest_update (crypt_stat->md5_tfm, &sg,1 ); -crypto_digest_final (crypt_stat->md5_tfm, dst); -mutex_unlock (&crypt_stat->cs_md5_tfm_mutex); +crypto_hash_init (&desc); +crypto_hash_update (&desc, &sg, len); +crypto_hash_final (&desc, dst); +mutex_unlock (&crypt_stat->cs_hash_tfm_mutex); out:return rc; }
@@ -178,7 +184,7 @@ ecryptfs_init_crypt_stat(struct ecryptfsmemset ((void *)crypt_stat,0 ,sizeof (struct ecryptfs_crypt_stat ));mutex_init (&crypt_stat->cs_mutex);mutex_init (&crypt_stat->cs_tfm_mutex); -mutex_init (&crypt_stat->cs_md5_tfm_mutex); +mutex_init (&crypt_stat->cs_hash_tfm_mutex);ECRYPTFS_SET_FLAG (crypt_stat->flags,ECRYPTFS_STRUCT_INITIALIZED ); }
@@ -192,8 +198,8 @@ void ecryptfs_destruct_crypt_stat(struct {if (crypt_stat->tfm)crypto_free_tfm (crypt_stat->tfm); -if (crypt_stat->md5_tfm) -crypto_free_tfm (crypt_stat->md5_tfm); +if (crypt_stat->hash_tfm) +crypto_free_hash (crypt_stat->hash_tfm);memset (crypt_stat,0 ,sizeof (struct ecryptfs_crypt_stat )); }
fs/ecryptfs/ecryptfs_kernel.h +4 -3
@@ -175,6 +175,7 @@ #define ECRYPTFS_FILE_SIZE_BYTES 8#define ECRYPTFS_DEFAULT_CIPHER "aes"#define ECRYPTFS_DEFAULT_KEY_BYTES 16#define ECRYPTFS_DEFAULT_CHAINING_MODE CRYPTO_TFM_MODE_CBC +#define ECRYPTFS_DEFAULT_HASH "md5"#define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C#define ECRYPTFS_TAG_11_PACKET_TYPE 0xED#define MD5_DIGEST_SIZE 16
@@ -205,14 +206,14 @@ #define ECRYPTFS_KEY_VALID 0x00unsigned int extent_mask;struct ecryptfs_mount_crypt_stat *mount_crypt_stat;struct crypto_tfm *tfm; -struct crypto_tfm *md5_tfm;/* Crypto context for generating -* the initialization vectors */ +struct crypto_hash *hash_tfm;/* Crypto context for generating +* the initialization vectors */ unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE ];unsigned char key[ECRYPTFS_MAX_KEY_BYTES ];unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES ];unsigned char keysigs[ECRYPTFS_MAX_NUM_KEYSIGS ][ECRYPTFS_SIG_SIZE_HEX ];struct mutex cs_tfm_mutex; -struct mutex cs_md5_tfm_mutex; +struct mutex cs_hash_tfm_mutex;struct mutex cs_mutex; };
Signature · 1 line
1.3.3
PATCH 3/6 eCryptfs: Cipher code to new crypto API
In reply to Michael HalcrowUpdate cipher block encryption code to the new crypto API.
---
fs/ecryptfs/crypto.c | 92 +++++++++++++++++++++++++++++-------- fs/ecryptfs/ecryptfs_kernel.h | 9 ++-- fs/ecryptfs/keystore.c | 101 +++++++++++++++++++++++++++-------------- fs/ecryptfs/main.c | 2 + 4 files changed, 146 insertions(+), 58 deletions(-)
401d3201a0ae8ff009eb1c363bef192ca06797b0
fs/ecryptfs/crypto.c +71 -21
@@ -123,6 +123,28 @@ out:return rc; } +int ecryptfs_crypto_api_algify_cipher_name (char **algified_name, +char *cipher_name, +char *chaining_modifier) +{ +int cipher_name_len =strlen (cipher_name); +int chaining_modifier_len =strlen (chaining_modifier); +int algified_name_len; +int rc; + + algified_name_len = (chaining_modifier_len + cipher_name_len +3 ); + (*algified_name) =kmalloc (algified_name_len,GFP_KERNEL ); +if (!(algified_name)) { + rc = -ENOMEM ; + goto out; + } +snprintf ((*algified_name), algified_name_len,"%s(%s)" , + chaining_modifier, cipher_name); + rc =0 ; +out: +return rc; +} +/** * ecryptfs_derive_iv * @iv: destination for the derived iv vale
@@ -197,7 +219,7 @@ ecryptfs_init_crypt_stat(struct ecryptfsvoid ecryptfs_destruct_crypt_stat (struct ecryptfs_crypt_stat *crypt_stat) {if (crypt_stat->tfm) -crypto_free_tfm (crypt_stat->tfm); +crypto_free_blkcipher (crypt_stat->tfm);if (crypt_stat->hash_tfm)crypto_free_hash (crypt_stat->hash_tfm);memset (crypt_stat,0 ,sizeof (struct ecryptfs_crypt_stat ));
@@ -209,7 +231,7 @@ void ecryptfs_destruct_mount_crypt_stat(if (mount_crypt_stat->global_auth_tok_key)key_put (mount_crypt_stat->global_auth_tok_key);if (mount_crypt_stat->global_key_tfm) -crypto_free_tfm (mount_crypt_stat->global_key_tfm); +crypto_free_blkcipher (mount_crypt_stat->global_key_tfm);memset (mount_crypt_stat,0 ,sizeof (struct ecryptfs_mount_crypt_stat )); }
@@ -275,6 +297,11 @@ static int encrypt_scatterlist(struct ec struct scatterlist *src_sg, int size, unsigned char *iv) { + struct blkcipher_desc desc = { + .tfm = crypt_stat->tfm, + .info = iv, + .flags =CRYPTO_TFM_REQ_MAY_SLEEP + };int rc =0 ; BUG_ON(!crypt_stat || !crypt_stat->tfm
@@ -288,8 +315,8 @@ static int encrypt_scatterlist(struct ec }/* Consider doing this once, when the file is opened */ mutex_lock (&crypt_stat->cs_tfm_mutex); - rc =crypto_cipher_setkey (crypt_stat->tfm, crypt_stat->key, - crypt_stat->key_size); + rc =crypto_blkcipher_setkey (crypt_stat->tfm, crypt_stat->key, + crypt_stat->key_size);if (rc) {ecryptfs_printk (KERN_ERR ,"Error setting key; rc = [%d]\n" , rc);
@@ -298,7 +325,7 @@ static int encrypt_scatterlist(struct ec goto out; }ecryptfs_printk (KERN_DEBUG ,"Encrypting [%d] bytes.\n" , size); -crypto_cipher_encrypt_iv (crypt_stat->tfm, dest_sg, src_sg, size, iv); +crypto_blkcipher_encrypt_iv (&desc, dest_sg, src_sg, size);mutex_unlock (&crypt_stat->cs_tfm_mutex); out:return rc;
@@ -681,12 +708,17 @@ static int decrypt_scatterlist(struct ec struct scatterlist *src_sg, int size, unsigned char *iv) { + struct blkcipher_desc desc = { + .tfm = crypt_stat->tfm, + .info = iv, + .flags =CRYPTO_TFM_REQ_MAY_SLEEP + };int rc =0 ;/* Consider doing this once, when the file is opened */ mutex_lock (&crypt_stat->cs_tfm_mutex); - rc =crypto_cipher_setkey (crypt_stat->tfm, crypt_stat->key, - crypt_stat->key_size); + rc =crypto_blkcipher_setkey (crypt_stat->tfm, crypt_stat->key, + crypt_stat->key_size);if (rc) {ecryptfs_printk (KERN_ERR ,"Error setting key; rc = [%d]\n" , rc);
@@ -695,8 +727,7 @@ static int decrypt_scatterlist(struct ec goto out; }ecryptfs_printk (KERN_DEBUG ,"Decrypting [%d] bytes.\n" , size); - rc =crypto_cipher_decrypt_iv (crypt_stat->tfm, dest_sg, src_sg, size, - iv); + rc =crypto_blkcipher_decrypt_iv (&desc, dest_sg, src_sg, size);mutex_unlock (&crypt_stat->cs_tfm_mutex);if (rc) { ecryptfs_printk(KERN_ERR, "Error decrypting; rc = [%d]\n",
@@ -765,6 +796,7 @@ #define ECRYPTFS_MAX_SCATTERLIST_LEN 4*/ int ecryptfs_init_crypt_ctx (struct ecryptfs_crypt_stat *crypt_stat) { +char *full_alg_name;int rc = -EINVAL ;if (!crypt_stat->cipher) {
@@ -781,16 +813,24 @@ int ecryptfs_init_crypt_ctx(struct ecryp goto out; }mutex_lock (&crypt_stat->cs_tfm_mutex); - crypt_stat->tfm =crypto_alloc_tfm (crypt_stat->cipher, -ECRYPTFS_DEFAULT_CHAINING_MODE - |CRYPTO_TFM_REQ_WEAK_KEY ); -mutex_unlock (&crypt_stat->cs_tfm_mutex); + rc =ecryptfs_crypto_api_algify_cipher_name (&full_alg_name, + crypt_stat->cipher,"cbc" ); +if (rc) + goto out; + crypt_stat->tfm =crypto_alloc_blkcipher (full_alg_name,0 , +CRYPTO_ALG_ASYNC ); +kfree (full_alg_name);if (!crypt_stat->tfm) {ecryptfs_printk (KERN_ERR ,"cryptfs: init_crypt_ctx(): " "Error initializing cipher [%s]\n" , crypt_stat->cipher); +mutex_unlock (&crypt_stat->cs_tfm_mutex); goto out; } +crypto_blkcipher_set_flags (crypt_stat->tfm, + (ECRYPTFS_DEFAULT_CHAINING_MODE + |CRYPTO_TFM_REQ_WEAK_KEY )); +mutex_unlock (&crypt_stat->cs_tfm_mutex); rc =0 ; out:return rc;
@@ -1588,10 +1628,11 @@ out:* event, regardless of whether this function succeeds for fails. */ int -ecryptfs_process_cipher (struct crypto_tfm **key_tfm,char *cipher_name, +ecryptfs_process_cipher (struct crypto_blkcipher **key_tfm,char *cipher_name,size_t *key_size) {char dummy_key[ECRYPTFS_MAX_KEY_BYTES ]; +char *full_alg_name;int rc; *key_tfm =NULL ;
@@ -1601,17 +1642,26 @@ ecryptfs_process_cipher(struct crypto_tf "allowable is [%d]\n", *key_size, ECRYPTFS_MAX_KEY_BYTES); goto out; } - *key_tfm =crypto_alloc_tfm (cipher_name,CRYPTO_TFM_REQ_WEAK_KEY ); -if (!(*key_tfm)) { - rc = -EINVAL ; + rc =ecryptfs_crypto_api_algify_cipher_name (&full_alg_name, cipher_name, +"ecb" ); +if (rc) + goto out; + *key_tfm =crypto_alloc_blkcipher (full_alg_name,0 ,CRYPTO_ALG_ASYNC ); +kfree (full_alg_name); +if (IS_ERR (*key_tfm)) { + rc =PTR_ERR (*key_tfm);printk (KERN_ERR "Unable to allocate crypto cipher with name " -"[%s]\n" , cipher_name); +"[%s]; rc = [%d]\n" , cipher_name, rc); goto out; } -if (*key_size ==0 ) - *key_size =crypto_tfm_alg_max_keysize (*key_tfm); +crypto_blkcipher_set_flags (*key_tfm,CRYPTO_TFM_REQ_WEAK_KEY ); +if (*key_size ==0 ) { +struct blkcipher_alg *alg =crypto_blkcipher_alg (*key_tfm); + + *key_size = alg->max_keysize; + }get_random_bytes (dummy_key, *key_size); - rc =crypto_cipher_setkey (*key_tfm, dummy_key, *key_size); + rc =crypto_blkcipher_setkey (*key_tfm, dummy_key, *key_size);if (rc) {printk (KERN_ERR "Error attempting to set key of size [%Zd] for " "cipher [%s]; rc = [%d]\n" , *key_size, cipher_name, rc);
fs/ecryptfs/ecryptfs_kernel.h +6 -3
@@ -205,7 +205,7 @@ #define ECRYPTFS_KEY_VALID 0x00size_t extent_shift;unsigned int extent_mask;struct ecryptfs_mount_crypt_stat *mount_crypt_stat; -struct crypto_tfm *tfm; +struct crypto_blkcipher *tfm;struct crypto_hash *hash_tfm;/* Crypto context for generating * the initialization vectors */ unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE ];
@@ -245,7 +245,7 @@ #define ECRYPTFS_PLAINTEXT_PASSTHROUGH_Estruct ecryptfs_auth_tok *global_auth_tok;struct key *global_auth_tok_key;size_t global_default_cipher_key_size; -struct crypto_tfm *global_key_tfm; +struct crypto_blkcipher *global_key_tfm;struct mutex global_key_tfm_mutex;unsigned char global_default_cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE +1 ];
@@ -426,6 +426,9 @@ void ecryptfs_destruct_crypt_stat(structvoid ecryptfs_destruct_mount_crypt_stat (struct ecryptfs_mount_crypt_stat *mount_crypt_stat);int ecryptfs_init_crypt_ctx (struct ecryptfs_crypt_stat *crypt_stat); +int ecryptfs_crypto_api_algify_cipher_name (char **algified_name, +char *cipher_name, +char *chaining_modifier);int ecryptfs_write_inode_size_to_header (struct file *lower_file,struct inode *lower_inode,struct inode *inode);
@@ -474,7 +477,7 @@ ecryptfs_parse_packet_set(struct ecryptf unsigned char *src, struct dentry *ecryptfs_dentry);int ecryptfs_truncate (struct dentry *dentry,loff_t new_length);int -ecryptfs_process_cipher (struct crypto_tfm **key_tfm,char *cipher_name, +ecryptfs_process_cipher (struct crypto_blkcipher **key_tfm,char *cipher_name,size_t *key_size);int ecryptfs_inode_test (struct inode *inode,void *candidate_lower_inode);int ecryptfs_inode_set (struct inode *inode,void *lower_inode);
fs/ecryptfs/keystore.c +67 -34
185 lines not on this page · raw message
fs/ecryptfs/main.c +2 -0
@@ -315,6 +315,8 @@ static int ecryptfs_parse_options(struct"with key size [%Zd] bytes; rc = [%d]\n" , mount_crypt_stat->global_default_cipher_name, mount_crypt_stat->global_default_cipher_key_size, rc); + mount_crypt_stat->global_key_tfm =NULL ; + mount_crypt_stat->global_auth_tok_key =NULL ; rc = -EINVAL ; goto out; }
Signature · 1 line
1.3.3
PATCH 4/6 eCryptfs: Consolidate lower dentry_open's
In reply to Michael HalcrowOpens on lower dentry objects happen in several places in eCryptfs, and they all involve the same steps (dget, mntget, dentry_open). This patch consolidates the lower open events into a single function call.
---
fs/ecryptfs/crypto.c | 24 +++++++++++----------- fs/ecryptfs/ecryptfs_kernel.h | 4 ++++ fs/ecryptfs/file.c | 44 ++++++++++++++++++++++++++++++++++------- fs/ecryptfs/inode.c | 33 ++++++++++--------------------- 4 files changed, 63 insertions(+), 42 deletions(-)
ae8de046956510acf0bd358ac93adccc78f76e84
fs/ecryptfs/crypto.c +12 -12
@@ -1191,28 +1191,28 @@ int ecryptfs_cipher_code_to_string(charint ecryptfs_read_header_region (char *data,struct dentry *dentry,struct vfsmount *mnt) { -struct file *file; +struct file *lower_file;mm_segment_t oldfs;int rc; - mnt =mntget (mnt); - file =dentry_open (dentry, mnt,O_RDONLY ); -if (IS_ERR (file)) { -ecryptfs_printk (KERN_DEBUG ,"Error opening file to " -"read header region\n" ); -mntput (mnt); - rc =PTR_ERR (file); +if ((rc =ecryptfs_open_lower_file (&lower_file, dentry, mnt, +O_RDONLY ))) { +printk (KERN_ERR +"Error opening lower_file to read header region\n" ); goto out; } - file->f_pos =0 ; + lower_file->f_pos =0 ; oldfs =get_fs ();set_fs (get_ds ());/* For releases 0.1 and 0.2, all of the header information * fits in the first data extent-sized region. */ - rc = file->f_op->read (file, (char __user *)data, -ECRYPTFS_DEFAULT_EXTENT_SIZE , &file->f_pos); + rc = lower_file->f_op->read (lower_file, (char __user *)data, +ECRYPTFS_DEFAULT_EXTENT_SIZE , &lower_file->f_pos);set_fs (oldfs); -fput (file); +if ((rc =ecryptfs_close_lower_file (lower_file))) { +printk (KERN_ERR "Error closing lower_file\n" ); + goto out; + } rc =0 ; out:return rc;
fs/ecryptfs/ecryptfs_kernel.h +4 -0
@@ -482,5 +482,9 @@ ecryptfs_process_cipher(struct crypto_blint ecryptfs_inode_test (struct inode *inode,void *candidate_lower_inode);int ecryptfs_inode_set (struct inode *inode,void *lower_inode);void ecryptfs_init_inode (struct inode *inode,struct inode *lower_inode); +int ecryptfs_open_lower_file (struct file **lower_file, +struct dentry *lower_dentry, +struct vfsmount *lower_mnt,int flags); +int ecryptfs_close_lower_file (struct file *lower_file);#endif /* #ifndef ECRYPTFS_KERNEL_H */
fs/ecryptfs/file.c +36 -8
72 lines not on this page · raw message
fs/ecryptfs/inode.c +11 -22
@@ -231,7 +231,6 @@ static int ecryptfs_initialize_file(struint lower_flags;struct ecryptfs_crypt_stat *crypt_stat;struct dentry *lower_dentry; -struct dentry *tlower_dentry =NULL ;struct file *lower_file;struct inode *inode, *lower_inode;struct vfsmount *lower_mnt;
@@ -241,30 +240,19 @@ static int ecryptfs_initialize_file(stru lower_dentry->d_name.name); inode = ecryptfs_dentry->d_inode; crypt_stat = &ecryptfs_inode_to_private (inode)->crypt_stat; - tlower_dentry =dget (lower_dentry); -if (!tlower_dentry) { - rc = -ENOMEM ; -ecryptfs_printk (KERN_ERR ,"Error dget'ing lower_dentry\n" ); - goto out; - } lower_flags = ((O_CREAT |O_WRONLY |O_TRUNC ) &O_ACCMODE ) |O_RDWR ;#if BITS_PER_LONG !=32 lower_flags |=O_LARGEFILE ;#endif lower_mnt =ecryptfs_dentry_to_lower_mnt (ecryptfs_dentry); -mntget (lower_mnt);/* Corresponding fput() at end of this function */ - lower_file =dentry_open (tlower_dentry, lower_mnt, lower_flags); -if (IS_ERR (lower_file)) { - rc =PTR_ERR (lower_file); +if ((rc =ecryptfs_open_lower_file (&lower_file, lower_dentry, lower_mnt, + lower_flags))) {ecryptfs_printk (KERN_ERR ,"Error opening dentry; rc = [%i]\n" , rc); goto out; } -/* fput(lower_file) should handle the puts if we do this */ - lower_file->f_dentry = tlower_dentry; - lower_file->f_vfsmnt = lower_mnt; - lower_inode = tlower_dentry->d_inode; + lower_inode = lower_dentry->d_inode;if (S_ISDIR (ecryptfs_dentry->d_inode->i_mode)) {ecryptfs_printk (KERN_DEBUG ,"This is a directory\n" );ECRYPTFS_CLEAR_FLAG (crypt_stat->flags,ECRYPTFS_ENCRYPTED );
@@ -285,7 +273,8 @@ #endif } rc =grow_file (ecryptfs_dentry, lower_file, inode, lower_inode); out_fput: -fput (lower_file); +if ((rc =ecryptfs_close_lower_file (lower_file))) +printk (KERN_ERR "Error closing lower_file\n" ); out:return rc; }
@@ -832,12 +821,11 @@ int ecryptfs_truncate(struct dentry *den } lower_dentry =ecryptfs_dentry_to_lower (dentry);/* This dget & mntget is released through fput at out_fput: */ -dget (lower_dentry); lower_mnt =ecryptfs_dentry_to_lower_mnt (dentry); -mntget (lower_mnt); - lower_file =dentry_open (lower_dentry, lower_mnt,O_RDWR ); -if (unlikely (IS_ERR (lower_file))) { - rc =PTR_ERR (lower_file); +if ((rc =ecryptfs_open_lower_file (&lower_file, lower_dentry, lower_mnt, +O_RDWR ))) { +ecryptfs_printk (KERN_ERR , +"Error opening dentry; rc = [%i]\n" , rc); goto out_free; }ecryptfs_set_file_lower (&fake_ecryptfs_file, lower_file);
@@ -879,7 +867,8 @@ int ecryptfs_truncate(struct dentry *den = CURRENT_TIME;mark_inode_dirty_sync (inode); out_fput: -fput (lower_file); +if ((rc =ecryptfs_close_lower_file (lower_file))) +printk (KERN_ERR "Error closing lower_file\n" ); out_free:if (ecryptfs_file_to_private (&fake_ecryptfs_file)) kmem_cache_free(ecryptfs_file_info_cache,
Signature · 1 line
1.3.3
PATCH 5/6 eCryptfs: Remove ecryptfs_umount_begin
In reply to Michael HalcrowThere is no point to calling the lower umount_begin when the eCryptfs umount_begin is called.
---
fs/ecryptfs/super.c | 18 ------------------ 1 files changed, 0 insertions(+), 18 deletions(-)
fc8b627f3b892266ac9a17e011396130ab8f6ddf
fs/ecryptfs/super.c +0 -18
@@ -138,23 +138,6 @@ static void ecryptfs_clear_inode(struct }/** -* ecryptfs_umount_begin -* -* Called in do_umount(). -*/ -static void ecryptfs_umount_begin (struct vfsmount *vfsmnt,int flags) -{ -struct vfsmount *lower_mnt = -ecryptfs_dentry_to_lower_mnt (vfsmnt->mnt_sb->s_root); -struct super_block *lower_sb; - -mntput (lower_mnt); - lower_sb = lower_mnt->mnt_sb; -if (lower_sb->s_op->umount_begin) - lower_sb->s_op->umount_begin (lower_mnt, flags); -} - -/** * ecryptfs_show_options * * Prints the directory we are currently mounted over.
@@ -193,6 +176,5 @@ struct super_operations ecryptfs_sops = .statfs = ecryptfs_statfs, .remount_fs = NULL, .clear_inode = ecryptfs_clear_inode, - .umount_begin = ecryptfs_umount_begin, .show_options = ecryptfs_show_options };
Signature · 1 line
1.3.3
PATCH 6/6 eCryptfs: Fix handling of lower d_count
In reply to Michael HalcrowFix the use of dget/dput calls to balance out on the lower filesystem.
---
fs/ecryptfs/dentry.c | 8 ++++++ fs/ecryptfs/inode.c | 62 ++++++++++++++++---------------------------------- 2 files changed, 27 insertions(+), 43 deletions(-)
0277a301b99c7a2270fcca1e2c2ada96037b6fa1
fs/ecryptfs/dentry.c +7 -1
@@ -24,6 +24,7 @@#include <linux/dcache.h> #include <linux/namei.h> +#include <linux/mount.h> #include "ecryptfs_kernel.h" /**
@@ -76,8 +77,13 @@ static void ecryptfs_d_release(struct deif (ecryptfs_dentry_to_private (dentry))kmem_cache_free (ecryptfs_dentry_info_cache,ecryptfs_dentry_to_private (dentry)); -if (lower_dentry) +if (lower_dentry) { +struct vfsmount *lower_mnt = +ecryptfs_dentry_to_lower_mnt (dentry); + +mntput (lower_mnt);dput (lower_dentry); + }return ; }
fs/ecryptfs/inode.c +20 -42
131 lines not on this page · raw message
Signature · 1 line
1.3.3
Re: [PATCH 2/6] eCryptfs: Hash code to new crypto API
In reply to Michael Halcrowfs/ecryptfs/crypto.c static int ecryptfs_calculate_md5(char * · line 120
Quoted 4 lines · Michael Halcrow
fs/ecryptfs/crypto.c +3
-0+crypto_hash_init (&desc); +crypto_hash_update (&desc, &sg, len); +crypto_hash_final (&desc, dst);
Whenever you do init+update+final, it's preferred that this be changed to crypto_hash_digest as this enables future optimisations to be made. For instance, some hardware can only handle a full digest rather than a partial update.
Thanks,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtPATCH 1/1 eCryptfs: Fix pointer deref
In reply to Michael HalcrowReview
Quoted 6 lines · Michael Halcrow
(quoted diff) +6
-0+ algified_name_len = (chaining_modifier_len + cipher_name_len + 3); + (*algified_name) = kmalloc(algified_name_len, GFP_KERNEL); + if (!(algified_name)) { + rc = -ENOMEM; + goto out; + }
I missed a pointer dereference in this kmalloc result check.
---
fs/ecryptfs/crypto.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
b30f5b01ff79d9250dbd9e39db1c1aae7719c815
fs/ecryptfs/crypto.c +1 -1
@@ -134,7 +134,7 @@ int ecryptfs_crypto_api_algify_cipher_na algified_name_len = (chaining_modifier_len + cipher_name_len +3 ); (*algified_name) =kmalloc (algified_name_len,GFP_KERNEL ); -if (!(algified_name)) { +if (!(*algified_name)) { rc = -ENOMEM ; goto out; }
Signature · 1 line
1.3.3