diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-30 02:43:50 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-30 02:43:50 -0400 |
commit | 74aec4e0dd93d4202d3d5a692723f39cc5332b15 (patch) | |
tree | 33affbfd65e4a1bfe3b27df6bd91baa2dfb593f7 /fs | |
parent | c32e7d669ef827f97d1aae8f6b34542665defbf6 (diff) | |
parent | 985ca0e626e195ea08a1a82b8dbeb6719747429a (diff) |
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/ecryptfs/ecryptfs-2.6
* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/ecryptfs/ecryptfs-2.6:
ecryptfs: Make inode bdi consistent with superblock bdi
eCryptfs: Unlock keys needed by ecryptfsd
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ecryptfs/inode.c | 1 | ||||
-rw-r--r-- | fs/ecryptfs/keystore.c | 47 |
2 files changed, 26 insertions, 22 deletions
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 340c657a108c..11f8582d7218 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -69,6 +69,7 @@ static int ecryptfs_inode_set(struct inode *inode, void *opaque) | |||
69 | inode->i_ino = lower_inode->i_ino; | 69 | inode->i_ino = lower_inode->i_ino; |
70 | inode->i_version++; | 70 | inode->i_version++; |
71 | inode->i_mapping->a_ops = &ecryptfs_aops; | 71 | inode->i_mapping->a_ops = &ecryptfs_aops; |
72 | inode->i_mapping->backing_dev_info = inode->i_sb->s_bdi; | ||
72 | 73 | ||
73 | if (S_ISLNK(inode->i_mode)) | 74 | if (S_ISLNK(inode->i_mode)) |
74 | inode->i_op = &ecryptfs_symlink_iops; | 75 | inode->i_op = &ecryptfs_symlink_iops; |
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. */ |
1872 | find_next_matching_auth_tok: | 1872 | find_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: | |||
1959 | out_wipe_list: | 1962 | out_wipe_list: |
1960 | wipe_auth_tok_list(&auth_tok_list); | 1963 | wipe_auth_tok_list(&auth_tok_list); |
1961 | out: | 1964 | out: |
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 | ||
1969 | static int | 1968 | static int |
1970 | pki_encrypt_session_key(struct ecryptfs_auth_tok *auth_tok, | 1969 | pki_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 | */ |
2022 | static int | 2026 | static int |
2023 | write_tag_1_packet(char *dest, size_t *remaining_bytes, | 2027 | write_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: | |||
2471 | out: | 2479 | out: |
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 | } |