aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@linux.vnet.ibm.com>2011-07-26 20:47:08 -0400
committerTyler Hicks <tyhicks@linux.vnet.ibm.com>2011-07-29 00:30:09 -0400
commitb2987a5e05ec7a1af7ca42e5d5349d7a22753031 (patch)
treebe0a56d227b5f6b661c0f8eecf960b61051d05d6 /fs/ecryptfs
parent55f9c40ff632d03c527d6a6ceddcda0a224587a6 (diff)
eCryptfs: Unlock keys needed by ecryptfsd
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> Cc: <stable@kernel.org> [2.6.39+]
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 c47253350123..08a2b52bf565 100644
--- a/fs/ecryptfs/keystore.c
+++ b/fs/ecryptfs/keystore.c
@@ -1871,11 +1871,6 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
1871 * just one will be sufficient to decrypt to get the FEK. */ 1871 * just one will be sufficient to decrypt to get the FEK. */
1872find_next_matching_auth_tok: 1872find_next_matching_auth_tok:
1873 found_auth_tok = 0; 1873 found_auth_tok = 0;
1874 if (auth_tok_key) {
1875 up_write(&(auth_tok_key->sem));
1876 key_put(auth_tok_key);
1877 auth_tok_key = NULL;
1878 }
1879 list_for_each_entry(auth_tok_list_item, &auth_tok_list, list) { 1874 list_for_each_entry(auth_tok_list_item, &auth_tok_list, list) {
1880 candidate_auth_tok = &auth_tok_list_item->auth_tok; 1875 candidate_auth_tok = &auth_tok_list_item->auth_tok;
1881 if (unlikely(ecryptfs_verbosity > 0)) { 1876 if (unlikely(ecryptfs_verbosity > 0)) {
@@ -1912,14 +1907,22 @@ found_matching_auth_tok:
1912 memcpy(&(candidate_auth_tok->token.private_key), 1907 memcpy(&(candidate_auth_tok->token.private_key),
1913 &(matching_auth_tok->token.private_key), 1908 &(matching_auth_tok->token.private_key),
1914 sizeof(struct ecryptfs_private_key)); 1909 sizeof(struct ecryptfs_private_key));
1910 up_write(&(auth_tok_key->sem));
1911 key_put(auth_tok_key);
1915 rc = decrypt_pki_encrypted_session_key(candidate_auth_tok, 1912 rc = decrypt_pki_encrypted_session_key(candidate_auth_tok,
1916 crypt_stat); 1913 crypt_stat);
1917 } else if (candidate_auth_tok->token_type == ECRYPTFS_PASSWORD) { 1914 } else if (candidate_auth_tok->token_type == ECRYPTFS_PASSWORD) {
1918 memcpy(&(candidate_auth_tok->token.password), 1915 memcpy(&(candidate_auth_tok->token.password),
1919 &(matching_auth_tok->token.password), 1916 &(matching_auth_tok->token.password),
1920 sizeof(struct ecryptfs_password)); 1917 sizeof(struct ecryptfs_password));
1918 up_write(&(auth_tok_key->sem));
1919 key_put(auth_tok_key);
1921 rc = decrypt_passphrase_encrypted_session_key( 1920 rc = decrypt_passphrase_encrypted_session_key(
1922 candidate_auth_tok, crypt_stat); 1921 candidate_auth_tok, crypt_stat);
1922 } else {
1923 up_write(&(auth_tok_key->sem));
1924 key_put(auth_tok_key);
1925 rc = -EINVAL;
1923 } 1926 }
1924 if (rc) { 1927 if (rc) {
1925 struct ecryptfs_auth_tok_list_item *auth_tok_list_item_tmp; 1928 struct ecryptfs_auth_tok_list_item *auth_tok_list_item_tmp;
@@ -1959,15 +1962,12 @@ found_matching_auth_tok:
1959out_wipe_list: 1962out_wipe_list:
1960 wipe_auth_tok_list(&auth_tok_list); 1963 wipe_auth_tok_list(&auth_tok_list);
1961out: 1964out:
1962 if (auth_tok_key) {
1963 up_write(&(auth_tok_key->sem));
1964 key_put(auth_tok_key);
1965 }
1966 return rc; 1965 return rc;
1967} 1966}
1968 1967
1969static int 1968static int
1970pki_encrypt_session_key(struct ecryptfs_auth_tok *auth_tok, 1969pki_encrypt_session_key(struct key *auth_tok_key,
1970 struct ecryptfs_auth_tok *auth_tok,
1971 struct ecryptfs_crypt_stat *crypt_stat, 1971 struct ecryptfs_crypt_stat *crypt_stat,
1972 struct ecryptfs_key_record *key_rec) 1972 struct ecryptfs_key_record *key_rec)
1973{ 1973{
@@ -1982,6 +1982,8 @@ pki_encrypt_session_key(struct ecryptfs_auth_tok *auth_tok,
1982 crypt_stat->cipher, 1982 crypt_stat->cipher,
1983 crypt_stat->key_size), 1983 crypt_stat->key_size),
1984 crypt_stat, &payload, &payload_len); 1984 crypt_stat, &payload, &payload_len);
1985 up_write(&(auth_tok_key->sem));
1986 key_put(auth_tok_key);
1985 if (rc) { 1987 if (rc) {
1986 ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet\n"); 1988 ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet\n");
1987 goto out; 1989 goto out;
@@ -2011,6 +2013,8 @@ out:
2011 * write_tag_1_packet - Write an RFC2440-compatible tag 1 (public key) packet 2013 * write_tag_1_packet - Write an RFC2440-compatible tag 1 (public key) packet
2012 * @dest: Buffer into which to write the packet 2014 * @dest: Buffer into which to write the packet
2013 * @remaining_bytes: Maximum number of bytes that can be writtn 2015 * @remaining_bytes: Maximum number of bytes that can be writtn
2016 * @auth_tok_key: The authentication token key to unlock and put when done with
2017 * @auth_tok
2014 * @auth_tok: The authentication token used for generating the tag 1 packet 2018 * @auth_tok: The authentication token used for generating the tag 1 packet
2015 * @crypt_stat: The cryptographic context 2019 * @crypt_stat: The cryptographic context
2016 * @key_rec: The key record struct for the tag 1 packet 2020 * @key_rec: The key record struct for the tag 1 packet
@@ -2021,7 +2025,7 @@ out:
2021 */ 2025 */
2022static int 2026static int
2023write_tag_1_packet(char *dest, size_t *remaining_bytes, 2027write_tag_1_packet(char *dest, size_t *remaining_bytes,
2024 struct ecryptfs_auth_tok *auth_tok, 2028 struct key *auth_tok_key, struct ecryptfs_auth_tok *auth_tok,
2025 struct ecryptfs_crypt_stat *crypt_stat, 2029 struct ecryptfs_crypt_stat *crypt_stat,
2026 struct ecryptfs_key_record *key_rec, size_t *packet_size) 2030 struct ecryptfs_key_record *key_rec, size_t *packet_size)
2027{ 2031{
@@ -2042,12 +2046,15 @@ write_tag_1_packet(char *dest, size_t *remaining_bytes,
2042 memcpy(key_rec->enc_key, 2046 memcpy(key_rec->enc_key,
2043 auth_tok->session_key.encrypted_key, 2047 auth_tok->session_key.encrypted_key,
2044 auth_tok->session_key.encrypted_key_size); 2048 auth_tok->session_key.encrypted_key_size);
2049 up_write(&(auth_tok_key->sem));
2050 key_put(auth_tok_key);
2045 goto encrypted_session_key_set; 2051 goto encrypted_session_key_set;
2046 } 2052 }
2047 if (auth_tok->session_key.encrypted_key_size == 0) 2053 if (auth_tok->session_key.encrypted_key_size == 0)
2048 auth_tok->session_key.encrypted_key_size = 2054 auth_tok->session_key.encrypted_key_size =
2049 auth_tok->token.private_key.key_size; 2055 auth_tok->token.private_key.key_size;
2050 rc = pki_encrypt_session_key(auth_tok, crypt_stat, key_rec); 2056 rc = pki_encrypt_session_key(auth_tok_key, auth_tok, crypt_stat,
2057 key_rec);
2051 if (rc) { 2058 if (rc) {
2052 printk(KERN_ERR "Failed to encrypt session key via a key " 2059 printk(KERN_ERR "Failed to encrypt session key via a key "
2053 "module; rc = [%d]\n", rc); 2060 "module; rc = [%d]\n", rc);
@@ -2424,6 +2431,8 @@ ecryptfs_generate_key_packet_set(char *dest_base,
2424 &max, auth_tok, 2431 &max, auth_tok,
2425 crypt_stat, key_rec, 2432 crypt_stat, key_rec,
2426 &written); 2433 &written);
2434 up_write(&(auth_tok_key->sem));
2435 key_put(auth_tok_key);
2427 if (rc) { 2436 if (rc) {
2428 ecryptfs_printk(KERN_WARNING, "Error " 2437 ecryptfs_printk(KERN_WARNING, "Error "
2429 "writing tag 3 packet\n"); 2438 "writing tag 3 packet\n");
@@ -2441,8 +2450,8 @@ ecryptfs_generate_key_packet_set(char *dest_base,
2441 } 2450 }
2442 (*len) += written; 2451 (*len) += written;
2443 } else if (auth_tok->token_type == ECRYPTFS_PRIVATE_KEY) { 2452 } else if (auth_tok->token_type == ECRYPTFS_PRIVATE_KEY) {
2444 rc = write_tag_1_packet(dest_base + (*len), 2453 rc = write_tag_1_packet(dest_base + (*len), &max,
2445 &max, auth_tok, 2454 auth_tok_key, auth_tok,
2446 crypt_stat, key_rec, &written); 2455 crypt_stat, key_rec, &written);
2447 if (rc) { 2456 if (rc) {
2448 ecryptfs_printk(KERN_WARNING, "Error " 2457 ecryptfs_printk(KERN_WARNING, "Error "
@@ -2451,14 +2460,13 @@ ecryptfs_generate_key_packet_set(char *dest_base,
2451 } 2460 }
2452 (*len) += written; 2461 (*len) += written;
2453 } else { 2462 } else {
2463 up_write(&(auth_tok_key->sem));
2464 key_put(auth_tok_key);
2454 ecryptfs_printk(KERN_WARNING, "Unsupported " 2465 ecryptfs_printk(KERN_WARNING, "Unsupported "
2455 "authentication token type\n"); 2466 "authentication token type\n");
2456 rc = -EINVAL; 2467 rc = -EINVAL;
2457 goto out_free; 2468 goto out_free;
2458 } 2469 }
2459 up_write(&(auth_tok_key->sem));
2460 key_put(auth_tok_key);
2461 auth_tok_key = NULL;
2462 } 2470 }
2463 if (likely(max > 0)) { 2471 if (likely(max > 0)) {
2464 dest_base[(*len)] = 0x00; 2472 dest_base[(*len)] = 0x00;
@@ -2471,11 +2479,6 @@ out_free:
2471out: 2479out:
2472 if (rc) 2480 if (rc)
2473 (*len) = 0; 2481 (*len) = 0;
2474 if (auth_tok_key) {
2475 up_write(&(auth_tok_key->sem));
2476 key_put(auth_tok_key);
2477 }
2478
2479 mutex_unlock(&crypt_stat->keysig_list_mutex); 2482 mutex_unlock(&crypt_stat->keysig_list_mutex);
2480 return rc; 2483 return rc;
2481} 2484}