Skip to content

Commit 950983f

Browse files
Roberto SassuTyler Hicks
authored andcommitted
eCryptfs: move ecryptfs_find_auth_tok_for_sig() call before mutex_lock
The ecryptfs_find_auth_tok_for_sig() call is moved before the mutex_lock(s->tfm_mutex) instruction in order to avoid possible deadlocks that may occur by holding the lock on the two semaphores 'key->sem' and 's->tfm_mutex' in reverse order. Signed-off-by: Roberto Sassu <roberto.sassu@polito.it> Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
1 parent 0e1fc5e commit 950983f

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

‎fs/ecryptfs/keystore.c‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,16 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
635635
}
636636
s->desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
637637
(*packet_size) = 0;
638+
rc = ecryptfs_find_auth_tok_for_sig(
639+
&auth_tok_key,
640+
&s->auth_tok, mount_crypt_stat,
641+
mount_crypt_stat->global_default_fnek_sig);
642+
if (rc) {
643+
printk(KERN_ERR "%s: Error attempting to find auth tok for "
644+
"fnek sig [%s]; rc = [%d]\n", __func__,
645+
mount_crypt_stat->global_default_fnek_sig, rc);
646+
goto out;
647+
}
638648
rc = ecryptfs_get_tfm_and_mutex_for_cipher_name(
639649
&s->desc.tfm,
640650
&s->tfm_mutex, mount_crypt_stat->global_default_fn_cipher_name);
@@ -720,16 +730,6 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
720730
goto out_free_unlock;
721731
}
722732
dest[s->i++] = s->cipher_code;
723-
rc = ecryptfs_find_auth_tok_for_sig(
724-
&auth_tok_key,
725-
&s->auth_tok, mount_crypt_stat,
726-
mount_crypt_stat->global_default_fnek_sig);
727-
if (rc) {
728-
printk(KERN_ERR "%s: Error attempting to find auth tok for "
729-
"fnek sig [%s]; rc = [%d]\n", __func__,
730-
mount_crypt_stat->global_default_fnek_sig, rc);
731-
goto out_free_unlock;
732-
}
733733
/* TODO: Support other key modules than passphrase for
734734
* filename encryption */
735735
if (s->auth_tok->token_type != ECRYPTFS_PASSWORD) {
@@ -983,6 +983,15 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
983983
__func__, s->cipher_code);
984984
goto out;
985985
}
986+
rc = ecryptfs_find_auth_tok_for_sig(&auth_tok_key,
987+
&s->auth_tok, mount_crypt_stat,
988+
s->fnek_sig_hex);
989+
if (rc) {
990+
printk(KERN_ERR "%s: Error attempting to find auth tok for "
991+
"fnek sig [%s]; rc = [%d]\n", __func__, s->fnek_sig_hex,
992+
rc);
993+
goto out;
994+
}
986995
rc = ecryptfs_get_tfm_and_mutex_for_cipher_name(&s->desc.tfm,
987996
&s->tfm_mutex,
988997
s->cipher_string);
@@ -1029,15 +1038,6 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
10291038
* >= ECRYPTFS_MAX_IV_BYTES. */
10301039
memset(s->iv, 0, ECRYPTFS_MAX_IV_BYTES);
10311040
s->desc.info = s->iv;
1032-
rc = ecryptfs_find_auth_tok_for_sig(&auth_tok_key,
1033-
&s->auth_tok, mount_crypt_stat,
1034-
s->fnek_sig_hex);
1035-
if (rc) {
1036-
printk(KERN_ERR "%s: Error attempting to find auth tok for "
1037-
"fnek sig [%s]; rc = [%d]\n", __func__, s->fnek_sig_hex,
1038-
rc);
1039-
goto out_free_unlock;
1040-
}
10411041
/* TODO: Support other key modules than passphrase for
10421042
* filename encryption */
10431043
if (s->auth_tok->token_type != ECRYPTFS_PASSWORD) {

0 commit comments

Comments
 (0)