Commit e77cc8d243f9f1e1d3f0799e23cc14e837ccc8c6
1 parent
13a791b4e6
Exists in
master
and in
7 other branches
eCryptfs: Remove ecryptfs_unlink_sigs warnings
A feature was added to the eCryptfs umount helper to automatically unlink the keys used for an eCryptfs mount from the kernel keyring upon umount. This patch keeps the unrecognized mount option warnings for ecryptfs_unlink_sigs out of the logs. Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Showing 3 changed files with 8 additions and 1 deletions Inline Diff
fs/ecryptfs/ecryptfs_kernel.h
1 | /** | 1 | /** |
2 | * eCryptfs: Linux filesystem encryption layer | 2 | * eCryptfs: Linux filesystem encryption layer |
3 | * Kernel declarations. | 3 | * Kernel declarations. |
4 | * | 4 | * |
5 | * Copyright (C) 1997-2003 Erez Zadok | 5 | * Copyright (C) 1997-2003 Erez Zadok |
6 | * Copyright (C) 2001-2003 Stony Brook University | 6 | * Copyright (C) 2001-2003 Stony Brook University |
7 | * Copyright (C) 2004-2008 International Business Machines Corp. | 7 | * Copyright (C) 2004-2008 International Business Machines Corp. |
8 | * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> | 8 | * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> |
9 | * Trevor S. Highland <trevor.highland@gmail.com> | 9 | * Trevor S. Highland <trevor.highland@gmail.com> |
10 | * Tyler Hicks <tyhicks@ou.edu> | 10 | * Tyler Hicks <tyhicks@ou.edu> |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or | 12 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU General Public License as | 13 | * modify it under the terms of the GNU General Public License as |
14 | * published by the Free Software Foundation; either version 2 of the | 14 | * published by the Free Software Foundation; either version 2 of the |
15 | * License, or (at your option) any later version. | 15 | * License, or (at your option) any later version. |
16 | * | 16 | * |
17 | * This program is distributed in the hope that it will be useful, but | 17 | * This program is distributed in the hope that it will be useful, but |
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | * General Public License for more details. | 20 | * General Public License for more details. |
21 | * | 21 | * |
22 | * You should have received a copy of the GNU General Public License | 22 | * You should have received a copy of the GNU General Public License |
23 | * along with this program; if not, write to the Free Software | 23 | * along with this program; if not, write to the Free Software |
24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
25 | * 02111-1307, USA. | 25 | * 02111-1307, USA. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef ECRYPTFS_KERNEL_H | 28 | #ifndef ECRYPTFS_KERNEL_H |
29 | #define ECRYPTFS_KERNEL_H | 29 | #define ECRYPTFS_KERNEL_H |
30 | 30 | ||
31 | #include <keys/user-type.h> | 31 | #include <keys/user-type.h> |
32 | #include <linux/fs.h> | 32 | #include <linux/fs.h> |
33 | #include <linux/fs_stack.h> | 33 | #include <linux/fs_stack.h> |
34 | #include <linux/namei.h> | 34 | #include <linux/namei.h> |
35 | #include <linux/scatterlist.h> | 35 | #include <linux/scatterlist.h> |
36 | #include <linux/hash.h> | 36 | #include <linux/hash.h> |
37 | #include <linux/nsproxy.h> | 37 | #include <linux/nsproxy.h> |
38 | 38 | ||
39 | /* Version verification for shared data structures w/ userspace */ | 39 | /* Version verification for shared data structures w/ userspace */ |
40 | #define ECRYPTFS_VERSION_MAJOR 0x00 | 40 | #define ECRYPTFS_VERSION_MAJOR 0x00 |
41 | #define ECRYPTFS_VERSION_MINOR 0x04 | 41 | #define ECRYPTFS_VERSION_MINOR 0x04 |
42 | #define ECRYPTFS_SUPPORTED_FILE_VERSION 0x03 | 42 | #define ECRYPTFS_SUPPORTED_FILE_VERSION 0x03 |
43 | /* These flags indicate which features are supported by the kernel | 43 | /* These flags indicate which features are supported by the kernel |
44 | * module; userspace tools such as the mount helper read | 44 | * module; userspace tools such as the mount helper read |
45 | * ECRYPTFS_VERSIONING_MASK from a sysfs handle in order to determine | 45 | * ECRYPTFS_VERSIONING_MASK from a sysfs handle in order to determine |
46 | * how to behave. */ | 46 | * how to behave. */ |
47 | #define ECRYPTFS_VERSIONING_PASSPHRASE 0x00000001 | 47 | #define ECRYPTFS_VERSIONING_PASSPHRASE 0x00000001 |
48 | #define ECRYPTFS_VERSIONING_PUBKEY 0x00000002 | 48 | #define ECRYPTFS_VERSIONING_PUBKEY 0x00000002 |
49 | #define ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH 0x00000004 | 49 | #define ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH 0x00000004 |
50 | #define ECRYPTFS_VERSIONING_POLICY 0x00000008 | 50 | #define ECRYPTFS_VERSIONING_POLICY 0x00000008 |
51 | #define ECRYPTFS_VERSIONING_XATTR 0x00000010 | 51 | #define ECRYPTFS_VERSIONING_XATTR 0x00000010 |
52 | #define ECRYPTFS_VERSIONING_MULTKEY 0x00000020 | 52 | #define ECRYPTFS_VERSIONING_MULTKEY 0x00000020 |
53 | #define ECRYPTFS_VERSIONING_DEVMISC 0x00000040 | 53 | #define ECRYPTFS_VERSIONING_DEVMISC 0x00000040 |
54 | #define ECRYPTFS_VERSIONING_HMAC 0x00000080 | 54 | #define ECRYPTFS_VERSIONING_HMAC 0x00000080 |
55 | #define ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION 0x00000100 | 55 | #define ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION 0x00000100 |
56 | #define ECRYPTFS_VERSIONING_GCM 0x00000200 | 56 | #define ECRYPTFS_VERSIONING_GCM 0x00000200 |
57 | #define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \ | 57 | #define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \ |
58 | | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \ | 58 | | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \ |
59 | | ECRYPTFS_VERSIONING_PUBKEY \ | 59 | | ECRYPTFS_VERSIONING_PUBKEY \ |
60 | | ECRYPTFS_VERSIONING_XATTR \ | 60 | | ECRYPTFS_VERSIONING_XATTR \ |
61 | | ECRYPTFS_VERSIONING_MULTKEY \ | 61 | | ECRYPTFS_VERSIONING_MULTKEY \ |
62 | | ECRYPTFS_VERSIONING_DEVMISC \ | 62 | | ECRYPTFS_VERSIONING_DEVMISC \ |
63 | | ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION) | 63 | | ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION) |
64 | #define ECRYPTFS_MAX_PASSWORD_LENGTH 64 | 64 | #define ECRYPTFS_MAX_PASSWORD_LENGTH 64 |
65 | #define ECRYPTFS_MAX_PASSPHRASE_BYTES ECRYPTFS_MAX_PASSWORD_LENGTH | 65 | #define ECRYPTFS_MAX_PASSPHRASE_BYTES ECRYPTFS_MAX_PASSWORD_LENGTH |
66 | #define ECRYPTFS_SALT_SIZE 8 | 66 | #define ECRYPTFS_SALT_SIZE 8 |
67 | #define ECRYPTFS_SALT_SIZE_HEX (ECRYPTFS_SALT_SIZE*2) | 67 | #define ECRYPTFS_SALT_SIZE_HEX (ECRYPTFS_SALT_SIZE*2) |
68 | /* The original signature size is only for what is stored on disk; all | 68 | /* The original signature size is only for what is stored on disk; all |
69 | * in-memory representations are expanded hex, so it better adapted to | 69 | * in-memory representations are expanded hex, so it better adapted to |
70 | * be passed around or referenced on the command line */ | 70 | * be passed around or referenced on the command line */ |
71 | #define ECRYPTFS_SIG_SIZE 8 | 71 | #define ECRYPTFS_SIG_SIZE 8 |
72 | #define ECRYPTFS_SIG_SIZE_HEX (ECRYPTFS_SIG_SIZE*2) | 72 | #define ECRYPTFS_SIG_SIZE_HEX (ECRYPTFS_SIG_SIZE*2) |
73 | #define ECRYPTFS_PASSWORD_SIG_SIZE ECRYPTFS_SIG_SIZE_HEX | 73 | #define ECRYPTFS_PASSWORD_SIG_SIZE ECRYPTFS_SIG_SIZE_HEX |
74 | #define ECRYPTFS_MAX_KEY_BYTES 64 | 74 | #define ECRYPTFS_MAX_KEY_BYTES 64 |
75 | #define ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES 512 | 75 | #define ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES 512 |
76 | #define ECRYPTFS_DEFAULT_IV_BYTES 16 | 76 | #define ECRYPTFS_DEFAULT_IV_BYTES 16 |
77 | #define ECRYPTFS_FILE_VERSION 0x03 | 77 | #define ECRYPTFS_FILE_VERSION 0x03 |
78 | #define ECRYPTFS_DEFAULT_EXTENT_SIZE 4096 | 78 | #define ECRYPTFS_DEFAULT_EXTENT_SIZE 4096 |
79 | #define ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE 8192 | 79 | #define ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE 8192 |
80 | #define ECRYPTFS_DEFAULT_MSG_CTX_ELEMS 32 | 80 | #define ECRYPTFS_DEFAULT_MSG_CTX_ELEMS 32 |
81 | #define ECRYPTFS_DEFAULT_SEND_TIMEOUT HZ | 81 | #define ECRYPTFS_DEFAULT_SEND_TIMEOUT HZ |
82 | #define ECRYPTFS_MAX_MSG_CTX_TTL (HZ*3) | 82 | #define ECRYPTFS_MAX_MSG_CTX_TTL (HZ*3) |
83 | #define ECRYPTFS_MAX_PKI_NAME_BYTES 16 | 83 | #define ECRYPTFS_MAX_PKI_NAME_BYTES 16 |
84 | #define ECRYPTFS_DEFAULT_NUM_USERS 4 | 84 | #define ECRYPTFS_DEFAULT_NUM_USERS 4 |
85 | #define ECRYPTFS_MAX_NUM_USERS 32768 | 85 | #define ECRYPTFS_MAX_NUM_USERS 32768 |
86 | #define ECRYPTFS_XATTR_NAME "user.ecryptfs" | 86 | #define ECRYPTFS_XATTR_NAME "user.ecryptfs" |
87 | 87 | ||
88 | #define RFC2440_CIPHER_DES3_EDE 0x02 | 88 | #define RFC2440_CIPHER_DES3_EDE 0x02 |
89 | #define RFC2440_CIPHER_CAST_5 0x03 | 89 | #define RFC2440_CIPHER_CAST_5 0x03 |
90 | #define RFC2440_CIPHER_BLOWFISH 0x04 | 90 | #define RFC2440_CIPHER_BLOWFISH 0x04 |
91 | #define RFC2440_CIPHER_AES_128 0x07 | 91 | #define RFC2440_CIPHER_AES_128 0x07 |
92 | #define RFC2440_CIPHER_AES_192 0x08 | 92 | #define RFC2440_CIPHER_AES_192 0x08 |
93 | #define RFC2440_CIPHER_AES_256 0x09 | 93 | #define RFC2440_CIPHER_AES_256 0x09 |
94 | #define RFC2440_CIPHER_TWOFISH 0x0a | 94 | #define RFC2440_CIPHER_TWOFISH 0x0a |
95 | #define RFC2440_CIPHER_CAST_6 0x0b | 95 | #define RFC2440_CIPHER_CAST_6 0x0b |
96 | 96 | ||
97 | #define RFC2440_CIPHER_RSA 0x01 | 97 | #define RFC2440_CIPHER_RSA 0x01 |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * For convenience, we may need to pass around the encrypted session | 100 | * For convenience, we may need to pass around the encrypted session |
101 | * key between kernel and userspace because the authentication token | 101 | * key between kernel and userspace because the authentication token |
102 | * may not be extractable. For example, the TPM may not release the | 102 | * may not be extractable. For example, the TPM may not release the |
103 | * private key, instead requiring the encrypted data and returning the | 103 | * private key, instead requiring the encrypted data and returning the |
104 | * decrypted data. | 104 | * decrypted data. |
105 | */ | 105 | */ |
106 | struct ecryptfs_session_key { | 106 | struct ecryptfs_session_key { |
107 | #define ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT 0x00000001 | 107 | #define ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT 0x00000001 |
108 | #define ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT 0x00000002 | 108 | #define ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT 0x00000002 |
109 | #define ECRYPTFS_CONTAINS_DECRYPTED_KEY 0x00000004 | 109 | #define ECRYPTFS_CONTAINS_DECRYPTED_KEY 0x00000004 |
110 | #define ECRYPTFS_CONTAINS_ENCRYPTED_KEY 0x00000008 | 110 | #define ECRYPTFS_CONTAINS_ENCRYPTED_KEY 0x00000008 |
111 | u32 flags; | 111 | u32 flags; |
112 | u32 encrypted_key_size; | 112 | u32 encrypted_key_size; |
113 | u32 decrypted_key_size; | 113 | u32 decrypted_key_size; |
114 | u8 encrypted_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES]; | 114 | u8 encrypted_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES]; |
115 | u8 decrypted_key[ECRYPTFS_MAX_KEY_BYTES]; | 115 | u8 decrypted_key[ECRYPTFS_MAX_KEY_BYTES]; |
116 | }; | 116 | }; |
117 | 117 | ||
118 | struct ecryptfs_password { | 118 | struct ecryptfs_password { |
119 | u32 password_bytes; | 119 | u32 password_bytes; |
120 | s32 hash_algo; | 120 | s32 hash_algo; |
121 | u32 hash_iterations; | 121 | u32 hash_iterations; |
122 | u32 session_key_encryption_key_bytes; | 122 | u32 session_key_encryption_key_bytes; |
123 | #define ECRYPTFS_PERSISTENT_PASSWORD 0x01 | 123 | #define ECRYPTFS_PERSISTENT_PASSWORD 0x01 |
124 | #define ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET 0x02 | 124 | #define ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET 0x02 |
125 | u32 flags; | 125 | u32 flags; |
126 | /* Iterated-hash concatenation of salt and passphrase */ | 126 | /* Iterated-hash concatenation of salt and passphrase */ |
127 | u8 session_key_encryption_key[ECRYPTFS_MAX_KEY_BYTES]; | 127 | u8 session_key_encryption_key[ECRYPTFS_MAX_KEY_BYTES]; |
128 | u8 signature[ECRYPTFS_PASSWORD_SIG_SIZE + 1]; | 128 | u8 signature[ECRYPTFS_PASSWORD_SIG_SIZE + 1]; |
129 | /* Always in expanded hex */ | 129 | /* Always in expanded hex */ |
130 | u8 salt[ECRYPTFS_SALT_SIZE]; | 130 | u8 salt[ECRYPTFS_SALT_SIZE]; |
131 | }; | 131 | }; |
132 | 132 | ||
133 | enum ecryptfs_token_types {ECRYPTFS_PASSWORD, ECRYPTFS_PRIVATE_KEY}; | 133 | enum ecryptfs_token_types {ECRYPTFS_PASSWORD, ECRYPTFS_PRIVATE_KEY}; |
134 | 134 | ||
135 | struct ecryptfs_private_key { | 135 | struct ecryptfs_private_key { |
136 | u32 key_size; | 136 | u32 key_size; |
137 | u32 data_len; | 137 | u32 data_len; |
138 | u8 signature[ECRYPTFS_PASSWORD_SIG_SIZE + 1]; | 138 | u8 signature[ECRYPTFS_PASSWORD_SIG_SIZE + 1]; |
139 | char pki_type[ECRYPTFS_MAX_PKI_NAME_BYTES + 1]; | 139 | char pki_type[ECRYPTFS_MAX_PKI_NAME_BYTES + 1]; |
140 | u8 data[]; | 140 | u8 data[]; |
141 | }; | 141 | }; |
142 | 142 | ||
143 | /* May be a password or a private key */ | 143 | /* May be a password or a private key */ |
144 | struct ecryptfs_auth_tok { | 144 | struct ecryptfs_auth_tok { |
145 | u16 version; /* 8-bit major and 8-bit minor */ | 145 | u16 version; /* 8-bit major and 8-bit minor */ |
146 | u16 token_type; | 146 | u16 token_type; |
147 | #define ECRYPTFS_ENCRYPT_ONLY 0x00000001 | 147 | #define ECRYPTFS_ENCRYPT_ONLY 0x00000001 |
148 | u32 flags; | 148 | u32 flags; |
149 | struct ecryptfs_session_key session_key; | 149 | struct ecryptfs_session_key session_key; |
150 | u8 reserved[32]; | 150 | u8 reserved[32]; |
151 | union { | 151 | union { |
152 | struct ecryptfs_password password; | 152 | struct ecryptfs_password password; |
153 | struct ecryptfs_private_key private_key; | 153 | struct ecryptfs_private_key private_key; |
154 | } token; | 154 | } token; |
155 | } __attribute__ ((packed)); | 155 | } __attribute__ ((packed)); |
156 | 156 | ||
157 | void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok); | 157 | void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok); |
158 | extern void ecryptfs_to_hex(char *dst, char *src, size_t src_size); | 158 | extern void ecryptfs_to_hex(char *dst, char *src, size_t src_size); |
159 | extern void ecryptfs_from_hex(char *dst, char *src, int dst_size); | 159 | extern void ecryptfs_from_hex(char *dst, char *src, int dst_size); |
160 | 160 | ||
161 | struct ecryptfs_key_record { | 161 | struct ecryptfs_key_record { |
162 | unsigned char type; | 162 | unsigned char type; |
163 | size_t enc_key_size; | 163 | size_t enc_key_size; |
164 | unsigned char sig[ECRYPTFS_SIG_SIZE]; | 164 | unsigned char sig[ECRYPTFS_SIG_SIZE]; |
165 | unsigned char enc_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES]; | 165 | unsigned char enc_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES]; |
166 | }; | 166 | }; |
167 | 167 | ||
168 | struct ecryptfs_auth_tok_list { | 168 | struct ecryptfs_auth_tok_list { |
169 | struct ecryptfs_auth_tok *auth_tok; | 169 | struct ecryptfs_auth_tok *auth_tok; |
170 | struct list_head list; | 170 | struct list_head list; |
171 | }; | 171 | }; |
172 | 172 | ||
173 | struct ecryptfs_crypt_stat; | 173 | struct ecryptfs_crypt_stat; |
174 | struct ecryptfs_mount_crypt_stat; | 174 | struct ecryptfs_mount_crypt_stat; |
175 | 175 | ||
176 | struct ecryptfs_page_crypt_context { | 176 | struct ecryptfs_page_crypt_context { |
177 | struct page *page; | 177 | struct page *page; |
178 | #define ECRYPTFS_PREPARE_COMMIT_MODE 0 | 178 | #define ECRYPTFS_PREPARE_COMMIT_MODE 0 |
179 | #define ECRYPTFS_WRITEPAGE_MODE 1 | 179 | #define ECRYPTFS_WRITEPAGE_MODE 1 |
180 | unsigned int mode; | 180 | unsigned int mode; |
181 | union { | 181 | union { |
182 | struct file *lower_file; | 182 | struct file *lower_file; |
183 | struct writeback_control *wbc; | 183 | struct writeback_control *wbc; |
184 | } param; | 184 | } param; |
185 | }; | 185 | }; |
186 | 186 | ||
187 | static inline struct ecryptfs_auth_tok * | 187 | static inline struct ecryptfs_auth_tok * |
188 | ecryptfs_get_key_payload_data(struct key *key) | 188 | ecryptfs_get_key_payload_data(struct key *key) |
189 | { | 189 | { |
190 | return (struct ecryptfs_auth_tok *) | 190 | return (struct ecryptfs_auth_tok *) |
191 | (((struct user_key_payload*)key->payload.data)->data); | 191 | (((struct user_key_payload*)key->payload.data)->data); |
192 | } | 192 | } |
193 | 193 | ||
194 | #define ECRYPTFS_SUPER_MAGIC 0xf15f | 194 | #define ECRYPTFS_SUPER_MAGIC 0xf15f |
195 | #define ECRYPTFS_MAX_KEYSET_SIZE 1024 | 195 | #define ECRYPTFS_MAX_KEYSET_SIZE 1024 |
196 | #define ECRYPTFS_MAX_CIPHER_NAME_SIZE 32 | 196 | #define ECRYPTFS_MAX_CIPHER_NAME_SIZE 32 |
197 | #define ECRYPTFS_MAX_NUM_ENC_KEYS 64 | 197 | #define ECRYPTFS_MAX_NUM_ENC_KEYS 64 |
198 | #define ECRYPTFS_MAX_IV_BYTES 16 /* 128 bits */ | 198 | #define ECRYPTFS_MAX_IV_BYTES 16 /* 128 bits */ |
199 | #define ECRYPTFS_SALT_BYTES 2 | 199 | #define ECRYPTFS_SALT_BYTES 2 |
200 | #define MAGIC_ECRYPTFS_MARKER 0x3c81b7f5 | 200 | #define MAGIC_ECRYPTFS_MARKER 0x3c81b7f5 |
201 | #define MAGIC_ECRYPTFS_MARKER_SIZE_BYTES 8 /* 4*2 */ | 201 | #define MAGIC_ECRYPTFS_MARKER_SIZE_BYTES 8 /* 4*2 */ |
202 | #define ECRYPTFS_FILE_SIZE_BYTES (sizeof(u64)) | 202 | #define ECRYPTFS_FILE_SIZE_BYTES (sizeof(u64)) |
203 | #define ECRYPTFS_DEFAULT_CIPHER "aes" | 203 | #define ECRYPTFS_DEFAULT_CIPHER "aes" |
204 | #define ECRYPTFS_DEFAULT_KEY_BYTES 16 | 204 | #define ECRYPTFS_DEFAULT_KEY_BYTES 16 |
205 | #define ECRYPTFS_DEFAULT_HASH "md5" | 205 | #define ECRYPTFS_DEFAULT_HASH "md5" |
206 | #define ECRYPTFS_TAG_70_DIGEST ECRYPTFS_DEFAULT_HASH | 206 | #define ECRYPTFS_TAG_70_DIGEST ECRYPTFS_DEFAULT_HASH |
207 | #define ECRYPTFS_TAG_1_PACKET_TYPE 0x01 | 207 | #define ECRYPTFS_TAG_1_PACKET_TYPE 0x01 |
208 | #define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C | 208 | #define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C |
209 | #define ECRYPTFS_TAG_11_PACKET_TYPE 0xED | 209 | #define ECRYPTFS_TAG_11_PACKET_TYPE 0xED |
210 | #define ECRYPTFS_TAG_64_PACKET_TYPE 0x40 | 210 | #define ECRYPTFS_TAG_64_PACKET_TYPE 0x40 |
211 | #define ECRYPTFS_TAG_65_PACKET_TYPE 0x41 | 211 | #define ECRYPTFS_TAG_65_PACKET_TYPE 0x41 |
212 | #define ECRYPTFS_TAG_66_PACKET_TYPE 0x42 | 212 | #define ECRYPTFS_TAG_66_PACKET_TYPE 0x42 |
213 | #define ECRYPTFS_TAG_67_PACKET_TYPE 0x43 | 213 | #define ECRYPTFS_TAG_67_PACKET_TYPE 0x43 |
214 | #define ECRYPTFS_TAG_70_PACKET_TYPE 0x46 /* FNEK-encrypted filename | 214 | #define ECRYPTFS_TAG_70_PACKET_TYPE 0x46 /* FNEK-encrypted filename |
215 | * as dentry name */ | 215 | * as dentry name */ |
216 | #define ECRYPTFS_TAG_71_PACKET_TYPE 0x47 /* FNEK-encrypted filename in | 216 | #define ECRYPTFS_TAG_71_PACKET_TYPE 0x47 /* FNEK-encrypted filename in |
217 | * metadata */ | 217 | * metadata */ |
218 | #define ECRYPTFS_TAG_72_PACKET_TYPE 0x48 /* FEK-encrypted filename as | 218 | #define ECRYPTFS_TAG_72_PACKET_TYPE 0x48 /* FEK-encrypted filename as |
219 | * dentry name */ | 219 | * dentry name */ |
220 | #define ECRYPTFS_TAG_73_PACKET_TYPE 0x49 /* FEK-encrypted filename as | 220 | #define ECRYPTFS_TAG_73_PACKET_TYPE 0x49 /* FEK-encrypted filename as |
221 | * metadata */ | 221 | * metadata */ |
222 | /* Constraint: ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES >= | 222 | /* Constraint: ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES >= |
223 | * ECRYPTFS_MAX_IV_BYTES */ | 223 | * ECRYPTFS_MAX_IV_BYTES */ |
224 | #define ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES 16 | 224 | #define ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES 16 |
225 | #define ECRYPTFS_NON_NULL 0x42 /* A reasonable substitute for NULL */ | 225 | #define ECRYPTFS_NON_NULL 0x42 /* A reasonable substitute for NULL */ |
226 | #define MD5_DIGEST_SIZE 16 | 226 | #define MD5_DIGEST_SIZE 16 |
227 | #define ECRYPTFS_TAG_70_DIGEST_SIZE MD5_DIGEST_SIZE | 227 | #define ECRYPTFS_TAG_70_DIGEST_SIZE MD5_DIGEST_SIZE |
228 | #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FEK_ENCRYPTED." | 228 | #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FEK_ENCRYPTED." |
229 | #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX_SIZE 23 | 229 | #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX_SIZE 23 |
230 | #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FNEK_ENCRYPTED." | 230 | #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FNEK_ENCRYPTED." |
231 | #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE 24 | 231 | #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE 24 |
232 | #define ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN (18 + 1 + 4 + 1 + 32) | 232 | #define ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN (18 + 1 + 4 + 1 + 32) |
233 | 233 | ||
234 | struct ecryptfs_key_sig { | 234 | struct ecryptfs_key_sig { |
235 | struct list_head crypt_stat_list; | 235 | struct list_head crypt_stat_list; |
236 | char keysig[ECRYPTFS_SIG_SIZE_HEX]; | 236 | char keysig[ECRYPTFS_SIG_SIZE_HEX]; |
237 | }; | 237 | }; |
238 | 238 | ||
239 | struct ecryptfs_filename { | 239 | struct ecryptfs_filename { |
240 | struct list_head crypt_stat_list; | 240 | struct list_head crypt_stat_list; |
241 | #define ECRYPTFS_FILENAME_CONTAINS_DECRYPTED 0x00000001 | 241 | #define ECRYPTFS_FILENAME_CONTAINS_DECRYPTED 0x00000001 |
242 | u32 flags; | 242 | u32 flags; |
243 | u32 seq_no; | 243 | u32 seq_no; |
244 | char *filename; | 244 | char *filename; |
245 | char *encrypted_filename; | 245 | char *encrypted_filename; |
246 | size_t filename_size; | 246 | size_t filename_size; |
247 | size_t encrypted_filename_size; | 247 | size_t encrypted_filename_size; |
248 | char fnek_sig[ECRYPTFS_SIG_SIZE_HEX]; | 248 | char fnek_sig[ECRYPTFS_SIG_SIZE_HEX]; |
249 | char dentry_name[ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN + 1]; | 249 | char dentry_name[ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN + 1]; |
250 | }; | 250 | }; |
251 | 251 | ||
252 | /** | 252 | /** |
253 | * This is the primary struct associated with each encrypted file. | 253 | * This is the primary struct associated with each encrypted file. |
254 | * | 254 | * |
255 | * TODO: cache align/pack? | 255 | * TODO: cache align/pack? |
256 | */ | 256 | */ |
257 | struct ecryptfs_crypt_stat { | 257 | struct ecryptfs_crypt_stat { |
258 | #define ECRYPTFS_STRUCT_INITIALIZED 0x00000001 | 258 | #define ECRYPTFS_STRUCT_INITIALIZED 0x00000001 |
259 | #define ECRYPTFS_POLICY_APPLIED 0x00000002 | 259 | #define ECRYPTFS_POLICY_APPLIED 0x00000002 |
260 | #define ECRYPTFS_NEW_FILE 0x00000004 | 260 | #define ECRYPTFS_NEW_FILE 0x00000004 |
261 | #define ECRYPTFS_ENCRYPTED 0x00000008 | 261 | #define ECRYPTFS_ENCRYPTED 0x00000008 |
262 | #define ECRYPTFS_SECURITY_WARNING 0x00000010 | 262 | #define ECRYPTFS_SECURITY_WARNING 0x00000010 |
263 | #define ECRYPTFS_ENABLE_HMAC 0x00000020 | 263 | #define ECRYPTFS_ENABLE_HMAC 0x00000020 |
264 | #define ECRYPTFS_ENCRYPT_IV_PAGES 0x00000040 | 264 | #define ECRYPTFS_ENCRYPT_IV_PAGES 0x00000040 |
265 | #define ECRYPTFS_KEY_VALID 0x00000080 | 265 | #define ECRYPTFS_KEY_VALID 0x00000080 |
266 | #define ECRYPTFS_METADATA_IN_XATTR 0x00000100 | 266 | #define ECRYPTFS_METADATA_IN_XATTR 0x00000100 |
267 | #define ECRYPTFS_VIEW_AS_ENCRYPTED 0x00000200 | 267 | #define ECRYPTFS_VIEW_AS_ENCRYPTED 0x00000200 |
268 | #define ECRYPTFS_KEY_SET 0x00000400 | 268 | #define ECRYPTFS_KEY_SET 0x00000400 |
269 | #define ECRYPTFS_ENCRYPT_FILENAMES 0x00000800 | 269 | #define ECRYPTFS_ENCRYPT_FILENAMES 0x00000800 |
270 | #define ECRYPTFS_ENCFN_USE_MOUNT_FNEK 0x00001000 | 270 | #define ECRYPTFS_ENCFN_USE_MOUNT_FNEK 0x00001000 |
271 | #define ECRYPTFS_ENCFN_USE_FEK 0x00002000 | 271 | #define ECRYPTFS_ENCFN_USE_FEK 0x00002000 |
272 | #define ECRYPTFS_UNLINK_SIGS 0x00004000 | ||
272 | u32 flags; | 273 | u32 flags; |
273 | unsigned int file_version; | 274 | unsigned int file_version; |
274 | size_t iv_bytes; | 275 | size_t iv_bytes; |
275 | size_t num_header_bytes_at_front; | 276 | size_t num_header_bytes_at_front; |
276 | size_t extent_size; /* Data extent size; default is 4096 */ | 277 | size_t extent_size; /* Data extent size; default is 4096 */ |
277 | size_t key_size; | 278 | size_t key_size; |
278 | size_t extent_shift; | 279 | size_t extent_shift; |
279 | unsigned int extent_mask; | 280 | unsigned int extent_mask; |
280 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat; | 281 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat; |
281 | struct crypto_blkcipher *tfm; | 282 | struct crypto_blkcipher *tfm; |
282 | struct crypto_hash *hash_tfm; /* Crypto context for generating | 283 | struct crypto_hash *hash_tfm; /* Crypto context for generating |
283 | * the initialization vectors */ | 284 | * the initialization vectors */ |
284 | unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE]; | 285 | unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE]; |
285 | unsigned char key[ECRYPTFS_MAX_KEY_BYTES]; | 286 | unsigned char key[ECRYPTFS_MAX_KEY_BYTES]; |
286 | unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES]; | 287 | unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES]; |
287 | struct list_head keysig_list; | 288 | struct list_head keysig_list; |
288 | struct mutex keysig_list_mutex; | 289 | struct mutex keysig_list_mutex; |
289 | struct mutex cs_tfm_mutex; | 290 | struct mutex cs_tfm_mutex; |
290 | struct mutex cs_hash_tfm_mutex; | 291 | struct mutex cs_hash_tfm_mutex; |
291 | struct mutex cs_mutex; | 292 | struct mutex cs_mutex; |
292 | }; | 293 | }; |
293 | 294 | ||
294 | /* inode private data. */ | 295 | /* inode private data. */ |
295 | struct ecryptfs_inode_info { | 296 | struct ecryptfs_inode_info { |
296 | struct inode vfs_inode; | 297 | struct inode vfs_inode; |
297 | struct inode *wii_inode; | 298 | struct inode *wii_inode; |
298 | struct file *lower_file; | 299 | struct file *lower_file; |
299 | struct mutex lower_file_mutex; | 300 | struct mutex lower_file_mutex; |
300 | struct ecryptfs_crypt_stat crypt_stat; | 301 | struct ecryptfs_crypt_stat crypt_stat; |
301 | }; | 302 | }; |
302 | 303 | ||
303 | /* dentry private data. Each dentry must keep track of a lower | 304 | /* dentry private data. Each dentry must keep track of a lower |
304 | * vfsmount too. */ | 305 | * vfsmount too. */ |
305 | struct ecryptfs_dentry_info { | 306 | struct ecryptfs_dentry_info { |
306 | struct path lower_path; | 307 | struct path lower_path; |
307 | struct ecryptfs_crypt_stat *crypt_stat; | 308 | struct ecryptfs_crypt_stat *crypt_stat; |
308 | }; | 309 | }; |
309 | 310 | ||
310 | /** | 311 | /** |
311 | * ecryptfs_global_auth_tok - A key used to encrypt all new files under the mountpoint | 312 | * ecryptfs_global_auth_tok - A key used to encrypt all new files under the mountpoint |
312 | * @flags: Status flags | 313 | * @flags: Status flags |
313 | * @mount_crypt_stat_list: These auth_toks hang off the mount-wide | 314 | * @mount_crypt_stat_list: These auth_toks hang off the mount-wide |
314 | * cryptographic context. Every time a new | 315 | * cryptographic context. Every time a new |
315 | * inode comes into existence, eCryptfs copies | 316 | * inode comes into existence, eCryptfs copies |
316 | * the auth_toks on that list to the set of | 317 | * the auth_toks on that list to the set of |
317 | * auth_toks on the inode's crypt_stat | 318 | * auth_toks on the inode's crypt_stat |
318 | * @global_auth_tok_key: The key from the user's keyring for the sig | 319 | * @global_auth_tok_key: The key from the user's keyring for the sig |
319 | * @global_auth_tok: The key contents | 320 | * @global_auth_tok: The key contents |
320 | * @sig: The key identifier | 321 | * @sig: The key identifier |
321 | * | 322 | * |
322 | * ecryptfs_global_auth_tok structs refer to authentication token keys | 323 | * ecryptfs_global_auth_tok structs refer to authentication token keys |
323 | * in the user keyring that apply to newly created files. A list of | 324 | * in the user keyring that apply to newly created files. A list of |
324 | * these objects hangs off of the mount_crypt_stat struct for any | 325 | * these objects hangs off of the mount_crypt_stat struct for any |
325 | * given eCryptfs mount. This struct maintains a reference to both the | 326 | * given eCryptfs mount. This struct maintains a reference to both the |
326 | * key contents and the key itself so that the key can be put on | 327 | * key contents and the key itself so that the key can be put on |
327 | * unmount. | 328 | * unmount. |
328 | */ | 329 | */ |
329 | struct ecryptfs_global_auth_tok { | 330 | struct ecryptfs_global_auth_tok { |
330 | #define ECRYPTFS_AUTH_TOK_INVALID 0x00000001 | 331 | #define ECRYPTFS_AUTH_TOK_INVALID 0x00000001 |
331 | #define ECRYPTFS_AUTH_TOK_FNEK 0x00000002 | 332 | #define ECRYPTFS_AUTH_TOK_FNEK 0x00000002 |
332 | u32 flags; | 333 | u32 flags; |
333 | struct list_head mount_crypt_stat_list; | 334 | struct list_head mount_crypt_stat_list; |
334 | struct key *global_auth_tok_key; | 335 | struct key *global_auth_tok_key; |
335 | struct ecryptfs_auth_tok *global_auth_tok; | 336 | struct ecryptfs_auth_tok *global_auth_tok; |
336 | unsigned char sig[ECRYPTFS_SIG_SIZE_HEX + 1]; | 337 | unsigned char sig[ECRYPTFS_SIG_SIZE_HEX + 1]; |
337 | }; | 338 | }; |
338 | 339 | ||
339 | /** | 340 | /** |
340 | * ecryptfs_key_tfm - Persistent key tfm | 341 | * ecryptfs_key_tfm - Persistent key tfm |
341 | * @key_tfm: crypto API handle to the key | 342 | * @key_tfm: crypto API handle to the key |
342 | * @key_size: Key size in bytes | 343 | * @key_size: Key size in bytes |
343 | * @key_tfm_mutex: Mutex to ensure only one operation in eCryptfs is | 344 | * @key_tfm_mutex: Mutex to ensure only one operation in eCryptfs is |
344 | * using the persistent TFM at any point in time | 345 | * using the persistent TFM at any point in time |
345 | * @key_tfm_list: Handle to hang this off the module-wide TFM list | 346 | * @key_tfm_list: Handle to hang this off the module-wide TFM list |
346 | * @cipher_name: String name for the cipher for this TFM | 347 | * @cipher_name: String name for the cipher for this TFM |
347 | * | 348 | * |
348 | * Typically, eCryptfs will use the same ciphers repeatedly throughout | 349 | * Typically, eCryptfs will use the same ciphers repeatedly throughout |
349 | * the course of its operations. In order to avoid unnecessarily | 350 | * the course of its operations. In order to avoid unnecessarily |
350 | * destroying and initializing the same cipher repeatedly, eCryptfs | 351 | * destroying and initializing the same cipher repeatedly, eCryptfs |
351 | * keeps a list of crypto API contexts around to use when needed. | 352 | * keeps a list of crypto API contexts around to use when needed. |
352 | */ | 353 | */ |
353 | struct ecryptfs_key_tfm { | 354 | struct ecryptfs_key_tfm { |
354 | struct crypto_blkcipher *key_tfm; | 355 | struct crypto_blkcipher *key_tfm; |
355 | size_t key_size; | 356 | size_t key_size; |
356 | struct mutex key_tfm_mutex; | 357 | struct mutex key_tfm_mutex; |
357 | struct list_head key_tfm_list; | 358 | struct list_head key_tfm_list; |
358 | unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1]; | 359 | unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1]; |
359 | }; | 360 | }; |
360 | 361 | ||
361 | extern struct mutex key_tfm_list_mutex; | 362 | extern struct mutex key_tfm_list_mutex; |
362 | 363 | ||
363 | /** | 364 | /** |
364 | * This struct is to enable a mount-wide passphrase/salt combo. This | 365 | * This struct is to enable a mount-wide passphrase/salt combo. This |
365 | * is more or less a stopgap to provide similar functionality to other | 366 | * is more or less a stopgap to provide similar functionality to other |
366 | * crypto filesystems like EncFS or CFS until full policy support is | 367 | * crypto filesystems like EncFS or CFS until full policy support is |
367 | * implemented in eCryptfs. | 368 | * implemented in eCryptfs. |
368 | */ | 369 | */ |
369 | struct ecryptfs_mount_crypt_stat { | 370 | struct ecryptfs_mount_crypt_stat { |
370 | /* Pointers to memory we do not own, do not free these */ | 371 | /* Pointers to memory we do not own, do not free these */ |
371 | #define ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED 0x00000001 | 372 | #define ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED 0x00000001 |
372 | #define ECRYPTFS_XATTR_METADATA_ENABLED 0x00000002 | 373 | #define ECRYPTFS_XATTR_METADATA_ENABLED 0x00000002 |
373 | #define ECRYPTFS_ENCRYPTED_VIEW_ENABLED 0x00000004 | 374 | #define ECRYPTFS_ENCRYPTED_VIEW_ENABLED 0x00000004 |
374 | #define ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED 0x00000008 | 375 | #define ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED 0x00000008 |
375 | #define ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES 0x00000010 | 376 | #define ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES 0x00000010 |
376 | #define ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK 0x00000020 | 377 | #define ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK 0x00000020 |
377 | #define ECRYPTFS_GLOBAL_ENCFN_USE_FEK 0x00000040 | 378 | #define ECRYPTFS_GLOBAL_ENCFN_USE_FEK 0x00000040 |
378 | u32 flags; | 379 | u32 flags; |
379 | struct list_head global_auth_tok_list; | 380 | struct list_head global_auth_tok_list; |
380 | struct mutex global_auth_tok_list_mutex; | 381 | struct mutex global_auth_tok_list_mutex; |
381 | size_t num_global_auth_toks; | 382 | size_t num_global_auth_toks; |
382 | size_t global_default_cipher_key_size; | 383 | size_t global_default_cipher_key_size; |
383 | size_t global_default_fn_cipher_key_bytes; | 384 | size_t global_default_fn_cipher_key_bytes; |
384 | unsigned char global_default_cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE | 385 | unsigned char global_default_cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE |
385 | + 1]; | 386 | + 1]; |
386 | unsigned char global_default_fn_cipher_name[ | 387 | unsigned char global_default_fn_cipher_name[ |
387 | ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1]; | 388 | ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1]; |
388 | char global_default_fnek_sig[ECRYPTFS_SIG_SIZE_HEX + 1]; | 389 | char global_default_fnek_sig[ECRYPTFS_SIG_SIZE_HEX + 1]; |
389 | }; | 390 | }; |
390 | 391 | ||
391 | /* superblock private data. */ | 392 | /* superblock private data. */ |
392 | struct ecryptfs_sb_info { | 393 | struct ecryptfs_sb_info { |
393 | struct super_block *wsi_sb; | 394 | struct super_block *wsi_sb; |
394 | struct ecryptfs_mount_crypt_stat mount_crypt_stat; | 395 | struct ecryptfs_mount_crypt_stat mount_crypt_stat; |
395 | }; | 396 | }; |
396 | 397 | ||
397 | /* file private data. */ | 398 | /* file private data. */ |
398 | struct ecryptfs_file_info { | 399 | struct ecryptfs_file_info { |
399 | struct file *wfi_file; | 400 | struct file *wfi_file; |
400 | struct ecryptfs_crypt_stat *crypt_stat; | 401 | struct ecryptfs_crypt_stat *crypt_stat; |
401 | }; | 402 | }; |
402 | 403 | ||
403 | /* auth_tok <=> encrypted_session_key mappings */ | 404 | /* auth_tok <=> encrypted_session_key mappings */ |
404 | struct ecryptfs_auth_tok_list_item { | 405 | struct ecryptfs_auth_tok_list_item { |
405 | unsigned char encrypted_session_key[ECRYPTFS_MAX_KEY_BYTES]; | 406 | unsigned char encrypted_session_key[ECRYPTFS_MAX_KEY_BYTES]; |
406 | struct list_head list; | 407 | struct list_head list; |
407 | struct ecryptfs_auth_tok auth_tok; | 408 | struct ecryptfs_auth_tok auth_tok; |
408 | }; | 409 | }; |
409 | 410 | ||
410 | struct ecryptfs_message { | 411 | struct ecryptfs_message { |
411 | /* Can never be greater than ecryptfs_message_buf_len */ | 412 | /* Can never be greater than ecryptfs_message_buf_len */ |
412 | /* Used to find the parent msg_ctx */ | 413 | /* Used to find the parent msg_ctx */ |
413 | /* Inherits from msg_ctx->index */ | 414 | /* Inherits from msg_ctx->index */ |
414 | u32 index; | 415 | u32 index; |
415 | u32 data_len; | 416 | u32 data_len; |
416 | u8 data[]; | 417 | u8 data[]; |
417 | }; | 418 | }; |
418 | 419 | ||
419 | struct ecryptfs_msg_ctx { | 420 | struct ecryptfs_msg_ctx { |
420 | #define ECRYPTFS_MSG_CTX_STATE_FREE 0x01 | 421 | #define ECRYPTFS_MSG_CTX_STATE_FREE 0x01 |
421 | #define ECRYPTFS_MSG_CTX_STATE_PENDING 0x02 | 422 | #define ECRYPTFS_MSG_CTX_STATE_PENDING 0x02 |
422 | #define ECRYPTFS_MSG_CTX_STATE_DONE 0x03 | 423 | #define ECRYPTFS_MSG_CTX_STATE_DONE 0x03 |
423 | #define ECRYPTFS_MSG_CTX_STATE_NO_REPLY 0x04 | 424 | #define ECRYPTFS_MSG_CTX_STATE_NO_REPLY 0x04 |
424 | u8 state; | 425 | u8 state; |
425 | #define ECRYPTFS_MSG_HELO 100 | 426 | #define ECRYPTFS_MSG_HELO 100 |
426 | #define ECRYPTFS_MSG_QUIT 101 | 427 | #define ECRYPTFS_MSG_QUIT 101 |
427 | #define ECRYPTFS_MSG_REQUEST 102 | 428 | #define ECRYPTFS_MSG_REQUEST 102 |
428 | #define ECRYPTFS_MSG_RESPONSE 103 | 429 | #define ECRYPTFS_MSG_RESPONSE 103 |
429 | u8 type; | 430 | u8 type; |
430 | u32 index; | 431 | u32 index; |
431 | /* Counter converts to a sequence number. Each message sent | 432 | /* Counter converts to a sequence number. Each message sent |
432 | * out for which we expect a response has an associated | 433 | * out for which we expect a response has an associated |
433 | * sequence number. The response must have the same sequence | 434 | * sequence number. The response must have the same sequence |
434 | * number as the counter for the msg_stc for the message to be | 435 | * number as the counter for the msg_stc for the message to be |
435 | * valid. */ | 436 | * valid. */ |
436 | u32 counter; | 437 | u32 counter; |
437 | size_t msg_size; | 438 | size_t msg_size; |
438 | struct ecryptfs_message *msg; | 439 | struct ecryptfs_message *msg; |
439 | struct task_struct *task; | 440 | struct task_struct *task; |
440 | struct list_head node; | 441 | struct list_head node; |
441 | struct list_head daemon_out_list; | 442 | struct list_head daemon_out_list; |
442 | struct mutex mux; | 443 | struct mutex mux; |
443 | }; | 444 | }; |
444 | 445 | ||
445 | struct ecryptfs_daemon; | 446 | struct ecryptfs_daemon; |
446 | 447 | ||
447 | struct ecryptfs_daemon { | 448 | struct ecryptfs_daemon { |
448 | #define ECRYPTFS_DAEMON_IN_READ 0x00000001 | 449 | #define ECRYPTFS_DAEMON_IN_READ 0x00000001 |
449 | #define ECRYPTFS_DAEMON_IN_POLL 0x00000002 | 450 | #define ECRYPTFS_DAEMON_IN_POLL 0x00000002 |
450 | #define ECRYPTFS_DAEMON_ZOMBIE 0x00000004 | 451 | #define ECRYPTFS_DAEMON_ZOMBIE 0x00000004 |
451 | #define ECRYPTFS_DAEMON_MISCDEV_OPEN 0x00000008 | 452 | #define ECRYPTFS_DAEMON_MISCDEV_OPEN 0x00000008 |
452 | u32 flags; | 453 | u32 flags; |
453 | u32 num_queued_msg_ctx; | 454 | u32 num_queued_msg_ctx; |
454 | struct pid *pid; | 455 | struct pid *pid; |
455 | uid_t euid; | 456 | uid_t euid; |
456 | struct user_namespace *user_ns; | 457 | struct user_namespace *user_ns; |
457 | struct task_struct *task; | 458 | struct task_struct *task; |
458 | struct mutex mux; | 459 | struct mutex mux; |
459 | struct list_head msg_ctx_out_queue; | 460 | struct list_head msg_ctx_out_queue; |
460 | wait_queue_head_t wait; | 461 | wait_queue_head_t wait; |
461 | struct hlist_node euid_chain; | 462 | struct hlist_node euid_chain; |
462 | }; | 463 | }; |
463 | 464 | ||
464 | extern struct mutex ecryptfs_daemon_hash_mux; | 465 | extern struct mutex ecryptfs_daemon_hash_mux; |
465 | 466 | ||
466 | static inline struct ecryptfs_file_info * | 467 | static inline struct ecryptfs_file_info * |
467 | ecryptfs_file_to_private(struct file *file) | 468 | ecryptfs_file_to_private(struct file *file) |
468 | { | 469 | { |
469 | return (struct ecryptfs_file_info *)file->private_data; | 470 | return (struct ecryptfs_file_info *)file->private_data; |
470 | } | 471 | } |
471 | 472 | ||
472 | static inline void | 473 | static inline void |
473 | ecryptfs_set_file_private(struct file *file, | 474 | ecryptfs_set_file_private(struct file *file, |
474 | struct ecryptfs_file_info *file_info) | 475 | struct ecryptfs_file_info *file_info) |
475 | { | 476 | { |
476 | file->private_data = file_info; | 477 | file->private_data = file_info; |
477 | } | 478 | } |
478 | 479 | ||
479 | static inline struct file *ecryptfs_file_to_lower(struct file *file) | 480 | static inline struct file *ecryptfs_file_to_lower(struct file *file) |
480 | { | 481 | { |
481 | return ((struct ecryptfs_file_info *)file->private_data)->wfi_file; | 482 | return ((struct ecryptfs_file_info *)file->private_data)->wfi_file; |
482 | } | 483 | } |
483 | 484 | ||
484 | static inline void | 485 | static inline void |
485 | ecryptfs_set_file_lower(struct file *file, struct file *lower_file) | 486 | ecryptfs_set_file_lower(struct file *file, struct file *lower_file) |
486 | { | 487 | { |
487 | ((struct ecryptfs_file_info *)file->private_data)->wfi_file = | 488 | ((struct ecryptfs_file_info *)file->private_data)->wfi_file = |
488 | lower_file; | 489 | lower_file; |
489 | } | 490 | } |
490 | 491 | ||
491 | static inline struct ecryptfs_inode_info * | 492 | static inline struct ecryptfs_inode_info * |
492 | ecryptfs_inode_to_private(struct inode *inode) | 493 | ecryptfs_inode_to_private(struct inode *inode) |
493 | { | 494 | { |
494 | return container_of(inode, struct ecryptfs_inode_info, vfs_inode); | 495 | return container_of(inode, struct ecryptfs_inode_info, vfs_inode); |
495 | } | 496 | } |
496 | 497 | ||
497 | static inline struct inode *ecryptfs_inode_to_lower(struct inode *inode) | 498 | static inline struct inode *ecryptfs_inode_to_lower(struct inode *inode) |
498 | { | 499 | { |
499 | return ecryptfs_inode_to_private(inode)->wii_inode; | 500 | return ecryptfs_inode_to_private(inode)->wii_inode; |
500 | } | 501 | } |
501 | 502 | ||
502 | static inline void | 503 | static inline void |
503 | ecryptfs_set_inode_lower(struct inode *inode, struct inode *lower_inode) | 504 | ecryptfs_set_inode_lower(struct inode *inode, struct inode *lower_inode) |
504 | { | 505 | { |
505 | ecryptfs_inode_to_private(inode)->wii_inode = lower_inode; | 506 | ecryptfs_inode_to_private(inode)->wii_inode = lower_inode; |
506 | } | 507 | } |
507 | 508 | ||
508 | static inline struct ecryptfs_sb_info * | 509 | static inline struct ecryptfs_sb_info * |
509 | ecryptfs_superblock_to_private(struct super_block *sb) | 510 | ecryptfs_superblock_to_private(struct super_block *sb) |
510 | { | 511 | { |
511 | return (struct ecryptfs_sb_info *)sb->s_fs_info; | 512 | return (struct ecryptfs_sb_info *)sb->s_fs_info; |
512 | } | 513 | } |
513 | 514 | ||
514 | static inline void | 515 | static inline void |
515 | ecryptfs_set_superblock_private(struct super_block *sb, | 516 | ecryptfs_set_superblock_private(struct super_block *sb, |
516 | struct ecryptfs_sb_info *sb_info) | 517 | struct ecryptfs_sb_info *sb_info) |
517 | { | 518 | { |
518 | sb->s_fs_info = sb_info; | 519 | sb->s_fs_info = sb_info; |
519 | } | 520 | } |
520 | 521 | ||
521 | static inline struct super_block * | 522 | static inline struct super_block * |
522 | ecryptfs_superblock_to_lower(struct super_block *sb) | 523 | ecryptfs_superblock_to_lower(struct super_block *sb) |
523 | { | 524 | { |
524 | return ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb; | 525 | return ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb; |
525 | } | 526 | } |
526 | 527 | ||
527 | static inline void | 528 | static inline void |
528 | ecryptfs_set_superblock_lower(struct super_block *sb, | 529 | ecryptfs_set_superblock_lower(struct super_block *sb, |
529 | struct super_block *lower_sb) | 530 | struct super_block *lower_sb) |
530 | { | 531 | { |
531 | ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb = lower_sb; | 532 | ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb = lower_sb; |
532 | } | 533 | } |
533 | 534 | ||
534 | static inline struct ecryptfs_dentry_info * | 535 | static inline struct ecryptfs_dentry_info * |
535 | ecryptfs_dentry_to_private(struct dentry *dentry) | 536 | ecryptfs_dentry_to_private(struct dentry *dentry) |
536 | { | 537 | { |
537 | return (struct ecryptfs_dentry_info *)dentry->d_fsdata; | 538 | return (struct ecryptfs_dentry_info *)dentry->d_fsdata; |
538 | } | 539 | } |
539 | 540 | ||
540 | static inline void | 541 | static inline void |
541 | ecryptfs_set_dentry_private(struct dentry *dentry, | 542 | ecryptfs_set_dentry_private(struct dentry *dentry, |
542 | struct ecryptfs_dentry_info *dentry_info) | 543 | struct ecryptfs_dentry_info *dentry_info) |
543 | { | 544 | { |
544 | dentry->d_fsdata = dentry_info; | 545 | dentry->d_fsdata = dentry_info; |
545 | } | 546 | } |
546 | 547 | ||
547 | static inline struct dentry * | 548 | static inline struct dentry * |
548 | ecryptfs_dentry_to_lower(struct dentry *dentry) | 549 | ecryptfs_dentry_to_lower(struct dentry *dentry) |
549 | { | 550 | { |
550 | return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry; | 551 | return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry; |
551 | } | 552 | } |
552 | 553 | ||
553 | static inline void | 554 | static inline void |
554 | ecryptfs_set_dentry_lower(struct dentry *dentry, struct dentry *lower_dentry) | 555 | ecryptfs_set_dentry_lower(struct dentry *dentry, struct dentry *lower_dentry) |
555 | { | 556 | { |
556 | ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry = | 557 | ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry = |
557 | lower_dentry; | 558 | lower_dentry; |
558 | } | 559 | } |
559 | 560 | ||
560 | static inline struct vfsmount * | 561 | static inline struct vfsmount * |
561 | ecryptfs_dentry_to_lower_mnt(struct dentry *dentry) | 562 | ecryptfs_dentry_to_lower_mnt(struct dentry *dentry) |
562 | { | 563 | { |
563 | return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt; | 564 | return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt; |
564 | } | 565 | } |
565 | 566 | ||
566 | static inline void | 567 | static inline void |
567 | ecryptfs_set_dentry_lower_mnt(struct dentry *dentry, struct vfsmount *lower_mnt) | 568 | ecryptfs_set_dentry_lower_mnt(struct dentry *dentry, struct vfsmount *lower_mnt) |
568 | { | 569 | { |
569 | ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt = | 570 | ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt = |
570 | lower_mnt; | 571 | lower_mnt; |
571 | } | 572 | } |
572 | 573 | ||
573 | #define ecryptfs_printk(type, fmt, arg...) \ | 574 | #define ecryptfs_printk(type, fmt, arg...) \ |
574 | __ecryptfs_printk(type "%s: " fmt, __func__, ## arg); | 575 | __ecryptfs_printk(type "%s: " fmt, __func__, ## arg); |
575 | void __ecryptfs_printk(const char *fmt, ...); | 576 | void __ecryptfs_printk(const char *fmt, ...); |
576 | 577 | ||
577 | extern const struct file_operations ecryptfs_main_fops; | 578 | extern const struct file_operations ecryptfs_main_fops; |
578 | extern const struct file_operations ecryptfs_dir_fops; | 579 | extern const struct file_operations ecryptfs_dir_fops; |
579 | extern const struct inode_operations ecryptfs_main_iops; | 580 | extern const struct inode_operations ecryptfs_main_iops; |
580 | extern const struct inode_operations ecryptfs_dir_iops; | 581 | extern const struct inode_operations ecryptfs_dir_iops; |
581 | extern const struct inode_operations ecryptfs_symlink_iops; | 582 | extern const struct inode_operations ecryptfs_symlink_iops; |
582 | extern const struct super_operations ecryptfs_sops; | 583 | extern const struct super_operations ecryptfs_sops; |
583 | extern const struct dentry_operations ecryptfs_dops; | 584 | extern const struct dentry_operations ecryptfs_dops; |
584 | extern struct address_space_operations ecryptfs_aops; | 585 | extern struct address_space_operations ecryptfs_aops; |
585 | extern int ecryptfs_verbosity; | 586 | extern int ecryptfs_verbosity; |
586 | extern unsigned int ecryptfs_message_buf_len; | 587 | extern unsigned int ecryptfs_message_buf_len; |
587 | extern signed long ecryptfs_message_wait_timeout; | 588 | extern signed long ecryptfs_message_wait_timeout; |
588 | extern unsigned int ecryptfs_number_of_users; | 589 | extern unsigned int ecryptfs_number_of_users; |
589 | 590 | ||
590 | extern struct kmem_cache *ecryptfs_auth_tok_list_item_cache; | 591 | extern struct kmem_cache *ecryptfs_auth_tok_list_item_cache; |
591 | extern struct kmem_cache *ecryptfs_file_info_cache; | 592 | extern struct kmem_cache *ecryptfs_file_info_cache; |
592 | extern struct kmem_cache *ecryptfs_dentry_info_cache; | 593 | extern struct kmem_cache *ecryptfs_dentry_info_cache; |
593 | extern struct kmem_cache *ecryptfs_inode_info_cache; | 594 | extern struct kmem_cache *ecryptfs_inode_info_cache; |
594 | extern struct kmem_cache *ecryptfs_sb_info_cache; | 595 | extern struct kmem_cache *ecryptfs_sb_info_cache; |
595 | extern struct kmem_cache *ecryptfs_header_cache_1; | 596 | extern struct kmem_cache *ecryptfs_header_cache_1; |
596 | extern struct kmem_cache *ecryptfs_header_cache_2; | 597 | extern struct kmem_cache *ecryptfs_header_cache_2; |
597 | extern struct kmem_cache *ecryptfs_xattr_cache; | 598 | extern struct kmem_cache *ecryptfs_xattr_cache; |
598 | extern struct kmem_cache *ecryptfs_key_record_cache; | 599 | extern struct kmem_cache *ecryptfs_key_record_cache; |
599 | extern struct kmem_cache *ecryptfs_key_sig_cache; | 600 | extern struct kmem_cache *ecryptfs_key_sig_cache; |
600 | extern struct kmem_cache *ecryptfs_global_auth_tok_cache; | 601 | extern struct kmem_cache *ecryptfs_global_auth_tok_cache; |
601 | extern struct kmem_cache *ecryptfs_key_tfm_cache; | 602 | extern struct kmem_cache *ecryptfs_key_tfm_cache; |
602 | extern struct kmem_cache *ecryptfs_open_req_cache; | 603 | extern struct kmem_cache *ecryptfs_open_req_cache; |
603 | 604 | ||
604 | struct ecryptfs_open_req { | 605 | struct ecryptfs_open_req { |
605 | #define ECRYPTFS_REQ_PROCESSED 0x00000001 | 606 | #define ECRYPTFS_REQ_PROCESSED 0x00000001 |
606 | #define ECRYPTFS_REQ_DROPPED 0x00000002 | 607 | #define ECRYPTFS_REQ_DROPPED 0x00000002 |
607 | #define ECRYPTFS_REQ_ZOMBIE 0x00000004 | 608 | #define ECRYPTFS_REQ_ZOMBIE 0x00000004 |
608 | u32 flags; | 609 | u32 flags; |
609 | struct file **lower_file; | 610 | struct file **lower_file; |
610 | struct dentry *lower_dentry; | 611 | struct dentry *lower_dentry; |
611 | struct vfsmount *lower_mnt; | 612 | struct vfsmount *lower_mnt; |
612 | wait_queue_head_t wait; | 613 | wait_queue_head_t wait; |
613 | struct mutex mux; | 614 | struct mutex mux; |
614 | struct list_head kthread_ctl_list; | 615 | struct list_head kthread_ctl_list; |
615 | }; | 616 | }; |
616 | 617 | ||
617 | #define ECRYPTFS_INTERPOSE_FLAG_D_ADD 0x00000001 | 618 | #define ECRYPTFS_INTERPOSE_FLAG_D_ADD 0x00000001 |
618 | int ecryptfs_interpose(struct dentry *hidden_dentry, | 619 | int ecryptfs_interpose(struct dentry *hidden_dentry, |
619 | struct dentry *this_dentry, struct super_block *sb, | 620 | struct dentry *this_dentry, struct super_block *sb, |
620 | u32 flags); | 621 | u32 flags); |
621 | int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | 622 | int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, |
622 | struct dentry *lower_dentry, | 623 | struct dentry *lower_dentry, |
623 | struct inode *ecryptfs_dir_inode, | 624 | struct inode *ecryptfs_dir_inode, |
624 | struct nameidata *ecryptfs_nd); | 625 | struct nameidata *ecryptfs_nd); |
625 | int ecryptfs_decode_and_decrypt_filename(char **decrypted_name, | 626 | int ecryptfs_decode_and_decrypt_filename(char **decrypted_name, |
626 | size_t *decrypted_name_size, | 627 | size_t *decrypted_name_size, |
627 | struct dentry *ecryptfs_dentry, | 628 | struct dentry *ecryptfs_dentry, |
628 | const char *name, size_t name_size); | 629 | const char *name, size_t name_size); |
629 | int ecryptfs_fill_zeros(struct file *file, loff_t new_length); | 630 | int ecryptfs_fill_zeros(struct file *file, loff_t new_length); |
630 | int ecryptfs_encrypt_and_encode_filename( | 631 | int ecryptfs_encrypt_and_encode_filename( |
631 | char **encoded_name, | 632 | char **encoded_name, |
632 | size_t *encoded_name_size, | 633 | size_t *encoded_name_size, |
633 | struct ecryptfs_crypt_stat *crypt_stat, | 634 | struct ecryptfs_crypt_stat *crypt_stat, |
634 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, | 635 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, |
635 | const char *name, size_t name_size); | 636 | const char *name, size_t name_size); |
636 | struct dentry *ecryptfs_lower_dentry(struct dentry *this_dentry); | 637 | struct dentry *ecryptfs_lower_dentry(struct dentry *this_dentry); |
637 | void ecryptfs_dump_hex(char *data, int bytes); | 638 | void ecryptfs_dump_hex(char *data, int bytes); |
638 | int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg, | 639 | int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg, |
639 | int sg_size); | 640 | int sg_size); |
640 | int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat); | 641 | int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat); |
641 | void ecryptfs_rotate_iv(unsigned char *iv); | 642 | void ecryptfs_rotate_iv(unsigned char *iv); |
642 | void ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat); | 643 | void ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat); |
643 | void ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat); | 644 | void ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat); |
644 | void ecryptfs_destroy_mount_crypt_stat( | 645 | void ecryptfs_destroy_mount_crypt_stat( |
645 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat); | 646 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat); |
646 | int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat); | 647 | int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat); |
647 | int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode); | 648 | int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode); |
648 | int ecryptfs_encrypt_page(struct page *page); | 649 | int ecryptfs_encrypt_page(struct page *page); |
649 | int ecryptfs_decrypt_page(struct page *page); | 650 | int ecryptfs_decrypt_page(struct page *page); |
650 | int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry); | 651 | int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry); |
651 | int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry); | 652 | int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry); |
652 | int ecryptfs_new_file_context(struct dentry *ecryptfs_dentry); | 653 | int ecryptfs_new_file_context(struct dentry *ecryptfs_dentry); |
653 | int ecryptfs_read_and_validate_header_region(char *data, | 654 | int ecryptfs_read_and_validate_header_region(char *data, |
654 | struct inode *ecryptfs_inode); | 655 | struct inode *ecryptfs_inode); |
655 | int ecryptfs_read_and_validate_xattr_region(char *page_virt, | 656 | int ecryptfs_read_and_validate_xattr_region(char *page_virt, |
656 | struct dentry *ecryptfs_dentry); | 657 | struct dentry *ecryptfs_dentry); |
657 | u8 ecryptfs_code_for_cipher_string(char *cipher_name, size_t key_bytes); | 658 | u8 ecryptfs_code_for_cipher_string(char *cipher_name, size_t key_bytes); |
658 | int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code); | 659 | int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code); |
659 | void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat); | 660 | void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat); |
660 | int ecryptfs_generate_key_packet_set(char *dest_base, | 661 | int ecryptfs_generate_key_packet_set(char *dest_base, |
661 | struct ecryptfs_crypt_stat *crypt_stat, | 662 | struct ecryptfs_crypt_stat *crypt_stat, |
662 | struct dentry *ecryptfs_dentry, | 663 | struct dentry *ecryptfs_dentry, |
663 | size_t *len, size_t max); | 664 | size_t *len, size_t max); |
664 | int | 665 | int |
665 | ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, | 666 | ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, |
666 | unsigned char *src, struct dentry *ecryptfs_dentry); | 667 | unsigned char *src, struct dentry *ecryptfs_dentry); |
667 | int ecryptfs_truncate(struct dentry *dentry, loff_t new_length); | 668 | int ecryptfs_truncate(struct dentry *dentry, loff_t new_length); |
668 | int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode); | 669 | int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode); |
669 | int ecryptfs_inode_set(struct inode *inode, void *lower_inode); | 670 | int ecryptfs_inode_set(struct inode *inode, void *lower_inode); |
670 | void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode); | 671 | void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode); |
671 | ssize_t | 672 | ssize_t |
672 | ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name, | 673 | ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name, |
673 | void *value, size_t size); | 674 | void *value, size_t size); |
674 | int | 675 | int |
675 | ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, | 676 | ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, |
676 | size_t size, int flags); | 677 | size_t size, int flags); |
677 | int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode); | 678 | int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode); |
678 | int ecryptfs_process_helo(uid_t euid, struct user_namespace *user_ns, | 679 | int ecryptfs_process_helo(uid_t euid, struct user_namespace *user_ns, |
679 | struct pid *pid); | 680 | struct pid *pid); |
680 | int ecryptfs_process_quit(uid_t euid, struct user_namespace *user_ns, | 681 | int ecryptfs_process_quit(uid_t euid, struct user_namespace *user_ns, |
681 | struct pid *pid); | 682 | struct pid *pid); |
682 | int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid, | 683 | int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid, |
683 | struct user_namespace *user_ns, struct pid *pid, | 684 | struct user_namespace *user_ns, struct pid *pid, |
684 | u32 seq); | 685 | u32 seq); |
685 | int ecryptfs_send_message(char *data, int data_len, | 686 | int ecryptfs_send_message(char *data, int data_len, |
686 | struct ecryptfs_msg_ctx **msg_ctx); | 687 | struct ecryptfs_msg_ctx **msg_ctx); |
687 | int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx, | 688 | int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx, |
688 | struct ecryptfs_message **emsg); | 689 | struct ecryptfs_message **emsg); |
689 | int ecryptfs_init_messaging(void); | 690 | int ecryptfs_init_messaging(void); |
690 | void ecryptfs_release_messaging(void); | 691 | void ecryptfs_release_messaging(void); |
691 | 692 | ||
692 | void | 693 | void |
693 | ecryptfs_write_header_metadata(char *virt, | 694 | ecryptfs_write_header_metadata(char *virt, |
694 | struct ecryptfs_crypt_stat *crypt_stat, | 695 | struct ecryptfs_crypt_stat *crypt_stat, |
695 | size_t *written); | 696 | size_t *written); |
696 | int ecryptfs_add_keysig(struct ecryptfs_crypt_stat *crypt_stat, char *sig); | 697 | int ecryptfs_add_keysig(struct ecryptfs_crypt_stat *crypt_stat, char *sig); |
697 | int | 698 | int |
698 | ecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat, | 699 | ecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat, |
699 | char *sig, u32 global_auth_tok_flags); | 700 | char *sig, u32 global_auth_tok_flags); |
700 | int ecryptfs_get_global_auth_tok_for_sig( | 701 | int ecryptfs_get_global_auth_tok_for_sig( |
701 | struct ecryptfs_global_auth_tok **global_auth_tok, | 702 | struct ecryptfs_global_auth_tok **global_auth_tok, |
702 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, char *sig); | 703 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, char *sig); |
703 | int | 704 | int |
704 | ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name, | 705 | ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name, |
705 | size_t key_size); | 706 | size_t key_size); |
706 | int ecryptfs_init_crypto(void); | 707 | int ecryptfs_init_crypto(void); |
707 | int ecryptfs_destroy_crypto(void); | 708 | int ecryptfs_destroy_crypto(void); |
708 | int ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm); | 709 | int ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm); |
709 | int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm, | 710 | int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm, |
710 | struct mutex **tfm_mutex, | 711 | struct mutex **tfm_mutex, |
711 | char *cipher_name); | 712 | char *cipher_name); |
712 | int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key, | 713 | int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key, |
713 | struct ecryptfs_auth_tok **auth_tok, | 714 | struct ecryptfs_auth_tok **auth_tok, |
714 | char *sig); | 715 | char *sig); |
715 | int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data, | 716 | int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data, |
716 | loff_t offset, size_t size); | 717 | loff_t offset, size_t size); |
717 | int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode, | 718 | int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode, |
718 | struct page *page_for_lower, | 719 | struct page *page_for_lower, |
719 | size_t offset_in_page, size_t size); | 720 | size_t offset_in_page, size_t size); |
720 | int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | 721 | int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, |
721 | size_t size); | 722 | size_t size); |
722 | int ecryptfs_read_lower(char *data, loff_t offset, size_t size, | 723 | int ecryptfs_read_lower(char *data, loff_t offset, size_t size, |
723 | struct inode *ecryptfs_inode); | 724 | struct inode *ecryptfs_inode); |
724 | int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs, | 725 | int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs, |
725 | pgoff_t page_index, | 726 | pgoff_t page_index, |
726 | size_t offset_in_page, size_t size, | 727 | size_t offset_in_page, size_t size, |
727 | struct inode *ecryptfs_inode); | 728 | struct inode *ecryptfs_inode); |
728 | struct page *ecryptfs_get_locked_page(struct file *file, loff_t index); | 729 | struct page *ecryptfs_get_locked_page(struct file *file, loff_t index); |
729 | int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon); | 730 | int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon); |
730 | int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon, uid_t euid, | 731 | int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon, uid_t euid, |
731 | struct user_namespace *user_ns); | 732 | struct user_namespace *user_ns); |
732 | int ecryptfs_parse_packet_length(unsigned char *data, size_t *size, | 733 | int ecryptfs_parse_packet_length(unsigned char *data, size_t *size, |
733 | size_t *length_size); | 734 | size_t *length_size); |
734 | int ecryptfs_write_packet_length(char *dest, size_t size, | 735 | int ecryptfs_write_packet_length(char *dest, size_t size, |
735 | size_t *packet_size_length); | 736 | size_t *packet_size_length); |
736 | int ecryptfs_init_ecryptfs_miscdev(void); | 737 | int ecryptfs_init_ecryptfs_miscdev(void); |
737 | void ecryptfs_destroy_ecryptfs_miscdev(void); | 738 | void ecryptfs_destroy_ecryptfs_miscdev(void); |
738 | int ecryptfs_send_miscdev(char *data, size_t data_size, | 739 | int ecryptfs_send_miscdev(char *data, size_t data_size, |
739 | struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, | 740 | struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, |
740 | u16 msg_flags, struct ecryptfs_daemon *daemon); | 741 | u16 msg_flags, struct ecryptfs_daemon *daemon); |
741 | void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx); | 742 | void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx); |
742 | int | 743 | int |
743 | ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, uid_t euid, | 744 | ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, uid_t euid, |
744 | struct user_namespace *user_ns, struct pid *pid); | 745 | struct user_namespace *user_ns, struct pid *pid); |
745 | int ecryptfs_init_kthread(void); | 746 | int ecryptfs_init_kthread(void); |
746 | void ecryptfs_destroy_kthread(void); | 747 | void ecryptfs_destroy_kthread(void); |
747 | int ecryptfs_privileged_open(struct file **lower_file, | 748 | int ecryptfs_privileged_open(struct file **lower_file, |
748 | struct dentry *lower_dentry, | 749 | struct dentry *lower_dentry, |
749 | struct vfsmount *lower_mnt, | 750 | struct vfsmount *lower_mnt, |
750 | const struct cred *cred); | 751 | const struct cred *cred); |
751 | int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry); | 752 | int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry); |
752 | int | 753 | int |
753 | ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes, | 754 | ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes, |
754 | size_t *packet_size, | 755 | size_t *packet_size, |
755 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, | 756 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, |
756 | char *filename, size_t filename_size); | 757 | char *filename, size_t filename_size); |
757 | int | 758 | int |
758 | ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size, | 759 | ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size, |
759 | size_t *packet_size, | 760 | size_t *packet_size, |
760 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, | 761 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, |
761 | char *data, size_t max_packet_size); | 762 | char *data, size_t max_packet_size); |
762 | int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat, | 763 | int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat, |
763 | loff_t offset); | 764 | loff_t offset); |
764 | 765 | ||
765 | #endif /* #ifndef ECRYPTFS_KERNEL_H */ | 766 | #endif /* #ifndef ECRYPTFS_KERNEL_H */ |
766 | 767 |
fs/ecryptfs/main.c
1 | /** | 1 | /** |
2 | * eCryptfs: Linux filesystem encryption layer | 2 | * eCryptfs: Linux filesystem encryption layer |
3 | * | 3 | * |
4 | * Copyright (C) 1997-2003 Erez Zadok | 4 | * Copyright (C) 1997-2003 Erez Zadok |
5 | * Copyright (C) 2001-2003 Stony Brook University | 5 | * Copyright (C) 2001-2003 Stony Brook University |
6 | * Copyright (C) 2004-2007 International Business Machines Corp. | 6 | * Copyright (C) 2004-2007 International Business Machines Corp. |
7 | * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> | 7 | * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> |
8 | * Michael C. Thompson <mcthomps@us.ibm.com> | 8 | * Michael C. Thompson <mcthomps@us.ibm.com> |
9 | * Tyler Hicks <tyhicks@ou.edu> | 9 | * Tyler Hicks <tyhicks@ou.edu> |
10 | * | 10 | * |
11 | * This program is free software; you can redistribute it and/or | 11 | * This program is free software; you can redistribute it and/or |
12 | * modify it under the terms of the GNU General Public License as | 12 | * modify it under the terms of the GNU General Public License as |
13 | * published by the Free Software Foundation; either version 2 of the | 13 | * published by the Free Software Foundation; either version 2 of the |
14 | * License, or (at your option) any later version. | 14 | * License, or (at your option) any later version. |
15 | * | 15 | * |
16 | * This program is distributed in the hope that it will be useful, but | 16 | * This program is distributed in the hope that it will be useful, but |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | * General Public License for more details. | 19 | * General Public License for more details. |
20 | * | 20 | * |
21 | * You should have received a copy of the GNU General Public License | 21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software | 22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
24 | * 02111-1307, USA. | 24 | * 02111-1307, USA. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include <linux/dcache.h> | 27 | #include <linux/dcache.h> |
28 | #include <linux/file.h> | 28 | #include <linux/file.h> |
29 | #include <linux/module.h> | 29 | #include <linux/module.h> |
30 | #include <linux/namei.h> | 30 | #include <linux/namei.h> |
31 | #include <linux/skbuff.h> | 31 | #include <linux/skbuff.h> |
32 | #include <linux/crypto.h> | 32 | #include <linux/crypto.h> |
33 | #include <linux/mount.h> | 33 | #include <linux/mount.h> |
34 | #include <linux/pagemap.h> | 34 | #include <linux/pagemap.h> |
35 | #include <linux/key.h> | 35 | #include <linux/key.h> |
36 | #include <linux/parser.h> | 36 | #include <linux/parser.h> |
37 | #include <linux/fs_stack.h> | 37 | #include <linux/fs_stack.h> |
38 | #include "ecryptfs_kernel.h" | 38 | #include "ecryptfs_kernel.h" |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Module parameter that defines the ecryptfs_verbosity level. | 41 | * Module parameter that defines the ecryptfs_verbosity level. |
42 | */ | 42 | */ |
43 | int ecryptfs_verbosity = 0; | 43 | int ecryptfs_verbosity = 0; |
44 | 44 | ||
45 | module_param(ecryptfs_verbosity, int, 0); | 45 | module_param(ecryptfs_verbosity, int, 0); |
46 | MODULE_PARM_DESC(ecryptfs_verbosity, | 46 | MODULE_PARM_DESC(ecryptfs_verbosity, |
47 | "Initial verbosity level (0 or 1; defaults to " | 47 | "Initial verbosity level (0 or 1; defaults to " |
48 | "0, which is Quiet)"); | 48 | "0, which is Quiet)"); |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Module parameter that defines the number of message buffer elements | 51 | * Module parameter that defines the number of message buffer elements |
52 | */ | 52 | */ |
53 | unsigned int ecryptfs_message_buf_len = ECRYPTFS_DEFAULT_MSG_CTX_ELEMS; | 53 | unsigned int ecryptfs_message_buf_len = ECRYPTFS_DEFAULT_MSG_CTX_ELEMS; |
54 | 54 | ||
55 | module_param(ecryptfs_message_buf_len, uint, 0); | 55 | module_param(ecryptfs_message_buf_len, uint, 0); |
56 | MODULE_PARM_DESC(ecryptfs_message_buf_len, | 56 | MODULE_PARM_DESC(ecryptfs_message_buf_len, |
57 | "Number of message buffer elements"); | 57 | "Number of message buffer elements"); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Module parameter that defines the maximum guaranteed amount of time to wait | 60 | * Module parameter that defines the maximum guaranteed amount of time to wait |
61 | * for a response from ecryptfsd. The actual sleep time will be, more than | 61 | * for a response from ecryptfsd. The actual sleep time will be, more than |
62 | * likely, a small amount greater than this specified value, but only less if | 62 | * likely, a small amount greater than this specified value, but only less if |
63 | * the message successfully arrives. | 63 | * the message successfully arrives. |
64 | */ | 64 | */ |
65 | signed long ecryptfs_message_wait_timeout = ECRYPTFS_MAX_MSG_CTX_TTL / HZ; | 65 | signed long ecryptfs_message_wait_timeout = ECRYPTFS_MAX_MSG_CTX_TTL / HZ; |
66 | 66 | ||
67 | module_param(ecryptfs_message_wait_timeout, long, 0); | 67 | module_param(ecryptfs_message_wait_timeout, long, 0); |
68 | MODULE_PARM_DESC(ecryptfs_message_wait_timeout, | 68 | MODULE_PARM_DESC(ecryptfs_message_wait_timeout, |
69 | "Maximum number of seconds that an operation will " | 69 | "Maximum number of seconds that an operation will " |
70 | "sleep while waiting for a message response from " | 70 | "sleep while waiting for a message response from " |
71 | "userspace"); | 71 | "userspace"); |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Module parameter that is an estimate of the maximum number of users | 74 | * Module parameter that is an estimate of the maximum number of users |
75 | * that will be concurrently using eCryptfs. Set this to the right | 75 | * that will be concurrently using eCryptfs. Set this to the right |
76 | * value to balance performance and memory use. | 76 | * value to balance performance and memory use. |
77 | */ | 77 | */ |
78 | unsigned int ecryptfs_number_of_users = ECRYPTFS_DEFAULT_NUM_USERS; | 78 | unsigned int ecryptfs_number_of_users = ECRYPTFS_DEFAULT_NUM_USERS; |
79 | 79 | ||
80 | module_param(ecryptfs_number_of_users, uint, 0); | 80 | module_param(ecryptfs_number_of_users, uint, 0); |
81 | MODULE_PARM_DESC(ecryptfs_number_of_users, "An estimate of the number of " | 81 | MODULE_PARM_DESC(ecryptfs_number_of_users, "An estimate of the number of " |
82 | "concurrent users of eCryptfs"); | 82 | "concurrent users of eCryptfs"); |
83 | 83 | ||
84 | void __ecryptfs_printk(const char *fmt, ...) | 84 | void __ecryptfs_printk(const char *fmt, ...) |
85 | { | 85 | { |
86 | va_list args; | 86 | va_list args; |
87 | va_start(args, fmt); | 87 | va_start(args, fmt); |
88 | if (fmt[1] == '7') { /* KERN_DEBUG */ | 88 | if (fmt[1] == '7') { /* KERN_DEBUG */ |
89 | if (ecryptfs_verbosity >= 1) | 89 | if (ecryptfs_verbosity >= 1) |
90 | vprintk(fmt, args); | 90 | vprintk(fmt, args); |
91 | } else | 91 | } else |
92 | vprintk(fmt, args); | 92 | vprintk(fmt, args); |
93 | va_end(args); | 93 | va_end(args); |
94 | } | 94 | } |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * ecryptfs_init_persistent_file | 97 | * ecryptfs_init_persistent_file |
98 | * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with | 98 | * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with |
99 | * the lower dentry and the lower mount set | 99 | * the lower dentry and the lower mount set |
100 | * | 100 | * |
101 | * eCryptfs only ever keeps a single open file for every lower | 101 | * eCryptfs only ever keeps a single open file for every lower |
102 | * inode. All I/O operations to the lower inode occur through that | 102 | * inode. All I/O operations to the lower inode occur through that |
103 | * file. When the first eCryptfs dentry that interposes with the first | 103 | * file. When the first eCryptfs dentry that interposes with the first |
104 | * lower dentry for that inode is created, this function creates the | 104 | * lower dentry for that inode is created, this function creates the |
105 | * persistent file struct and associates it with the eCryptfs | 105 | * persistent file struct and associates it with the eCryptfs |
106 | * inode. When the eCryptfs inode is destroyed, the file is closed. | 106 | * inode. When the eCryptfs inode is destroyed, the file is closed. |
107 | * | 107 | * |
108 | * The persistent file will be opened with read/write permissions, if | 108 | * The persistent file will be opened with read/write permissions, if |
109 | * possible. Otherwise, it is opened read-only. | 109 | * possible. Otherwise, it is opened read-only. |
110 | * | 110 | * |
111 | * This function does nothing if a lower persistent file is already | 111 | * This function does nothing if a lower persistent file is already |
112 | * associated with the eCryptfs inode. | 112 | * associated with the eCryptfs inode. |
113 | * | 113 | * |
114 | * Returns zero on success; non-zero otherwise | 114 | * Returns zero on success; non-zero otherwise |
115 | */ | 115 | */ |
116 | int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry) | 116 | int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry) |
117 | { | 117 | { |
118 | const struct cred *cred = current_cred(); | 118 | const struct cred *cred = current_cred(); |
119 | struct ecryptfs_inode_info *inode_info = | 119 | struct ecryptfs_inode_info *inode_info = |
120 | ecryptfs_inode_to_private(ecryptfs_dentry->d_inode); | 120 | ecryptfs_inode_to_private(ecryptfs_dentry->d_inode); |
121 | int rc = 0; | 121 | int rc = 0; |
122 | 122 | ||
123 | mutex_lock(&inode_info->lower_file_mutex); | 123 | mutex_lock(&inode_info->lower_file_mutex); |
124 | if (!inode_info->lower_file) { | 124 | if (!inode_info->lower_file) { |
125 | struct dentry *lower_dentry; | 125 | struct dentry *lower_dentry; |
126 | struct vfsmount *lower_mnt = | 126 | struct vfsmount *lower_mnt = |
127 | ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry); | 127 | ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry); |
128 | 128 | ||
129 | lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); | 129 | lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); |
130 | rc = ecryptfs_privileged_open(&inode_info->lower_file, | 130 | rc = ecryptfs_privileged_open(&inode_info->lower_file, |
131 | lower_dentry, lower_mnt, cred); | 131 | lower_dentry, lower_mnt, cred); |
132 | if (rc || IS_ERR(inode_info->lower_file)) { | 132 | if (rc || IS_ERR(inode_info->lower_file)) { |
133 | printk(KERN_ERR "Error opening lower persistent file " | 133 | printk(KERN_ERR "Error opening lower persistent file " |
134 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " | 134 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " |
135 | "rc = [%d]\n", lower_dentry, lower_mnt, rc); | 135 | "rc = [%d]\n", lower_dentry, lower_mnt, rc); |
136 | rc = PTR_ERR(inode_info->lower_file); | 136 | rc = PTR_ERR(inode_info->lower_file); |
137 | inode_info->lower_file = NULL; | 137 | inode_info->lower_file = NULL; |
138 | } | 138 | } |
139 | } | 139 | } |
140 | mutex_unlock(&inode_info->lower_file_mutex); | 140 | mutex_unlock(&inode_info->lower_file_mutex); |
141 | return rc; | 141 | return rc; |
142 | } | 142 | } |
143 | 143 | ||
144 | /** | 144 | /** |
145 | * ecryptfs_interpose | 145 | * ecryptfs_interpose |
146 | * @lower_dentry: Existing dentry in the lower filesystem | 146 | * @lower_dentry: Existing dentry in the lower filesystem |
147 | * @dentry: ecryptfs' dentry | 147 | * @dentry: ecryptfs' dentry |
148 | * @sb: ecryptfs's super_block | 148 | * @sb: ecryptfs's super_block |
149 | * @flags: flags to govern behavior of interpose procedure | 149 | * @flags: flags to govern behavior of interpose procedure |
150 | * | 150 | * |
151 | * Interposes upper and lower dentries. | 151 | * Interposes upper and lower dentries. |
152 | * | 152 | * |
153 | * Returns zero on success; non-zero otherwise | 153 | * Returns zero on success; non-zero otherwise |
154 | */ | 154 | */ |
155 | int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry, | 155 | int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry, |
156 | struct super_block *sb, u32 flags) | 156 | struct super_block *sb, u32 flags) |
157 | { | 157 | { |
158 | struct inode *lower_inode; | 158 | struct inode *lower_inode; |
159 | struct inode *inode; | 159 | struct inode *inode; |
160 | int rc = 0; | 160 | int rc = 0; |
161 | 161 | ||
162 | lower_inode = lower_dentry->d_inode; | 162 | lower_inode = lower_dentry->d_inode; |
163 | if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) { | 163 | if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) { |
164 | rc = -EXDEV; | 164 | rc = -EXDEV; |
165 | goto out; | 165 | goto out; |
166 | } | 166 | } |
167 | if (!igrab(lower_inode)) { | 167 | if (!igrab(lower_inode)) { |
168 | rc = -ESTALE; | 168 | rc = -ESTALE; |
169 | goto out; | 169 | goto out; |
170 | } | 170 | } |
171 | inode = iget5_locked(sb, (unsigned long)lower_inode, | 171 | inode = iget5_locked(sb, (unsigned long)lower_inode, |
172 | ecryptfs_inode_test, ecryptfs_inode_set, | 172 | ecryptfs_inode_test, ecryptfs_inode_set, |
173 | lower_inode); | 173 | lower_inode); |
174 | if (!inode) { | 174 | if (!inode) { |
175 | rc = -EACCES; | 175 | rc = -EACCES; |
176 | iput(lower_inode); | 176 | iput(lower_inode); |
177 | goto out; | 177 | goto out; |
178 | } | 178 | } |
179 | if (inode->i_state & I_NEW) | 179 | if (inode->i_state & I_NEW) |
180 | unlock_new_inode(inode); | 180 | unlock_new_inode(inode); |
181 | else | 181 | else |
182 | iput(lower_inode); | 182 | iput(lower_inode); |
183 | if (S_ISLNK(lower_inode->i_mode)) | 183 | if (S_ISLNK(lower_inode->i_mode)) |
184 | inode->i_op = &ecryptfs_symlink_iops; | 184 | inode->i_op = &ecryptfs_symlink_iops; |
185 | else if (S_ISDIR(lower_inode->i_mode)) | 185 | else if (S_ISDIR(lower_inode->i_mode)) |
186 | inode->i_op = &ecryptfs_dir_iops; | 186 | inode->i_op = &ecryptfs_dir_iops; |
187 | if (S_ISDIR(lower_inode->i_mode)) | 187 | if (S_ISDIR(lower_inode->i_mode)) |
188 | inode->i_fop = &ecryptfs_dir_fops; | 188 | inode->i_fop = &ecryptfs_dir_fops; |
189 | if (special_file(lower_inode->i_mode)) | 189 | if (special_file(lower_inode->i_mode)) |
190 | init_special_inode(inode, lower_inode->i_mode, | 190 | init_special_inode(inode, lower_inode->i_mode, |
191 | lower_inode->i_rdev); | 191 | lower_inode->i_rdev); |
192 | dentry->d_op = &ecryptfs_dops; | 192 | dentry->d_op = &ecryptfs_dops; |
193 | fsstack_copy_attr_all(inode, lower_inode, NULL); | 193 | fsstack_copy_attr_all(inode, lower_inode, NULL); |
194 | /* This size will be overwritten for real files w/ headers and | 194 | /* This size will be overwritten for real files w/ headers and |
195 | * other metadata */ | 195 | * other metadata */ |
196 | fsstack_copy_inode_size(inode, lower_inode); | 196 | fsstack_copy_inode_size(inode, lower_inode); |
197 | if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD) | 197 | if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD) |
198 | d_add(dentry, inode); | 198 | d_add(dentry, inode); |
199 | else | 199 | else |
200 | d_instantiate(dentry, inode); | 200 | d_instantiate(dentry, inode); |
201 | out: | 201 | out: |
202 | return rc; | 202 | return rc; |
203 | } | 203 | } |
204 | 204 | ||
205 | enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, | 205 | enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, |
206 | ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher, | 206 | ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher, |
207 | ecryptfs_opt_ecryptfs_key_bytes, | 207 | ecryptfs_opt_ecryptfs_key_bytes, |
208 | ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata, | 208 | ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata, |
209 | ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig, | 209 | ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig, |
210 | ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_bytes, | 210 | ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_bytes, |
211 | ecryptfs_opt_err }; | 211 | ecryptfs_opt_unlink_sigs, ecryptfs_opt_err }; |
212 | 212 | ||
213 | static const match_table_t tokens = { | 213 | static const match_table_t tokens = { |
214 | {ecryptfs_opt_sig, "sig=%s"}, | 214 | {ecryptfs_opt_sig, "sig=%s"}, |
215 | {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"}, | 215 | {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"}, |
216 | {ecryptfs_opt_cipher, "cipher=%s"}, | 216 | {ecryptfs_opt_cipher, "cipher=%s"}, |
217 | {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"}, | 217 | {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"}, |
218 | {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"}, | 218 | {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"}, |
219 | {ecryptfs_opt_passthrough, "ecryptfs_passthrough"}, | 219 | {ecryptfs_opt_passthrough, "ecryptfs_passthrough"}, |
220 | {ecryptfs_opt_xattr_metadata, "ecryptfs_xattr_metadata"}, | 220 | {ecryptfs_opt_xattr_metadata, "ecryptfs_xattr_metadata"}, |
221 | {ecryptfs_opt_encrypted_view, "ecryptfs_encrypted_view"}, | 221 | {ecryptfs_opt_encrypted_view, "ecryptfs_encrypted_view"}, |
222 | {ecryptfs_opt_fnek_sig, "ecryptfs_fnek_sig=%s"}, | 222 | {ecryptfs_opt_fnek_sig, "ecryptfs_fnek_sig=%s"}, |
223 | {ecryptfs_opt_fn_cipher, "ecryptfs_fn_cipher=%s"}, | 223 | {ecryptfs_opt_fn_cipher, "ecryptfs_fn_cipher=%s"}, |
224 | {ecryptfs_opt_fn_cipher_key_bytes, "ecryptfs_fn_key_bytes=%u"}, | 224 | {ecryptfs_opt_fn_cipher_key_bytes, "ecryptfs_fn_key_bytes=%u"}, |
225 | {ecryptfs_opt_unlink_sigs, "ecryptfs_unlink_sigs"}, | ||
225 | {ecryptfs_opt_err, NULL} | 226 | {ecryptfs_opt_err, NULL} |
226 | }; | 227 | }; |
227 | 228 | ||
228 | static int ecryptfs_init_global_auth_toks( | 229 | static int ecryptfs_init_global_auth_toks( |
229 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat) | 230 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat) |
230 | { | 231 | { |
231 | struct ecryptfs_global_auth_tok *global_auth_tok; | 232 | struct ecryptfs_global_auth_tok *global_auth_tok; |
232 | int rc = 0; | 233 | int rc = 0; |
233 | 234 | ||
234 | list_for_each_entry(global_auth_tok, | 235 | list_for_each_entry(global_auth_tok, |
235 | &mount_crypt_stat->global_auth_tok_list, | 236 | &mount_crypt_stat->global_auth_tok_list, |
236 | mount_crypt_stat_list) { | 237 | mount_crypt_stat_list) { |
237 | rc = ecryptfs_keyring_auth_tok_for_sig( | 238 | rc = ecryptfs_keyring_auth_tok_for_sig( |
238 | &global_auth_tok->global_auth_tok_key, | 239 | &global_auth_tok->global_auth_tok_key, |
239 | &global_auth_tok->global_auth_tok, | 240 | &global_auth_tok->global_auth_tok, |
240 | global_auth_tok->sig); | 241 | global_auth_tok->sig); |
241 | if (rc) { | 242 | if (rc) { |
242 | printk(KERN_ERR "Could not find valid key in user " | 243 | printk(KERN_ERR "Could not find valid key in user " |
243 | "session keyring for sig specified in mount " | 244 | "session keyring for sig specified in mount " |
244 | "option: [%s]\n", global_auth_tok->sig); | 245 | "option: [%s]\n", global_auth_tok->sig); |
245 | global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID; | 246 | global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID; |
246 | goto out; | 247 | goto out; |
247 | } else | 248 | } else |
248 | global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID; | 249 | global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID; |
249 | } | 250 | } |
250 | out: | 251 | out: |
251 | return rc; | 252 | return rc; |
252 | } | 253 | } |
253 | 254 | ||
254 | static void ecryptfs_init_mount_crypt_stat( | 255 | static void ecryptfs_init_mount_crypt_stat( |
255 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat) | 256 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat) |
256 | { | 257 | { |
257 | memset((void *)mount_crypt_stat, 0, | 258 | memset((void *)mount_crypt_stat, 0, |
258 | sizeof(struct ecryptfs_mount_crypt_stat)); | 259 | sizeof(struct ecryptfs_mount_crypt_stat)); |
259 | INIT_LIST_HEAD(&mount_crypt_stat->global_auth_tok_list); | 260 | INIT_LIST_HEAD(&mount_crypt_stat->global_auth_tok_list); |
260 | mutex_init(&mount_crypt_stat->global_auth_tok_list_mutex); | 261 | mutex_init(&mount_crypt_stat->global_auth_tok_list_mutex); |
261 | mount_crypt_stat->flags |= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED; | 262 | mount_crypt_stat->flags |= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED; |
262 | } | 263 | } |
263 | 264 | ||
264 | /** | 265 | /** |
265 | * ecryptfs_parse_options | 266 | * ecryptfs_parse_options |
266 | * @sb: The ecryptfs super block | 267 | * @sb: The ecryptfs super block |
267 | * @options: The options pased to the kernel | 268 | * @options: The options pased to the kernel |
268 | * | 269 | * |
269 | * Parse mount options: | 270 | * Parse mount options: |
270 | * debug=N - ecryptfs_verbosity level for debug output | 271 | * debug=N - ecryptfs_verbosity level for debug output |
271 | * sig=XXX - description(signature) of the key to use | 272 | * sig=XXX - description(signature) of the key to use |
272 | * | 273 | * |
273 | * Returns the dentry object of the lower-level (lower/interposed) | 274 | * Returns the dentry object of the lower-level (lower/interposed) |
274 | * directory; We want to mount our stackable file system on top of | 275 | * directory; We want to mount our stackable file system on top of |
275 | * that lower directory. | 276 | * that lower directory. |
276 | * | 277 | * |
277 | * The signature of the key to use must be the description of a key | 278 | * The signature of the key to use must be the description of a key |
278 | * already in the keyring. Mounting will fail if the key can not be | 279 | * already in the keyring. Mounting will fail if the key can not be |
279 | * found. | 280 | * found. |
280 | * | 281 | * |
281 | * Returns zero on success; non-zero on error | 282 | * Returns zero on success; non-zero on error |
282 | */ | 283 | */ |
283 | static int ecryptfs_parse_options(struct super_block *sb, char *options) | 284 | static int ecryptfs_parse_options(struct super_block *sb, char *options) |
284 | { | 285 | { |
285 | char *p; | 286 | char *p; |
286 | int rc = 0; | 287 | int rc = 0; |
287 | int sig_set = 0; | 288 | int sig_set = 0; |
288 | int cipher_name_set = 0; | 289 | int cipher_name_set = 0; |
289 | int fn_cipher_name_set = 0; | 290 | int fn_cipher_name_set = 0; |
290 | int cipher_key_bytes; | 291 | int cipher_key_bytes; |
291 | int cipher_key_bytes_set = 0; | 292 | int cipher_key_bytes_set = 0; |
292 | int fn_cipher_key_bytes; | 293 | int fn_cipher_key_bytes; |
293 | int fn_cipher_key_bytes_set = 0; | 294 | int fn_cipher_key_bytes_set = 0; |
294 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = | 295 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = |
295 | &ecryptfs_superblock_to_private(sb)->mount_crypt_stat; | 296 | &ecryptfs_superblock_to_private(sb)->mount_crypt_stat; |
296 | substring_t args[MAX_OPT_ARGS]; | 297 | substring_t args[MAX_OPT_ARGS]; |
297 | int token; | 298 | int token; |
298 | char *sig_src; | 299 | char *sig_src; |
299 | char *cipher_name_dst; | 300 | char *cipher_name_dst; |
300 | char *cipher_name_src; | 301 | char *cipher_name_src; |
301 | char *fn_cipher_name_dst; | 302 | char *fn_cipher_name_dst; |
302 | char *fn_cipher_name_src; | 303 | char *fn_cipher_name_src; |
303 | char *fnek_dst; | 304 | char *fnek_dst; |
304 | char *fnek_src; | 305 | char *fnek_src; |
305 | char *cipher_key_bytes_src; | 306 | char *cipher_key_bytes_src; |
306 | char *fn_cipher_key_bytes_src; | 307 | char *fn_cipher_key_bytes_src; |
307 | 308 | ||
308 | if (!options) { | 309 | if (!options) { |
309 | rc = -EINVAL; | 310 | rc = -EINVAL; |
310 | goto out; | 311 | goto out; |
311 | } | 312 | } |
312 | ecryptfs_init_mount_crypt_stat(mount_crypt_stat); | 313 | ecryptfs_init_mount_crypt_stat(mount_crypt_stat); |
313 | while ((p = strsep(&options, ",")) != NULL) { | 314 | while ((p = strsep(&options, ",")) != NULL) { |
314 | if (!*p) | 315 | if (!*p) |
315 | continue; | 316 | continue; |
316 | token = match_token(p, tokens, args); | 317 | token = match_token(p, tokens, args); |
317 | switch (token) { | 318 | switch (token) { |
318 | case ecryptfs_opt_sig: | 319 | case ecryptfs_opt_sig: |
319 | case ecryptfs_opt_ecryptfs_sig: | 320 | case ecryptfs_opt_ecryptfs_sig: |
320 | sig_src = args[0].from; | 321 | sig_src = args[0].from; |
321 | rc = ecryptfs_add_global_auth_tok(mount_crypt_stat, | 322 | rc = ecryptfs_add_global_auth_tok(mount_crypt_stat, |
322 | sig_src, 0); | 323 | sig_src, 0); |
323 | if (rc) { | 324 | if (rc) { |
324 | printk(KERN_ERR "Error attempting to register " | 325 | printk(KERN_ERR "Error attempting to register " |
325 | "global sig; rc = [%d]\n", rc); | 326 | "global sig; rc = [%d]\n", rc); |
326 | goto out; | 327 | goto out; |
327 | } | 328 | } |
328 | sig_set = 1; | 329 | sig_set = 1; |
329 | break; | 330 | break; |
330 | case ecryptfs_opt_cipher: | 331 | case ecryptfs_opt_cipher: |
331 | case ecryptfs_opt_ecryptfs_cipher: | 332 | case ecryptfs_opt_ecryptfs_cipher: |
332 | cipher_name_src = args[0].from; | 333 | cipher_name_src = args[0].from; |
333 | cipher_name_dst = | 334 | cipher_name_dst = |
334 | mount_crypt_stat-> | 335 | mount_crypt_stat-> |
335 | global_default_cipher_name; | 336 | global_default_cipher_name; |
336 | strncpy(cipher_name_dst, cipher_name_src, | 337 | strncpy(cipher_name_dst, cipher_name_src, |
337 | ECRYPTFS_MAX_CIPHER_NAME_SIZE); | 338 | ECRYPTFS_MAX_CIPHER_NAME_SIZE); |
338 | cipher_name_dst[ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0'; | 339 | cipher_name_dst[ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0'; |
339 | cipher_name_set = 1; | 340 | cipher_name_set = 1; |
340 | break; | 341 | break; |
341 | case ecryptfs_opt_ecryptfs_key_bytes: | 342 | case ecryptfs_opt_ecryptfs_key_bytes: |
342 | cipher_key_bytes_src = args[0].from; | 343 | cipher_key_bytes_src = args[0].from; |
343 | cipher_key_bytes = | 344 | cipher_key_bytes = |
344 | (int)simple_strtol(cipher_key_bytes_src, | 345 | (int)simple_strtol(cipher_key_bytes_src, |
345 | &cipher_key_bytes_src, 0); | 346 | &cipher_key_bytes_src, 0); |
346 | mount_crypt_stat->global_default_cipher_key_size = | 347 | mount_crypt_stat->global_default_cipher_key_size = |
347 | cipher_key_bytes; | 348 | cipher_key_bytes; |
348 | cipher_key_bytes_set = 1; | 349 | cipher_key_bytes_set = 1; |
349 | break; | 350 | break; |
350 | case ecryptfs_opt_passthrough: | 351 | case ecryptfs_opt_passthrough: |
351 | mount_crypt_stat->flags |= | 352 | mount_crypt_stat->flags |= |
352 | ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED; | 353 | ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED; |
353 | break; | 354 | break; |
354 | case ecryptfs_opt_xattr_metadata: | 355 | case ecryptfs_opt_xattr_metadata: |
355 | mount_crypt_stat->flags |= | 356 | mount_crypt_stat->flags |= |
356 | ECRYPTFS_XATTR_METADATA_ENABLED; | 357 | ECRYPTFS_XATTR_METADATA_ENABLED; |
357 | break; | 358 | break; |
358 | case ecryptfs_opt_encrypted_view: | 359 | case ecryptfs_opt_encrypted_view: |
359 | mount_crypt_stat->flags |= | 360 | mount_crypt_stat->flags |= |
360 | ECRYPTFS_XATTR_METADATA_ENABLED; | 361 | ECRYPTFS_XATTR_METADATA_ENABLED; |
361 | mount_crypt_stat->flags |= | 362 | mount_crypt_stat->flags |= |
362 | ECRYPTFS_ENCRYPTED_VIEW_ENABLED; | 363 | ECRYPTFS_ENCRYPTED_VIEW_ENABLED; |
363 | break; | 364 | break; |
364 | case ecryptfs_opt_fnek_sig: | 365 | case ecryptfs_opt_fnek_sig: |
365 | fnek_src = args[0].from; | 366 | fnek_src = args[0].from; |
366 | fnek_dst = | 367 | fnek_dst = |
367 | mount_crypt_stat->global_default_fnek_sig; | 368 | mount_crypt_stat->global_default_fnek_sig; |
368 | strncpy(fnek_dst, fnek_src, ECRYPTFS_SIG_SIZE_HEX); | 369 | strncpy(fnek_dst, fnek_src, ECRYPTFS_SIG_SIZE_HEX); |
369 | mount_crypt_stat->global_default_fnek_sig[ | 370 | mount_crypt_stat->global_default_fnek_sig[ |
370 | ECRYPTFS_SIG_SIZE_HEX] = '\0'; | 371 | ECRYPTFS_SIG_SIZE_HEX] = '\0'; |
371 | rc = ecryptfs_add_global_auth_tok( | 372 | rc = ecryptfs_add_global_auth_tok( |
372 | mount_crypt_stat, | 373 | mount_crypt_stat, |
373 | mount_crypt_stat->global_default_fnek_sig, | 374 | mount_crypt_stat->global_default_fnek_sig, |
374 | ECRYPTFS_AUTH_TOK_FNEK); | 375 | ECRYPTFS_AUTH_TOK_FNEK); |
375 | if (rc) { | 376 | if (rc) { |
376 | printk(KERN_ERR "Error attempting to register " | 377 | printk(KERN_ERR "Error attempting to register " |
377 | "global fnek sig [%s]; rc = [%d]\n", | 378 | "global fnek sig [%s]; rc = [%d]\n", |
378 | mount_crypt_stat->global_default_fnek_sig, | 379 | mount_crypt_stat->global_default_fnek_sig, |
379 | rc); | 380 | rc); |
380 | goto out; | 381 | goto out; |
381 | } | 382 | } |
382 | mount_crypt_stat->flags |= | 383 | mount_crypt_stat->flags |= |
383 | (ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES | 384 | (ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES |
384 | | ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK); | 385 | | ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK); |
385 | break; | 386 | break; |
386 | case ecryptfs_opt_fn_cipher: | 387 | case ecryptfs_opt_fn_cipher: |
387 | fn_cipher_name_src = args[0].from; | 388 | fn_cipher_name_src = args[0].from; |
388 | fn_cipher_name_dst = | 389 | fn_cipher_name_dst = |
389 | mount_crypt_stat->global_default_fn_cipher_name; | 390 | mount_crypt_stat->global_default_fn_cipher_name; |
390 | strncpy(fn_cipher_name_dst, fn_cipher_name_src, | 391 | strncpy(fn_cipher_name_dst, fn_cipher_name_src, |
391 | ECRYPTFS_MAX_CIPHER_NAME_SIZE); | 392 | ECRYPTFS_MAX_CIPHER_NAME_SIZE); |
392 | mount_crypt_stat->global_default_fn_cipher_name[ | 393 | mount_crypt_stat->global_default_fn_cipher_name[ |
393 | ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0'; | 394 | ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0'; |
394 | fn_cipher_name_set = 1; | 395 | fn_cipher_name_set = 1; |
395 | break; | 396 | break; |
396 | case ecryptfs_opt_fn_cipher_key_bytes: | 397 | case ecryptfs_opt_fn_cipher_key_bytes: |
397 | fn_cipher_key_bytes_src = args[0].from; | 398 | fn_cipher_key_bytes_src = args[0].from; |
398 | fn_cipher_key_bytes = | 399 | fn_cipher_key_bytes = |
399 | (int)simple_strtol(fn_cipher_key_bytes_src, | 400 | (int)simple_strtol(fn_cipher_key_bytes_src, |
400 | &fn_cipher_key_bytes_src, 0); | 401 | &fn_cipher_key_bytes_src, 0); |
401 | mount_crypt_stat->global_default_fn_cipher_key_bytes = | 402 | mount_crypt_stat->global_default_fn_cipher_key_bytes = |
402 | fn_cipher_key_bytes; | 403 | fn_cipher_key_bytes; |
403 | fn_cipher_key_bytes_set = 1; | 404 | fn_cipher_key_bytes_set = 1; |
405 | break; | ||
406 | case ecryptfs_opt_unlink_sigs: | ||
407 | mount_crypt_stat->flags |= ECRYPTFS_UNLINK_SIGS; | ||
404 | break; | 408 | break; |
405 | case ecryptfs_opt_err: | 409 | case ecryptfs_opt_err: |
406 | default: | 410 | default: |
407 | printk(KERN_WARNING | 411 | printk(KERN_WARNING |
408 | "%s: eCryptfs: unrecognized option [%s]\n", | 412 | "%s: eCryptfs: unrecognized option [%s]\n", |
409 | __func__, p); | 413 | __func__, p); |
410 | } | 414 | } |
411 | } | 415 | } |
412 | if (!sig_set) { | 416 | if (!sig_set) { |
413 | rc = -EINVAL; | 417 | rc = -EINVAL; |
414 | ecryptfs_printk(KERN_ERR, "You must supply at least one valid " | 418 | ecryptfs_printk(KERN_ERR, "You must supply at least one valid " |
415 | "auth tok signature as a mount " | 419 | "auth tok signature as a mount " |
416 | "parameter; see the eCryptfs README\n"); | 420 | "parameter; see the eCryptfs README\n"); |
417 | goto out; | 421 | goto out; |
418 | } | 422 | } |
419 | if (!cipher_name_set) { | 423 | if (!cipher_name_set) { |
420 | int cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER); | 424 | int cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER); |
421 | 425 | ||
422 | BUG_ON(cipher_name_len >= ECRYPTFS_MAX_CIPHER_NAME_SIZE); | 426 | BUG_ON(cipher_name_len >= ECRYPTFS_MAX_CIPHER_NAME_SIZE); |
423 | strcpy(mount_crypt_stat->global_default_cipher_name, | 427 | strcpy(mount_crypt_stat->global_default_cipher_name, |
424 | ECRYPTFS_DEFAULT_CIPHER); | 428 | ECRYPTFS_DEFAULT_CIPHER); |
425 | } | 429 | } |
426 | if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) | 430 | if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) |
427 | && !fn_cipher_name_set) | 431 | && !fn_cipher_name_set) |
428 | strcpy(mount_crypt_stat->global_default_fn_cipher_name, | 432 | strcpy(mount_crypt_stat->global_default_fn_cipher_name, |
429 | mount_crypt_stat->global_default_cipher_name); | 433 | mount_crypt_stat->global_default_cipher_name); |
430 | if (!cipher_key_bytes_set) | 434 | if (!cipher_key_bytes_set) |
431 | mount_crypt_stat->global_default_cipher_key_size = 0; | 435 | mount_crypt_stat->global_default_cipher_key_size = 0; |
432 | if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) | 436 | if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) |
433 | && !fn_cipher_key_bytes_set) | 437 | && !fn_cipher_key_bytes_set) |
434 | mount_crypt_stat->global_default_fn_cipher_key_bytes = | 438 | mount_crypt_stat->global_default_fn_cipher_key_bytes = |
435 | mount_crypt_stat->global_default_cipher_key_size; | 439 | mount_crypt_stat->global_default_cipher_key_size; |
436 | mutex_lock(&key_tfm_list_mutex); | 440 | mutex_lock(&key_tfm_list_mutex); |
437 | if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name, | 441 | if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name, |
438 | NULL)) { | 442 | NULL)) { |
439 | rc = ecryptfs_add_new_key_tfm( | 443 | rc = ecryptfs_add_new_key_tfm( |
440 | NULL, mount_crypt_stat->global_default_cipher_name, | 444 | NULL, mount_crypt_stat->global_default_cipher_name, |
441 | mount_crypt_stat->global_default_cipher_key_size); | 445 | mount_crypt_stat->global_default_cipher_key_size); |
442 | if (rc) { | 446 | if (rc) { |
443 | printk(KERN_ERR "Error attempting to initialize " | 447 | printk(KERN_ERR "Error attempting to initialize " |
444 | "cipher with name = [%s] and key size = [%td]; " | 448 | "cipher with name = [%s] and key size = [%td]; " |
445 | "rc = [%d]\n", | 449 | "rc = [%d]\n", |
446 | mount_crypt_stat->global_default_cipher_name, | 450 | mount_crypt_stat->global_default_cipher_name, |
447 | mount_crypt_stat->global_default_cipher_key_size, | 451 | mount_crypt_stat->global_default_cipher_key_size, |
448 | rc); | 452 | rc); |
449 | rc = -EINVAL; | 453 | rc = -EINVAL; |
450 | mutex_unlock(&key_tfm_list_mutex); | 454 | mutex_unlock(&key_tfm_list_mutex); |
451 | goto out; | 455 | goto out; |
452 | } | 456 | } |
453 | } | 457 | } |
454 | if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) | 458 | if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) |
455 | && !ecryptfs_tfm_exists( | 459 | && !ecryptfs_tfm_exists( |
456 | mount_crypt_stat->global_default_fn_cipher_name, NULL)) { | 460 | mount_crypt_stat->global_default_fn_cipher_name, NULL)) { |
457 | rc = ecryptfs_add_new_key_tfm( | 461 | rc = ecryptfs_add_new_key_tfm( |
458 | NULL, mount_crypt_stat->global_default_fn_cipher_name, | 462 | NULL, mount_crypt_stat->global_default_fn_cipher_name, |
459 | mount_crypt_stat->global_default_fn_cipher_key_bytes); | 463 | mount_crypt_stat->global_default_fn_cipher_key_bytes); |
460 | if (rc) { | 464 | if (rc) { |
461 | printk(KERN_ERR "Error attempting to initialize " | 465 | printk(KERN_ERR "Error attempting to initialize " |
462 | "cipher with name = [%s] and key size = [%td]; " | 466 | "cipher with name = [%s] and key size = [%td]; " |
463 | "rc = [%d]\n", | 467 | "rc = [%d]\n", |
464 | mount_crypt_stat->global_default_fn_cipher_name, | 468 | mount_crypt_stat->global_default_fn_cipher_name, |
465 | mount_crypt_stat->global_default_fn_cipher_key_bytes, | 469 | mount_crypt_stat->global_default_fn_cipher_key_bytes, |
466 | rc); | 470 | rc); |
467 | rc = -EINVAL; | 471 | rc = -EINVAL; |
468 | mutex_unlock(&key_tfm_list_mutex); | 472 | mutex_unlock(&key_tfm_list_mutex); |
469 | goto out; | 473 | goto out; |
470 | } | 474 | } |
471 | } | 475 | } |
472 | mutex_unlock(&key_tfm_list_mutex); | 476 | mutex_unlock(&key_tfm_list_mutex); |
473 | rc = ecryptfs_init_global_auth_toks(mount_crypt_stat); | 477 | rc = ecryptfs_init_global_auth_toks(mount_crypt_stat); |
474 | if (rc) | 478 | if (rc) |
475 | printk(KERN_WARNING "One or more global auth toks could not " | 479 | printk(KERN_WARNING "One or more global auth toks could not " |
476 | "properly register; rc = [%d]\n", rc); | 480 | "properly register; rc = [%d]\n", rc); |
477 | out: | 481 | out: |
478 | return rc; | 482 | return rc; |
479 | } | 483 | } |
480 | 484 | ||
481 | struct kmem_cache *ecryptfs_sb_info_cache; | 485 | struct kmem_cache *ecryptfs_sb_info_cache; |
482 | 486 | ||
483 | /** | 487 | /** |
484 | * ecryptfs_fill_super | 488 | * ecryptfs_fill_super |
485 | * @sb: The ecryptfs super block | 489 | * @sb: The ecryptfs super block |
486 | * @raw_data: The options passed to mount | 490 | * @raw_data: The options passed to mount |
487 | * @silent: Not used but required by function prototype | 491 | * @silent: Not used but required by function prototype |
488 | * | 492 | * |
489 | * Sets up what we can of the sb, rest is done in ecryptfs_read_super | 493 | * Sets up what we can of the sb, rest is done in ecryptfs_read_super |
490 | * | 494 | * |
491 | * Returns zero on success; non-zero otherwise | 495 | * Returns zero on success; non-zero otherwise |
492 | */ | 496 | */ |
493 | static int | 497 | static int |
494 | ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent) | 498 | ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent) |
495 | { | 499 | { |
496 | int rc = 0; | 500 | int rc = 0; |
497 | 501 | ||
498 | /* Released in ecryptfs_put_super() */ | 502 | /* Released in ecryptfs_put_super() */ |
499 | ecryptfs_set_superblock_private(sb, | 503 | ecryptfs_set_superblock_private(sb, |
500 | kmem_cache_zalloc(ecryptfs_sb_info_cache, | 504 | kmem_cache_zalloc(ecryptfs_sb_info_cache, |
501 | GFP_KERNEL)); | 505 | GFP_KERNEL)); |
502 | if (!ecryptfs_superblock_to_private(sb)) { | 506 | if (!ecryptfs_superblock_to_private(sb)) { |
503 | ecryptfs_printk(KERN_WARNING, "Out of memory\n"); | 507 | ecryptfs_printk(KERN_WARNING, "Out of memory\n"); |
504 | rc = -ENOMEM; | 508 | rc = -ENOMEM; |
505 | goto out; | 509 | goto out; |
506 | } | 510 | } |
507 | sb->s_op = &ecryptfs_sops; | 511 | sb->s_op = &ecryptfs_sops; |
508 | /* Released through deactivate_super(sb) from get_sb_nodev */ | 512 | /* Released through deactivate_super(sb) from get_sb_nodev */ |
509 | sb->s_root = d_alloc(NULL, &(const struct qstr) { | 513 | sb->s_root = d_alloc(NULL, &(const struct qstr) { |
510 | .hash = 0,.name = "/",.len = 1}); | 514 | .hash = 0,.name = "/",.len = 1}); |
511 | if (!sb->s_root) { | 515 | if (!sb->s_root) { |
512 | ecryptfs_printk(KERN_ERR, "d_alloc failed\n"); | 516 | ecryptfs_printk(KERN_ERR, "d_alloc failed\n"); |
513 | rc = -ENOMEM; | 517 | rc = -ENOMEM; |
514 | goto out; | 518 | goto out; |
515 | } | 519 | } |
516 | sb->s_root->d_op = &ecryptfs_dops; | 520 | sb->s_root->d_op = &ecryptfs_dops; |
517 | sb->s_root->d_sb = sb; | 521 | sb->s_root->d_sb = sb; |
518 | sb->s_root->d_parent = sb->s_root; | 522 | sb->s_root->d_parent = sb->s_root; |
519 | /* Released in d_release when dput(sb->s_root) is called */ | 523 | /* Released in d_release when dput(sb->s_root) is called */ |
520 | /* through deactivate_super(sb) from get_sb_nodev() */ | 524 | /* through deactivate_super(sb) from get_sb_nodev() */ |
521 | ecryptfs_set_dentry_private(sb->s_root, | 525 | ecryptfs_set_dentry_private(sb->s_root, |
522 | kmem_cache_zalloc(ecryptfs_dentry_info_cache, | 526 | kmem_cache_zalloc(ecryptfs_dentry_info_cache, |
523 | GFP_KERNEL)); | 527 | GFP_KERNEL)); |
524 | if (!ecryptfs_dentry_to_private(sb->s_root)) { | 528 | if (!ecryptfs_dentry_to_private(sb->s_root)) { |
525 | ecryptfs_printk(KERN_ERR, | 529 | ecryptfs_printk(KERN_ERR, |
526 | "dentry_info_cache alloc failed\n"); | 530 | "dentry_info_cache alloc failed\n"); |
527 | rc = -ENOMEM; | 531 | rc = -ENOMEM; |
528 | goto out; | 532 | goto out; |
529 | } | 533 | } |
530 | rc = 0; | 534 | rc = 0; |
531 | out: | 535 | out: |
532 | /* Should be able to rely on deactivate_super called from | 536 | /* Should be able to rely on deactivate_super called from |
533 | * get_sb_nodev */ | 537 | * get_sb_nodev */ |
534 | return rc; | 538 | return rc; |
535 | } | 539 | } |
536 | 540 | ||
537 | /** | 541 | /** |
538 | * ecryptfs_read_super | 542 | * ecryptfs_read_super |
539 | * @sb: The ecryptfs super block | 543 | * @sb: The ecryptfs super block |
540 | * @dev_name: The path to mount over | 544 | * @dev_name: The path to mount over |
541 | * | 545 | * |
542 | * Read the super block of the lower filesystem, and use | 546 | * Read the super block of the lower filesystem, and use |
543 | * ecryptfs_interpose to create our initial inode and super block | 547 | * ecryptfs_interpose to create our initial inode and super block |
544 | * struct. | 548 | * struct. |
545 | */ | 549 | */ |
546 | static int ecryptfs_read_super(struct super_block *sb, const char *dev_name) | 550 | static int ecryptfs_read_super(struct super_block *sb, const char *dev_name) |
547 | { | 551 | { |
548 | struct path path; | 552 | struct path path; |
549 | int rc; | 553 | int rc; |
550 | 554 | ||
551 | rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); | 555 | rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); |
552 | if (rc) { | 556 | if (rc) { |
553 | ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n"); | 557 | ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n"); |
554 | goto out; | 558 | goto out; |
555 | } | 559 | } |
556 | ecryptfs_set_superblock_lower(sb, path.dentry->d_sb); | 560 | ecryptfs_set_superblock_lower(sb, path.dentry->d_sb); |
557 | sb->s_maxbytes = path.dentry->d_sb->s_maxbytes; | 561 | sb->s_maxbytes = path.dentry->d_sb->s_maxbytes; |
558 | sb->s_blocksize = path.dentry->d_sb->s_blocksize; | 562 | sb->s_blocksize = path.dentry->d_sb->s_blocksize; |
559 | ecryptfs_set_dentry_lower(sb->s_root, path.dentry); | 563 | ecryptfs_set_dentry_lower(sb->s_root, path.dentry); |
560 | ecryptfs_set_dentry_lower_mnt(sb->s_root, path.mnt); | 564 | ecryptfs_set_dentry_lower_mnt(sb->s_root, path.mnt); |
561 | rc = ecryptfs_interpose(path.dentry, sb->s_root, sb, 0); | 565 | rc = ecryptfs_interpose(path.dentry, sb->s_root, sb, 0); |
562 | if (rc) | 566 | if (rc) |
563 | goto out_free; | 567 | goto out_free; |
564 | rc = 0; | 568 | rc = 0; |
565 | goto out; | 569 | goto out; |
566 | out_free: | 570 | out_free: |
567 | path_put(&path); | 571 | path_put(&path); |
568 | out: | 572 | out: |
569 | return rc; | 573 | return rc; |
570 | } | 574 | } |
571 | 575 | ||
572 | /** | 576 | /** |
573 | * ecryptfs_get_sb | 577 | * ecryptfs_get_sb |
574 | * @fs_type | 578 | * @fs_type |
575 | * @flags | 579 | * @flags |
576 | * @dev_name: The path to mount over | 580 | * @dev_name: The path to mount over |
577 | * @raw_data: The options passed into the kernel | 581 | * @raw_data: The options passed into the kernel |
578 | * | 582 | * |
579 | * The whole ecryptfs_get_sb process is broken into 4 functions: | 583 | * The whole ecryptfs_get_sb process is broken into 4 functions: |
580 | * ecryptfs_parse_options(): handle options passed to ecryptfs, if any | 584 | * ecryptfs_parse_options(): handle options passed to ecryptfs, if any |
581 | * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block | 585 | * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block |
582 | * with as much information as it can before needing | 586 | * with as much information as it can before needing |
583 | * the lower filesystem. | 587 | * the lower filesystem. |
584 | * ecryptfs_read_super(): this accesses the lower filesystem and uses | 588 | * ecryptfs_read_super(): this accesses the lower filesystem and uses |
585 | * ecryptfs_interpolate to perform most of the linking | 589 | * ecryptfs_interpolate to perform most of the linking |
586 | * ecryptfs_interpolate(): links the lower filesystem into ecryptfs | 590 | * ecryptfs_interpolate(): links the lower filesystem into ecryptfs |
587 | */ | 591 | */ |
588 | static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, | 592 | static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, |
589 | const char *dev_name, void *raw_data, | 593 | const char *dev_name, void *raw_data, |
590 | struct vfsmount *mnt) | 594 | struct vfsmount *mnt) |
591 | { | 595 | { |
592 | int rc; | 596 | int rc; |
593 | struct super_block *sb; | 597 | struct super_block *sb; |
594 | 598 | ||
595 | rc = get_sb_nodev(fs_type, flags, raw_data, ecryptfs_fill_super, mnt); | 599 | rc = get_sb_nodev(fs_type, flags, raw_data, ecryptfs_fill_super, mnt); |
596 | if (rc < 0) { | 600 | if (rc < 0) { |
597 | printk(KERN_ERR "Getting sb failed; rc = [%d]\n", rc); | 601 | printk(KERN_ERR "Getting sb failed; rc = [%d]\n", rc); |
598 | goto out; | 602 | goto out; |
599 | } | 603 | } |
600 | sb = mnt->mnt_sb; | 604 | sb = mnt->mnt_sb; |
601 | rc = ecryptfs_parse_options(sb, raw_data); | 605 | rc = ecryptfs_parse_options(sb, raw_data); |
602 | if (rc) { | 606 | if (rc) { |
603 | printk(KERN_ERR "Error parsing options; rc = [%d]\n", rc); | 607 | printk(KERN_ERR "Error parsing options; rc = [%d]\n", rc); |
604 | goto out_abort; | 608 | goto out_abort; |
605 | } | 609 | } |
606 | rc = ecryptfs_read_super(sb, dev_name); | 610 | rc = ecryptfs_read_super(sb, dev_name); |
607 | if (rc) { | 611 | if (rc) { |
608 | printk(KERN_ERR "Reading sb failed; rc = [%d]\n", rc); | 612 | printk(KERN_ERR "Reading sb failed; rc = [%d]\n", rc); |
609 | goto out_abort; | 613 | goto out_abort; |
610 | } | 614 | } |
611 | goto out; | 615 | goto out; |
612 | out_abort: | 616 | out_abort: |
613 | dput(sb->s_root); | 617 | dput(sb->s_root); |
614 | up_write(&sb->s_umount); | 618 | up_write(&sb->s_umount); |
615 | deactivate_super(sb); | 619 | deactivate_super(sb); |
616 | out: | 620 | out: |
617 | return rc; | 621 | return rc; |
618 | } | 622 | } |
619 | 623 | ||
620 | /** | 624 | /** |
621 | * ecryptfs_kill_block_super | 625 | * ecryptfs_kill_block_super |
622 | * @sb: The ecryptfs super block | 626 | * @sb: The ecryptfs super block |
623 | * | 627 | * |
624 | * Used to bring the superblock down and free the private data. | 628 | * Used to bring the superblock down and free the private data. |
625 | * Private data is free'd in ecryptfs_put_super() | 629 | * Private data is free'd in ecryptfs_put_super() |
626 | */ | 630 | */ |
627 | static void ecryptfs_kill_block_super(struct super_block *sb) | 631 | static void ecryptfs_kill_block_super(struct super_block *sb) |
628 | { | 632 | { |
629 | generic_shutdown_super(sb); | 633 | generic_shutdown_super(sb); |
630 | } | 634 | } |
631 | 635 | ||
632 | static struct file_system_type ecryptfs_fs_type = { | 636 | static struct file_system_type ecryptfs_fs_type = { |
633 | .owner = THIS_MODULE, | 637 | .owner = THIS_MODULE, |
634 | .name = "ecryptfs", | 638 | .name = "ecryptfs", |
635 | .get_sb = ecryptfs_get_sb, | 639 | .get_sb = ecryptfs_get_sb, |
636 | .kill_sb = ecryptfs_kill_block_super, | 640 | .kill_sb = ecryptfs_kill_block_super, |
637 | .fs_flags = 0 | 641 | .fs_flags = 0 |
638 | }; | 642 | }; |
639 | 643 | ||
640 | /** | 644 | /** |
641 | * inode_info_init_once | 645 | * inode_info_init_once |
642 | * | 646 | * |
643 | * Initializes the ecryptfs_inode_info_cache when it is created | 647 | * Initializes the ecryptfs_inode_info_cache when it is created |
644 | */ | 648 | */ |
645 | static void | 649 | static void |
646 | inode_info_init_once(void *vptr) | 650 | inode_info_init_once(void *vptr) |
647 | { | 651 | { |
648 | struct ecryptfs_inode_info *ei = (struct ecryptfs_inode_info *)vptr; | 652 | struct ecryptfs_inode_info *ei = (struct ecryptfs_inode_info *)vptr; |
649 | 653 | ||
650 | inode_init_once(&ei->vfs_inode); | 654 | inode_init_once(&ei->vfs_inode); |
651 | } | 655 | } |
652 | 656 | ||
653 | static struct ecryptfs_cache_info { | 657 | static struct ecryptfs_cache_info { |
654 | struct kmem_cache **cache; | 658 | struct kmem_cache **cache; |
655 | const char *name; | 659 | const char *name; |
656 | size_t size; | 660 | size_t size; |
657 | void (*ctor)(void *obj); | 661 | void (*ctor)(void *obj); |
658 | } ecryptfs_cache_infos[] = { | 662 | } ecryptfs_cache_infos[] = { |
659 | { | 663 | { |
660 | .cache = &ecryptfs_auth_tok_list_item_cache, | 664 | .cache = &ecryptfs_auth_tok_list_item_cache, |
661 | .name = "ecryptfs_auth_tok_list_item", | 665 | .name = "ecryptfs_auth_tok_list_item", |
662 | .size = sizeof(struct ecryptfs_auth_tok_list_item), | 666 | .size = sizeof(struct ecryptfs_auth_tok_list_item), |
663 | }, | 667 | }, |
664 | { | 668 | { |
665 | .cache = &ecryptfs_file_info_cache, | 669 | .cache = &ecryptfs_file_info_cache, |
666 | .name = "ecryptfs_file_cache", | 670 | .name = "ecryptfs_file_cache", |
667 | .size = sizeof(struct ecryptfs_file_info), | 671 | .size = sizeof(struct ecryptfs_file_info), |
668 | }, | 672 | }, |
669 | { | 673 | { |
670 | .cache = &ecryptfs_dentry_info_cache, | 674 | .cache = &ecryptfs_dentry_info_cache, |
671 | .name = "ecryptfs_dentry_info_cache", | 675 | .name = "ecryptfs_dentry_info_cache", |
672 | .size = sizeof(struct ecryptfs_dentry_info), | 676 | .size = sizeof(struct ecryptfs_dentry_info), |
673 | }, | 677 | }, |
674 | { | 678 | { |
675 | .cache = &ecryptfs_inode_info_cache, | 679 | .cache = &ecryptfs_inode_info_cache, |
676 | .name = "ecryptfs_inode_cache", | 680 | .name = "ecryptfs_inode_cache", |
677 | .size = sizeof(struct ecryptfs_inode_info), | 681 | .size = sizeof(struct ecryptfs_inode_info), |
678 | .ctor = inode_info_init_once, | 682 | .ctor = inode_info_init_once, |
679 | }, | 683 | }, |
680 | { | 684 | { |
681 | .cache = &ecryptfs_sb_info_cache, | 685 | .cache = &ecryptfs_sb_info_cache, |
682 | .name = "ecryptfs_sb_cache", | 686 | .name = "ecryptfs_sb_cache", |
683 | .size = sizeof(struct ecryptfs_sb_info), | 687 | .size = sizeof(struct ecryptfs_sb_info), |
684 | }, | 688 | }, |
685 | { | 689 | { |
686 | .cache = &ecryptfs_header_cache_1, | 690 | .cache = &ecryptfs_header_cache_1, |
687 | .name = "ecryptfs_headers_1", | 691 | .name = "ecryptfs_headers_1", |
688 | .size = PAGE_CACHE_SIZE, | 692 | .size = PAGE_CACHE_SIZE, |
689 | }, | 693 | }, |
690 | { | 694 | { |
691 | .cache = &ecryptfs_header_cache_2, | 695 | .cache = &ecryptfs_header_cache_2, |
692 | .name = "ecryptfs_headers_2", | 696 | .name = "ecryptfs_headers_2", |
693 | .size = PAGE_CACHE_SIZE, | 697 | .size = PAGE_CACHE_SIZE, |
694 | }, | 698 | }, |
695 | { | 699 | { |
696 | .cache = &ecryptfs_xattr_cache, | 700 | .cache = &ecryptfs_xattr_cache, |
697 | .name = "ecryptfs_xattr_cache", | 701 | .name = "ecryptfs_xattr_cache", |
698 | .size = PAGE_CACHE_SIZE, | 702 | .size = PAGE_CACHE_SIZE, |
699 | }, | 703 | }, |
700 | { | 704 | { |
701 | .cache = &ecryptfs_key_record_cache, | 705 | .cache = &ecryptfs_key_record_cache, |
702 | .name = "ecryptfs_key_record_cache", | 706 | .name = "ecryptfs_key_record_cache", |
703 | .size = sizeof(struct ecryptfs_key_record), | 707 | .size = sizeof(struct ecryptfs_key_record), |
704 | }, | 708 | }, |
705 | { | 709 | { |
706 | .cache = &ecryptfs_key_sig_cache, | 710 | .cache = &ecryptfs_key_sig_cache, |
707 | .name = "ecryptfs_key_sig_cache", | 711 | .name = "ecryptfs_key_sig_cache", |
708 | .size = sizeof(struct ecryptfs_key_sig), | 712 | .size = sizeof(struct ecryptfs_key_sig), |
709 | }, | 713 | }, |
710 | { | 714 | { |
711 | .cache = &ecryptfs_global_auth_tok_cache, | 715 | .cache = &ecryptfs_global_auth_tok_cache, |
712 | .name = "ecryptfs_global_auth_tok_cache", | 716 | .name = "ecryptfs_global_auth_tok_cache", |
713 | .size = sizeof(struct ecryptfs_global_auth_tok), | 717 | .size = sizeof(struct ecryptfs_global_auth_tok), |
714 | }, | 718 | }, |
715 | { | 719 | { |
716 | .cache = &ecryptfs_key_tfm_cache, | 720 | .cache = &ecryptfs_key_tfm_cache, |
717 | .name = "ecryptfs_key_tfm_cache", | 721 | .name = "ecryptfs_key_tfm_cache", |
718 | .size = sizeof(struct ecryptfs_key_tfm), | 722 | .size = sizeof(struct ecryptfs_key_tfm), |
719 | }, | 723 | }, |
720 | { | 724 | { |
721 | .cache = &ecryptfs_open_req_cache, | 725 | .cache = &ecryptfs_open_req_cache, |
722 | .name = "ecryptfs_open_req_cache", | 726 | .name = "ecryptfs_open_req_cache", |
723 | .size = sizeof(struct ecryptfs_open_req), | 727 | .size = sizeof(struct ecryptfs_open_req), |
724 | }, | 728 | }, |
725 | }; | 729 | }; |
726 | 730 | ||
727 | static void ecryptfs_free_kmem_caches(void) | 731 | static void ecryptfs_free_kmem_caches(void) |
728 | { | 732 | { |
729 | int i; | 733 | int i; |
730 | 734 | ||
731 | for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) { | 735 | for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) { |
732 | struct ecryptfs_cache_info *info; | 736 | struct ecryptfs_cache_info *info; |
733 | 737 | ||
734 | info = &ecryptfs_cache_infos[i]; | 738 | info = &ecryptfs_cache_infos[i]; |
735 | if (*(info->cache)) | 739 | if (*(info->cache)) |
736 | kmem_cache_destroy(*(info->cache)); | 740 | kmem_cache_destroy(*(info->cache)); |
737 | } | 741 | } |
738 | } | 742 | } |
739 | 743 | ||
740 | /** | 744 | /** |
741 | * ecryptfs_init_kmem_caches | 745 | * ecryptfs_init_kmem_caches |
742 | * | 746 | * |
743 | * Returns zero on success; non-zero otherwise | 747 | * Returns zero on success; non-zero otherwise |
744 | */ | 748 | */ |
745 | static int ecryptfs_init_kmem_caches(void) | 749 | static int ecryptfs_init_kmem_caches(void) |
746 | { | 750 | { |
747 | int i; | 751 | int i; |
748 | 752 | ||
749 | for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) { | 753 | for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) { |
750 | struct ecryptfs_cache_info *info; | 754 | struct ecryptfs_cache_info *info; |
751 | 755 | ||
752 | info = &ecryptfs_cache_infos[i]; | 756 | info = &ecryptfs_cache_infos[i]; |
753 | *(info->cache) = kmem_cache_create(info->name, info->size, | 757 | *(info->cache) = kmem_cache_create(info->name, info->size, |
754 | 0, SLAB_HWCACHE_ALIGN, info->ctor); | 758 | 0, SLAB_HWCACHE_ALIGN, info->ctor); |
755 | if (!*(info->cache)) { | 759 | if (!*(info->cache)) { |
756 | ecryptfs_free_kmem_caches(); | 760 | ecryptfs_free_kmem_caches(); |
757 | ecryptfs_printk(KERN_WARNING, "%s: " | 761 | ecryptfs_printk(KERN_WARNING, "%s: " |
758 | "kmem_cache_create failed\n", | 762 | "kmem_cache_create failed\n", |
759 | info->name); | 763 | info->name); |
760 | return -ENOMEM; | 764 | return -ENOMEM; |
761 | } | 765 | } |
762 | } | 766 | } |
763 | return 0; | 767 | return 0; |
764 | } | 768 | } |
765 | 769 | ||
766 | static struct kobject *ecryptfs_kobj; | 770 | static struct kobject *ecryptfs_kobj; |
767 | 771 | ||
768 | static ssize_t version_show(struct kobject *kobj, | 772 | static ssize_t version_show(struct kobject *kobj, |
769 | struct kobj_attribute *attr, char *buff) | 773 | struct kobj_attribute *attr, char *buff) |
770 | { | 774 | { |
771 | return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK); | 775 | return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK); |
772 | } | 776 | } |
773 | 777 | ||
774 | static struct kobj_attribute version_attr = __ATTR_RO(version); | 778 | static struct kobj_attribute version_attr = __ATTR_RO(version); |
775 | 779 | ||
776 | static struct attribute *attributes[] = { | 780 | static struct attribute *attributes[] = { |
777 | &version_attr.attr, | 781 | &version_attr.attr, |
778 | NULL, | 782 | NULL, |
779 | }; | 783 | }; |
780 | 784 | ||
781 | static struct attribute_group attr_group = { | 785 | static struct attribute_group attr_group = { |
782 | .attrs = attributes, | 786 | .attrs = attributes, |
783 | }; | 787 | }; |
784 | 788 | ||
785 | static int do_sysfs_registration(void) | 789 | static int do_sysfs_registration(void) |
786 | { | 790 | { |
787 | int rc; | 791 | int rc; |
788 | 792 | ||
789 | ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj); | 793 | ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj); |
790 | if (!ecryptfs_kobj) { | 794 | if (!ecryptfs_kobj) { |
791 | printk(KERN_ERR "Unable to create ecryptfs kset\n"); | 795 | printk(KERN_ERR "Unable to create ecryptfs kset\n"); |
792 | rc = -ENOMEM; | 796 | rc = -ENOMEM; |
793 | goto out; | 797 | goto out; |
794 | } | 798 | } |
795 | rc = sysfs_create_group(ecryptfs_kobj, &attr_group); | 799 | rc = sysfs_create_group(ecryptfs_kobj, &attr_group); |
796 | if (rc) { | 800 | if (rc) { |
797 | printk(KERN_ERR | 801 | printk(KERN_ERR |
798 | "Unable to create ecryptfs version attributes\n"); | 802 | "Unable to create ecryptfs version attributes\n"); |
799 | kobject_put(ecryptfs_kobj); | 803 | kobject_put(ecryptfs_kobj); |
800 | } | 804 | } |
801 | out: | 805 | out: |
802 | return rc; | 806 | return rc; |
803 | } | 807 | } |
804 | 808 | ||
805 | static void do_sysfs_unregistration(void) | 809 | static void do_sysfs_unregistration(void) |
806 | { | 810 | { |
807 | sysfs_remove_group(ecryptfs_kobj, &attr_group); | 811 | sysfs_remove_group(ecryptfs_kobj, &attr_group); |
808 | kobject_put(ecryptfs_kobj); | 812 | kobject_put(ecryptfs_kobj); |
809 | } | 813 | } |
810 | 814 | ||
811 | static int __init ecryptfs_init(void) | 815 | static int __init ecryptfs_init(void) |
812 | { | 816 | { |
813 | int rc; | 817 | int rc; |
814 | 818 | ||
815 | if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAGE_CACHE_SIZE) { | 819 | if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAGE_CACHE_SIZE) { |
816 | rc = -EINVAL; | 820 | rc = -EINVAL; |
817 | ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is " | 821 | ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is " |
818 | "larger than the host's page size, and so " | 822 | "larger than the host's page size, and so " |
819 | "eCryptfs cannot run on this system. The " | 823 | "eCryptfs cannot run on this system. The " |
820 | "default eCryptfs extent size is [%d] bytes; " | 824 | "default eCryptfs extent size is [%d] bytes; " |
821 | "the page size is [%d] bytes.\n", | 825 | "the page size is [%d] bytes.\n", |
822 | ECRYPTFS_DEFAULT_EXTENT_SIZE, PAGE_CACHE_SIZE); | 826 | ECRYPTFS_DEFAULT_EXTENT_SIZE, PAGE_CACHE_SIZE); |
823 | goto out; | 827 | goto out; |
824 | } | 828 | } |
825 | rc = ecryptfs_init_kmem_caches(); | 829 | rc = ecryptfs_init_kmem_caches(); |
826 | if (rc) { | 830 | if (rc) { |
827 | printk(KERN_ERR | 831 | printk(KERN_ERR |
828 | "Failed to allocate one or more kmem_cache objects\n"); | 832 | "Failed to allocate one or more kmem_cache objects\n"); |
829 | goto out; | 833 | goto out; |
830 | } | 834 | } |
831 | rc = register_filesystem(&ecryptfs_fs_type); | 835 | rc = register_filesystem(&ecryptfs_fs_type); |
832 | if (rc) { | 836 | if (rc) { |
833 | printk(KERN_ERR "Failed to register filesystem\n"); | 837 | printk(KERN_ERR "Failed to register filesystem\n"); |
834 | goto out_free_kmem_caches; | 838 | goto out_free_kmem_caches; |
835 | } | 839 | } |
836 | rc = do_sysfs_registration(); | 840 | rc = do_sysfs_registration(); |
837 | if (rc) { | 841 | if (rc) { |
838 | printk(KERN_ERR "sysfs registration failed\n"); | 842 | printk(KERN_ERR "sysfs registration failed\n"); |
839 | goto out_unregister_filesystem; | 843 | goto out_unregister_filesystem; |
840 | } | 844 | } |
841 | rc = ecryptfs_init_kthread(); | 845 | rc = ecryptfs_init_kthread(); |
842 | if (rc) { | 846 | if (rc) { |
843 | printk(KERN_ERR "%s: kthread initialization failed; " | 847 | printk(KERN_ERR "%s: kthread initialization failed; " |
844 | "rc = [%d]\n", __func__, rc); | 848 | "rc = [%d]\n", __func__, rc); |
845 | goto out_do_sysfs_unregistration; | 849 | goto out_do_sysfs_unregistration; |
846 | } | 850 | } |
847 | rc = ecryptfs_init_messaging(); | 851 | rc = ecryptfs_init_messaging(); |
848 | if (rc) { | 852 | if (rc) { |
849 | printk(KERN_ERR "Failure occured while attempting to " | 853 | printk(KERN_ERR "Failure occured while attempting to " |
850 | "initialize the communications channel to " | 854 | "initialize the communications channel to " |
851 | "ecryptfsd\n"); | 855 | "ecryptfsd\n"); |
852 | goto out_destroy_kthread; | 856 | goto out_destroy_kthread; |
853 | } | 857 | } |
854 | rc = ecryptfs_init_crypto(); | 858 | rc = ecryptfs_init_crypto(); |
855 | if (rc) { | 859 | if (rc) { |
856 | printk(KERN_ERR "Failure whilst attempting to init crypto; " | 860 | printk(KERN_ERR "Failure whilst attempting to init crypto; " |
857 | "rc = [%d]\n", rc); | 861 | "rc = [%d]\n", rc); |
858 | goto out_release_messaging; | 862 | goto out_release_messaging; |
859 | } | 863 | } |
860 | if (ecryptfs_verbosity > 0) | 864 | if (ecryptfs_verbosity > 0) |
861 | printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values " | 865 | printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values " |
862 | "will be written to the syslog!\n", ecryptfs_verbosity); | 866 | "will be written to the syslog!\n", ecryptfs_verbosity); |
863 | 867 | ||
864 | goto out; | 868 | goto out; |
865 | out_release_messaging: | 869 | out_release_messaging: |
866 | ecryptfs_release_messaging(); | 870 | ecryptfs_release_messaging(); |
867 | out_destroy_kthread: | 871 | out_destroy_kthread: |
868 | ecryptfs_destroy_kthread(); | 872 | ecryptfs_destroy_kthread(); |
869 | out_do_sysfs_unregistration: | 873 | out_do_sysfs_unregistration: |
870 | do_sysfs_unregistration(); | 874 | do_sysfs_unregistration(); |
871 | out_unregister_filesystem: | 875 | out_unregister_filesystem: |
872 | unregister_filesystem(&ecryptfs_fs_type); | 876 | unregister_filesystem(&ecryptfs_fs_type); |
873 | out_free_kmem_caches: | 877 | out_free_kmem_caches: |
874 | ecryptfs_free_kmem_caches(); | 878 | ecryptfs_free_kmem_caches(); |
875 | out: | 879 | out: |
876 | return rc; | 880 | return rc; |
877 | } | 881 | } |
878 | 882 | ||
879 | static void __exit ecryptfs_exit(void) | 883 | static void __exit ecryptfs_exit(void) |
880 | { | 884 | { |
881 | int rc; | 885 | int rc; |
882 | 886 | ||
883 | rc = ecryptfs_destroy_crypto(); | 887 | rc = ecryptfs_destroy_crypto(); |
884 | if (rc) | 888 | if (rc) |
885 | printk(KERN_ERR "Failure whilst attempting to destroy crypto; " | 889 | printk(KERN_ERR "Failure whilst attempting to destroy crypto; " |
886 | "rc = [%d]\n", rc); | 890 | "rc = [%d]\n", rc); |
887 | ecryptfs_release_messaging(); | 891 | ecryptfs_release_messaging(); |
888 | ecryptfs_destroy_kthread(); | 892 | ecryptfs_destroy_kthread(); |
889 | do_sysfs_unregistration(); | 893 | do_sysfs_unregistration(); |
890 | unregister_filesystem(&ecryptfs_fs_type); | 894 | unregister_filesystem(&ecryptfs_fs_type); |
891 | ecryptfs_free_kmem_caches(); | 895 | ecryptfs_free_kmem_caches(); |
892 | } | 896 | } |
893 | 897 | ||
894 | MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>"); | 898 | MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>"); |
895 | MODULE_DESCRIPTION("eCryptfs"); | 899 | MODULE_DESCRIPTION("eCryptfs"); |
896 | 900 | ||
897 | MODULE_LICENSE("GPL"); | 901 | MODULE_LICENSE("GPL"); |
898 | 902 | ||
899 | module_init(ecryptfs_init) | 903 | module_init(ecryptfs_init) |
900 | module_exit(ecryptfs_exit) | 904 | module_exit(ecryptfs_exit) |
901 | 905 |
fs/ecryptfs/super.c
1 | /** | 1 | /** |
2 | * eCryptfs: Linux filesystem encryption layer | 2 | * eCryptfs: Linux filesystem encryption layer |
3 | * | 3 | * |
4 | * Copyright (C) 1997-2003 Erez Zadok | 4 | * Copyright (C) 1997-2003 Erez Zadok |
5 | * Copyright (C) 2001-2003 Stony Brook University | 5 | * Copyright (C) 2001-2003 Stony Brook University |
6 | * Copyright (C) 2004-2006 International Business Machines Corp. | 6 | * Copyright (C) 2004-2006 International Business Machines Corp. |
7 | * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> | 7 | * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> |
8 | * Michael C. Thompson <mcthomps@us.ibm.com> | 8 | * Michael C. Thompson <mcthomps@us.ibm.com> |
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or | 10 | * This program is free software; you can redistribute it and/or |
11 | * modify it under the terms of the GNU General Public License as | 11 | * modify it under the terms of the GNU General Public License as |
12 | * published by the Free Software Foundation; either version 2 of the | 12 | * published by the Free Software Foundation; either version 2 of the |
13 | * License, or (at your option) any later version. | 13 | * License, or (at your option) any later version. |
14 | * | 14 | * |
15 | * This program is distributed in the hope that it will be useful, but | 15 | * This program is distributed in the hope that it will be useful, but |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 | * General Public License for more details. | 18 | * General Public License for more details. |
19 | * | 19 | * |
20 | * You should have received a copy of the GNU General Public License | 20 | * You should have received a copy of the GNU General Public License |
21 | * along with this program; if not, write to the Free Software | 21 | * along with this program; if not, write to the Free Software |
22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
23 | * 02111-1307, USA. | 23 | * 02111-1307, USA. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/fs.h> | 26 | #include <linux/fs.h> |
27 | #include <linux/mount.h> | 27 | #include <linux/mount.h> |
28 | #include <linux/key.h> | 28 | #include <linux/key.h> |
29 | #include <linux/seq_file.h> | 29 | #include <linux/seq_file.h> |
30 | #include <linux/file.h> | 30 | #include <linux/file.h> |
31 | #include <linux/crypto.h> | 31 | #include <linux/crypto.h> |
32 | #include "ecryptfs_kernel.h" | 32 | #include "ecryptfs_kernel.h" |
33 | 33 | ||
34 | struct kmem_cache *ecryptfs_inode_info_cache; | 34 | struct kmem_cache *ecryptfs_inode_info_cache; |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * ecryptfs_alloc_inode - allocate an ecryptfs inode | 37 | * ecryptfs_alloc_inode - allocate an ecryptfs inode |
38 | * @sb: Pointer to the ecryptfs super block | 38 | * @sb: Pointer to the ecryptfs super block |
39 | * | 39 | * |
40 | * Called to bring an inode into existence. | 40 | * Called to bring an inode into existence. |
41 | * | 41 | * |
42 | * Only handle allocation, setting up structures should be done in | 42 | * Only handle allocation, setting up structures should be done in |
43 | * ecryptfs_read_inode. This is because the kernel, between now and | 43 | * ecryptfs_read_inode. This is because the kernel, between now and |
44 | * then, will 0 out the private data pointer. | 44 | * then, will 0 out the private data pointer. |
45 | * | 45 | * |
46 | * Returns a pointer to a newly allocated inode, NULL otherwise | 46 | * Returns a pointer to a newly allocated inode, NULL otherwise |
47 | */ | 47 | */ |
48 | static struct inode *ecryptfs_alloc_inode(struct super_block *sb) | 48 | static struct inode *ecryptfs_alloc_inode(struct super_block *sb) |
49 | { | 49 | { |
50 | struct ecryptfs_inode_info *inode_info; | 50 | struct ecryptfs_inode_info *inode_info; |
51 | struct inode *inode = NULL; | 51 | struct inode *inode = NULL; |
52 | 52 | ||
53 | inode_info = kmem_cache_alloc(ecryptfs_inode_info_cache, GFP_KERNEL); | 53 | inode_info = kmem_cache_alloc(ecryptfs_inode_info_cache, GFP_KERNEL); |
54 | if (unlikely(!inode_info)) | 54 | if (unlikely(!inode_info)) |
55 | goto out; | 55 | goto out; |
56 | ecryptfs_init_crypt_stat(&inode_info->crypt_stat); | 56 | ecryptfs_init_crypt_stat(&inode_info->crypt_stat); |
57 | mutex_init(&inode_info->lower_file_mutex); | 57 | mutex_init(&inode_info->lower_file_mutex); |
58 | inode_info->lower_file = NULL; | 58 | inode_info->lower_file = NULL; |
59 | inode = &inode_info->vfs_inode; | 59 | inode = &inode_info->vfs_inode; |
60 | out: | 60 | out: |
61 | return inode; | 61 | return inode; |
62 | } | 62 | } |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * ecryptfs_destroy_inode | 65 | * ecryptfs_destroy_inode |
66 | * @inode: The ecryptfs inode | 66 | * @inode: The ecryptfs inode |
67 | * | 67 | * |
68 | * This is used during the final destruction of the inode. All | 68 | * This is used during the final destruction of the inode. All |
69 | * allocation of memory related to the inode, including allocated | 69 | * allocation of memory related to the inode, including allocated |
70 | * memory in the crypt_stat struct, will be released here. This | 70 | * memory in the crypt_stat struct, will be released here. This |
71 | * function also fput()'s the persistent file for the lower inode. | 71 | * function also fput()'s the persistent file for the lower inode. |
72 | * There should be no chance that this deallocation will be missed. | 72 | * There should be no chance that this deallocation will be missed. |
73 | */ | 73 | */ |
74 | static void ecryptfs_destroy_inode(struct inode *inode) | 74 | static void ecryptfs_destroy_inode(struct inode *inode) |
75 | { | 75 | { |
76 | struct ecryptfs_inode_info *inode_info; | 76 | struct ecryptfs_inode_info *inode_info; |
77 | 77 | ||
78 | inode_info = ecryptfs_inode_to_private(inode); | 78 | inode_info = ecryptfs_inode_to_private(inode); |
79 | mutex_lock(&inode_info->lower_file_mutex); | 79 | mutex_lock(&inode_info->lower_file_mutex); |
80 | if (inode_info->lower_file) { | 80 | if (inode_info->lower_file) { |
81 | struct dentry *lower_dentry = | 81 | struct dentry *lower_dentry = |
82 | inode_info->lower_file->f_dentry; | 82 | inode_info->lower_file->f_dentry; |
83 | 83 | ||
84 | BUG_ON(!lower_dentry); | 84 | BUG_ON(!lower_dentry); |
85 | if (lower_dentry->d_inode) { | 85 | if (lower_dentry->d_inode) { |
86 | fput(inode_info->lower_file); | 86 | fput(inode_info->lower_file); |
87 | inode_info->lower_file = NULL; | 87 | inode_info->lower_file = NULL; |
88 | d_drop(lower_dentry); | 88 | d_drop(lower_dentry); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | mutex_unlock(&inode_info->lower_file_mutex); | 91 | mutex_unlock(&inode_info->lower_file_mutex); |
92 | ecryptfs_destroy_crypt_stat(&inode_info->crypt_stat); | 92 | ecryptfs_destroy_crypt_stat(&inode_info->crypt_stat); |
93 | kmem_cache_free(ecryptfs_inode_info_cache, inode_info); | 93 | kmem_cache_free(ecryptfs_inode_info_cache, inode_info); |
94 | } | 94 | } |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * ecryptfs_init_inode | 97 | * ecryptfs_init_inode |
98 | * @inode: The ecryptfs inode | 98 | * @inode: The ecryptfs inode |
99 | * | 99 | * |
100 | * Set up the ecryptfs inode. | 100 | * Set up the ecryptfs inode. |
101 | */ | 101 | */ |
102 | void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode) | 102 | void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode) |
103 | { | 103 | { |
104 | ecryptfs_set_inode_lower(inode, lower_inode); | 104 | ecryptfs_set_inode_lower(inode, lower_inode); |
105 | inode->i_ino = lower_inode->i_ino; | 105 | inode->i_ino = lower_inode->i_ino; |
106 | inode->i_version++; | 106 | inode->i_version++; |
107 | inode->i_op = &ecryptfs_main_iops; | 107 | inode->i_op = &ecryptfs_main_iops; |
108 | inode->i_fop = &ecryptfs_main_fops; | 108 | inode->i_fop = &ecryptfs_main_fops; |
109 | inode->i_mapping->a_ops = &ecryptfs_aops; | 109 | inode->i_mapping->a_ops = &ecryptfs_aops; |
110 | } | 110 | } |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * ecryptfs_put_super | 113 | * ecryptfs_put_super |
114 | * @sb: Pointer to the ecryptfs super block | 114 | * @sb: Pointer to the ecryptfs super block |
115 | * | 115 | * |
116 | * Final actions when unmounting a file system. | 116 | * Final actions when unmounting a file system. |
117 | * This will handle deallocation and release of our private data. | 117 | * This will handle deallocation and release of our private data. |
118 | */ | 118 | */ |
119 | static void ecryptfs_put_super(struct super_block *sb) | 119 | static void ecryptfs_put_super(struct super_block *sb) |
120 | { | 120 | { |
121 | struct ecryptfs_sb_info *sb_info = ecryptfs_superblock_to_private(sb); | 121 | struct ecryptfs_sb_info *sb_info = ecryptfs_superblock_to_private(sb); |
122 | 122 | ||
123 | ecryptfs_destroy_mount_crypt_stat(&sb_info->mount_crypt_stat); | 123 | ecryptfs_destroy_mount_crypt_stat(&sb_info->mount_crypt_stat); |
124 | kmem_cache_free(ecryptfs_sb_info_cache, sb_info); | 124 | kmem_cache_free(ecryptfs_sb_info_cache, sb_info); |
125 | ecryptfs_set_superblock_private(sb, NULL); | 125 | ecryptfs_set_superblock_private(sb, NULL); |
126 | } | 126 | } |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * ecryptfs_statfs | 129 | * ecryptfs_statfs |
130 | * @sb: The ecryptfs super block | 130 | * @sb: The ecryptfs super block |
131 | * @buf: The struct kstatfs to fill in with stats | 131 | * @buf: The struct kstatfs to fill in with stats |
132 | * | 132 | * |
133 | * Get the filesystem statistics. Currently, we let this pass right through | 133 | * Get the filesystem statistics. Currently, we let this pass right through |
134 | * to the lower filesystem and take no action ourselves. | 134 | * to the lower filesystem and take no action ourselves. |
135 | */ | 135 | */ |
136 | static int ecryptfs_statfs(struct dentry *dentry, struct kstatfs *buf) | 136 | static int ecryptfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
137 | { | 137 | { |
138 | return vfs_statfs(ecryptfs_dentry_to_lower(dentry), buf); | 138 | return vfs_statfs(ecryptfs_dentry_to_lower(dentry), buf); |
139 | } | 139 | } |
140 | 140 | ||
141 | /** | 141 | /** |
142 | * ecryptfs_clear_inode | 142 | * ecryptfs_clear_inode |
143 | * @inode - The ecryptfs inode | 143 | * @inode - The ecryptfs inode |
144 | * | 144 | * |
145 | * Called by iput() when the inode reference count reached zero | 145 | * Called by iput() when the inode reference count reached zero |
146 | * and the inode is not hashed anywhere. Used to clear anything | 146 | * and the inode is not hashed anywhere. Used to clear anything |
147 | * that needs to be, before the inode is completely destroyed and put | 147 | * that needs to be, before the inode is completely destroyed and put |
148 | * on the inode free list. We use this to drop out reference to the | 148 | * on the inode free list. We use this to drop out reference to the |
149 | * lower inode. | 149 | * lower inode. |
150 | */ | 150 | */ |
151 | static void ecryptfs_clear_inode(struct inode *inode) | 151 | static void ecryptfs_clear_inode(struct inode *inode) |
152 | { | 152 | { |
153 | iput(ecryptfs_inode_to_lower(inode)); | 153 | iput(ecryptfs_inode_to_lower(inode)); |
154 | } | 154 | } |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * ecryptfs_show_options | 157 | * ecryptfs_show_options |
158 | * | 158 | * |
159 | * Prints the mount options for a given superblock. | 159 | * Prints the mount options for a given superblock. |
160 | * Returns zero; does not fail. | 160 | * Returns zero; does not fail. |
161 | */ | 161 | */ |
162 | static int ecryptfs_show_options(struct seq_file *m, struct vfsmount *mnt) | 162 | static int ecryptfs_show_options(struct seq_file *m, struct vfsmount *mnt) |
163 | { | 163 | { |
164 | struct super_block *sb = mnt->mnt_sb; | 164 | struct super_block *sb = mnt->mnt_sb; |
165 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = | 165 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = |
166 | &ecryptfs_superblock_to_private(sb)->mount_crypt_stat; | 166 | &ecryptfs_superblock_to_private(sb)->mount_crypt_stat; |
167 | struct ecryptfs_global_auth_tok *walker; | 167 | struct ecryptfs_global_auth_tok *walker; |
168 | 168 | ||
169 | mutex_lock(&mount_crypt_stat->global_auth_tok_list_mutex); | 169 | mutex_lock(&mount_crypt_stat->global_auth_tok_list_mutex); |
170 | list_for_each_entry(walker, | 170 | list_for_each_entry(walker, |
171 | &mount_crypt_stat->global_auth_tok_list, | 171 | &mount_crypt_stat->global_auth_tok_list, |
172 | mount_crypt_stat_list) { | 172 | mount_crypt_stat_list) { |
173 | if (walker->flags & ECRYPTFS_AUTH_TOK_FNEK) | 173 | if (walker->flags & ECRYPTFS_AUTH_TOK_FNEK) |
174 | seq_printf(m, ",ecryptfs_fnek_sig=%s", walker->sig); | 174 | seq_printf(m, ",ecryptfs_fnek_sig=%s", walker->sig); |
175 | else | 175 | else |
176 | seq_printf(m, ",ecryptfs_sig=%s", walker->sig); | 176 | seq_printf(m, ",ecryptfs_sig=%s", walker->sig); |
177 | } | 177 | } |
178 | mutex_unlock(&mount_crypt_stat->global_auth_tok_list_mutex); | 178 | mutex_unlock(&mount_crypt_stat->global_auth_tok_list_mutex); |
179 | 179 | ||
180 | seq_printf(m, ",ecryptfs_cipher=%s", | 180 | seq_printf(m, ",ecryptfs_cipher=%s", |
181 | mount_crypt_stat->global_default_cipher_name); | 181 | mount_crypt_stat->global_default_cipher_name); |
182 | 182 | ||
183 | if (mount_crypt_stat->global_default_cipher_key_size) | 183 | if (mount_crypt_stat->global_default_cipher_key_size) |
184 | seq_printf(m, ",ecryptfs_key_bytes=%zd", | 184 | seq_printf(m, ",ecryptfs_key_bytes=%zd", |
185 | mount_crypt_stat->global_default_cipher_key_size); | 185 | mount_crypt_stat->global_default_cipher_key_size); |
186 | if (mount_crypt_stat->flags & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED) | 186 | if (mount_crypt_stat->flags & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED) |
187 | seq_printf(m, ",ecryptfs_passthrough"); | 187 | seq_printf(m, ",ecryptfs_passthrough"); |
188 | if (mount_crypt_stat->flags & ECRYPTFS_XATTR_METADATA_ENABLED) | 188 | if (mount_crypt_stat->flags & ECRYPTFS_XATTR_METADATA_ENABLED) |
189 | seq_printf(m, ",ecryptfs_xattr_metadata"); | 189 | seq_printf(m, ",ecryptfs_xattr_metadata"); |
190 | if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) | 190 | if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) |
191 | seq_printf(m, ",ecryptfs_encrypted_view"); | 191 | seq_printf(m, ",ecryptfs_encrypted_view"); |
192 | if (mount_crypt_stat->flags & ECRYPTFS_UNLINK_SIGS) | ||
193 | seq_printf(m, ",ecryptfs_unlink_sigs"); | ||
192 | 194 | ||
193 | return 0; | 195 | return 0; |
194 | } | 196 | } |
195 | 197 | ||
196 | const struct super_operations ecryptfs_sops = { | 198 | const struct super_operations ecryptfs_sops = { |
197 | .alloc_inode = ecryptfs_alloc_inode, | 199 | .alloc_inode = ecryptfs_alloc_inode, |
198 | .destroy_inode = ecryptfs_destroy_inode, | 200 | .destroy_inode = ecryptfs_destroy_inode, |
199 | .drop_inode = generic_delete_inode, | 201 | .drop_inode = generic_delete_inode, |
200 | .put_super = ecryptfs_put_super, | 202 | .put_super = ecryptfs_put_super, |
201 | .statfs = ecryptfs_statfs, | 203 | .statfs = ecryptfs_statfs, |
202 | .remount_fs = NULL, | 204 | .remount_fs = NULL, |
203 | .clear_inode = ecryptfs_clear_inode, | 205 | .clear_inode = ecryptfs_clear_inode, |
204 | .show_options = ecryptfs_show_options | 206 | .show_options = ecryptfs_show_options |
205 | }; | 207 | }; |
206 | 208 |