aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@linux.vnet.ibm.com>2011-07-26 20:47:08 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-08-05 00:58:39 -0400
commitefc977be4683816c39dfab38a34f68e07b78997e (patch)
treef5e6296a2fffd89df762e4808339043411809c3a /fs/ecryptfs
parenta21353bae5e98fce18080a3691ef75ede61dd261 (diff)
eCryptfs: Unlock keys needed by ecryptfsd
commit b2987a5e05ec7a1af7ca42e5d5349d7a22753031 upstream. Fixes a regression caused by b5695d04634fa4ccca7dcbc05bb4a66522f02e0b Kernel keyring keys containing eCryptfs authentication tokens should not be write locked when calling out to ecryptfsd to wrap and unwrap file encryption keys. The eCryptfs kernel code can not hold the key's write lock because ecryptfsd needs to request the key after receiving such a request from the kernel. Without this fix, all file opens and creates will timeout and fail when using the eCryptfs PKI infrastructure. This is not an issue when using passphrase-based mount keys, which is the most widely deployed eCryptfs configuration. Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com> Acked-by: Roberto Sassu <roberto.sassu@polito.it> Tested-by: Roberto Sassu <roberto.sassu@polito.it> Tested-by: Alexis Hafner1 <haf@zurich.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r--fs/ecryptfs/keystore.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
index 27a7fefb83e..89dc18e7e95 100644
--- a/fs/ecryptfs/keystore.c
+++ b/fs/ecryptfs/keystore.c
@@ -1868,11 +1868,6 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
1868 * just one will be sufficient to decrypt to get the FEK. */ 1868 * just one will be sufficient to decrypt to get the FEK. */
1869find_next_matching_auth_tok: 1869find_next_matching_auth_tok:
1870 found_auth_tok = 0; 1870 found_auth_tok = 0;
1871 if (auth_tok_key) {
1872 up_write(&(auth_tok_key->sem));
1873 key_put(auth_tok_key);
1874 auth_tok_key = NULL;
1875 }
1876 list_for_each_entry(auth_tok_list_item, &auth_tok_list, list) { 1871 list_for_each_entry(auth_tok_list_item, &auth_tok_list, list) {
1877 candidate_auth_tok = &auth_tok_list_item->auth_tok; 1872 candidate_auth_tok = &auth_tok_list_item->auth_tok;
1878 if (unlikely(ecryptfs_verbosity > 0)) { 1873 if (unlikely(ecryptfs_verbosity > 0)) {
@@ -1909,14 +1904,22 @@ found_matching_auth_tok:
1909 memcpy(&(candidate_auth_tok->token.private_key), 1904 memcpy(&(candidate_auth_tok->token.private_key),
1910 &(matching_auth_tok->token.private_key), 1905 &(matching_auth_tok->token.private_key),
1911 sizeof(struct ecryptfs_private_key)); 1906 sizeof(struct ecryptfs_private_key));
1907 up_write(&(auth_tok_key->sem));
1908 key_put(auth_tok_key);
1912 rc = decrypt_pki_encrypted_session_key(candidate_auth_tok, 1909 rc = decrypt_pki_encrypted_session_key(candidate_auth_tok,
1913 crypt_stat); 1910 crypt_stat);
1914 } else if (candidate_auth_tok->token_type == ECRYPTFS_PASSWORD) { 1911 } else if (candidate_auth_tok->token_type == ECRYPTFS_PASSWORD) {
1915 memcpy(&(candidate_auth_tok->token.password), 1912 memcpy(&(candidate_auth_tok->token.password),
1916 &(matching_auth_tok->token.password), 1913 &(matching_auth_tok->token.password),
1917 sizeof(struct ecryptfs_password)); 1914 sizeof(struct ecryptfs_password));
1915 up_write(&(auth_tok_key->sem));
1916 key_put(auth_tok_key);
1918 rc = decrypt_passphrase_encrypted_session_key( 1917 rc = decrypt_passphrase_encrypted_session_key(
1919 candidate_auth_tok, crypt_stat); 1918 candidate_auth_tok, crypt_stat);
1919 } else {
1920 up_write(&(auth_tok_key->sem));
1921 key_put(auth_tok_key);
1922 rc = -EINVAL;
1920 } 1923 }
1921 if (rc) { 1924 if (rc) {
1922 struct ecryptfs_auth_tok_list_item *auth_tok_list_item_tmp; 1925 struct ecryptfs_auth_tok_list_item *auth_tok_list_item_tmp;
@@ -1956,15 +1959,12 @@ found_matching_auth_tok:
1956out_wipe_list: 1959out_wipe_list:
1957 wipe_auth_tok_list(&auth_tok_list); 1960 wipe_auth_tok_list(&auth_tok_list);
1958out: 1961out:
1959 if (auth_tok_key) {
1960 up_write(&(auth_tok_key->sem));
1961 key_put(auth_tok_key);
1962 }
1963 return rc; 1962 return rc;
1964} 1963}
1965 1964
1966static int 1965static int
1967pki_encrypt_session_key(struct ecryptfs_auth_tok *auth_tok, 1966pki_encrypt_session_key(struct key *auth_tok_key,
1967 struct ecryptfs_auth_tok *auth_tok,
1968 struct ecryptfs_crypt_stat *crypt_stat, 1968 struct ecryptfs_crypt_stat *crypt_stat,
1969 struct ecryptfs_key_record *key_rec) 1969 struct ecryptfs_key_record *key_rec)
1970{ 1970{
@@ -1979,6 +1979,8 @@ pki_encrypt_session_key(struct ecryptfs_auth_tok *auth_tok,
1979 crypt_stat->cipher, 1979 crypt_stat->cipher,
1980 crypt_stat->key_size), 1980 crypt_stat->key_size),
1981 crypt_stat, &payload, &payload_len); 1981 crypt_stat, &payload, &payload_len);
1982 up_write(&(auth_tok_key->sem));
1983 key_put(auth_tok_key);
1982 if (rc) { 1984 if (rc) {
1983 ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet\n"); 1985 ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet\n");
1984 goto out; 1986 goto out;
@@ -2008,6 +2010,8 @@ out:
2008 * write_tag_1_packet - Write an RFC2440-compatible tag 1 (public key) packet 2010 * write_tag_1_packet - Write an RFC2440-compatible tag 1 (public key) packet
2009 * @dest: Buffer into which to write the packet 2011 * @dest: Buffer into which to write the packet
2010 * @remaining_bytes: Maximum number of bytes that can be writtn 2012 * @remaining_bytes: Maximum number of bytes that can be writtn
2013 * @auth_tok_key: The authentication token key to unlock and put when done with
2014 * @auth_tok
2011 * @auth_tok: The authentication token used for generating the tag 1 packet 2015 * @auth_tok: The authentication token used for generating the tag 1 packet
2012 * @crypt_stat: The cryptographic context 2016 * @crypt_stat: The cryptographic context
2013 * @key_rec: The key record struct for the tag 1 packet 2017 * @key_rec: The key record struct for the tag 1 packet
@@ -2018,7 +2022,7 @@ out:
2018 */ 2022 */
2019static int 2023static int
2020write_tag_1_packet(char *dest, size_t *remaining_bytes, 2024write_tag_1_packet(char *dest, size_t *remaining_bytes,
2021 struct ecryptfs_auth_tok *auth_tok, 2025 struct key *auth_tok_key, struct ecryptfs_auth_tok *auth_tok,
2022 struct ecryptfs_crypt_stat *crypt_stat, 2026 struct ecryptfs_crypt_stat *crypt_stat,
2023 struct ecryptfs_key_record *key_rec, size_t *packet_size) 2027 struct ecryptfs_key_record *key_rec, size_t *packet_size)
2024{ 2028{
@@ -2039,12 +2043,15 @@ write_tag_1_packet(char *dest, size_t *remaining_bytes,
2039 memcpy(key_rec->enc_key, 2043 memcpy(key_rec->enc_key,
2040 auth_tok->session_key.encrypted_key, 2044 auth_tok->session_key.encrypted_key,
2041 auth_tok->session_key.encrypted_key_size); 2045 auth_tok->session_key.encrypted_key_size);
2046 up_write(&(auth_tok_key->sem));
2047 key_put(auth_tok_key);
2042 goto encrypted_session_key_set; 2048 goto encrypted_session_key_set;
2043 } 2049 }
2044 if (auth_tok->session_key.encrypted_key_size == 0) 2050 if (auth_tok->session_key.encrypted_key_size == 0)
2045 auth_tok->session_key.encrypted_key_size = 2051 auth_tok->session_key.encrypted_key_size =
2046 auth_tok->token.private_key.key_size; 2052 auth_tok->token.private_key.key_size;
2047 rc = pki_encrypt_session_key(auth_tok, crypt_stat, key_rec); 2053 rc = pki_encrypt_session_key(auth_tok_key, auth_tok, crypt_stat,
2054 key_rec);
2048 if (rc) { 2055 if (rc) {
2049 printk(KERN_ERR "Failed to encrypt session key via a key " 2056 printk(KERN_ERR "Failed to encrypt session key via a key "
2050 "module; rc = [%d]\n", rc); 2057 "module; rc = [%d]\n", rc);
@@ -2421,6 +2428,8 @@ ecryptfs_generate_key_packet_set(char *dest_base,
2421 &max, auth_tok, 2428 &max, auth_tok,
2422 crypt_stat, key_rec, 2429 crypt_stat, key_rec,
2423 &written); 2430 &written);
2431 up_write(&(auth_tok_key->sem));
2432 key_put(auth_tok_key);
2424 if (rc) { 2433 if (rc) {
2425 ecryptfs_printk(KERN_WARNING, "Error " 2434 ecryptfs_printk(KERN_WARNING, "Error "
2426 "writing tag 3 packet\n"); 2435 "writing tag 3 packet\n");
@@ -2438,8 +2447,8 @@ ecryptfs_generate_key_packet_set(char *dest_base,
2438 } 2447 }
2439 (*len) += written; 2448 (*len) += written;
2440 } else if (auth_tok->token_type == ECRYPTFS_PRIVATE_KEY) { 2449 } else if (auth_tok->token_type == ECRYPTFS_PRIVATE_KEY) {
2441 rc = write_tag_1_packet(dest_base + (*len), 2450 rc = write_tag_1_packet(dest_base + (*len), &max,
2442 &max, auth_tok, 2451 auth_tok_key, auth_tok,
2443 crypt_stat, key_rec, &written); 2452 crypt_stat, key_rec, &written);
2444 if (rc) { 2453 if (rc) {
2445 ecryptfs_printk(KERN_WARNING, "Error " 2454 ecryptfs_printk(KERN_WARNING, "Error "
@@ -2448,14 +2457,13 @@ ecryptfs_generate_key_packet_set(char *dest_base,
2448 } 2457 }
2449 (*len) += written; 2458 (*len) += written;
2450 } else { 2459 } else {
2460 up_write(&(auth_tok_key->sem));
2461 key_put(auth_tok_key);
2451 ecryptfs_printk(KERN_WARNING, "Unsupported " 2462 ecryptfs_printk(KERN_WARNING, "Unsupported "
2452 "authentication token type\n"); 2463 "authentication token type\n");
2453 rc = -EINVAL; 2464 rc = -EINVAL;
2454 goto out_free; 2465 goto out_free;
2455 } 2466 }
2456 up_write(&(auth_tok_key->sem));
2457 key_put(auth_tok_key);
2458 auth_tok_key = NULL;
2459 } 2467 }
2460 if (likely(max > 0)) { 2468 if (likely(max > 0)) {
2461 dest_base[(*len)] = 0x00; 2469 dest_base[(*len)] = 0x00;
@@ -2468,11 +2476,6 @@ out_free:
2468out: 2476out:
2469 if (rc) 2477 if (rc)
2470 (*len) = 0; 2478 (*len) = 0;
2471 if (auth_tok_key) {
2472 up_write(&(auth_tok_key->sem));
2473 key_put(auth_tok_key);
2474 }
2475
2476 mutex_unlock(&crypt_stat->keysig_list_mutex); 2479 mutex_unlock(&crypt_stat->keysig_list_mutex);
2477 return rc; 2480 return rc;
2478} 2481}