1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /**
3*4882a593Smuzhiyun * eCryptfs: Linux filesystem encryption layer
4*4882a593Smuzhiyun * Kernel declarations.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 1997-2003 Erez Zadok
7*4882a593Smuzhiyun * Copyright (C) 2001-2003 Stony Brook University
8*4882a593Smuzhiyun * Copyright (C) 2004-2008 International Business Machines Corp.
9*4882a593Smuzhiyun * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
10*4882a593Smuzhiyun * Trevor S. Highland <trevor.highland@gmail.com>
11*4882a593Smuzhiyun * Tyler Hicks <code@tyhicks.com>
12*4882a593Smuzhiyun */
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #ifndef ECRYPTFS_KERNEL_H
15*4882a593Smuzhiyun #define ECRYPTFS_KERNEL_H
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include <crypto/skcipher.h>
18*4882a593Smuzhiyun #include <keys/user-type.h>
19*4882a593Smuzhiyun #include <keys/encrypted-type.h>
20*4882a593Smuzhiyun #include <linux/kernel.h>
21*4882a593Smuzhiyun #include <linux/fs.h>
22*4882a593Smuzhiyun #include <linux/fs_stack.h>
23*4882a593Smuzhiyun #include <linux/namei.h>
24*4882a593Smuzhiyun #include <linux/scatterlist.h>
25*4882a593Smuzhiyun #include <linux/hash.h>
26*4882a593Smuzhiyun #include <linux/nsproxy.h>
27*4882a593Smuzhiyun #include <linux/backing-dev.h>
28*4882a593Smuzhiyun #include <linux/ecryptfs.h>
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #define ECRYPTFS_DEFAULT_IV_BYTES 16
31*4882a593Smuzhiyun #define ECRYPTFS_DEFAULT_EXTENT_SIZE 4096
32*4882a593Smuzhiyun #define ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE 8192
33*4882a593Smuzhiyun #define ECRYPTFS_DEFAULT_MSG_CTX_ELEMS 32
34*4882a593Smuzhiyun #define ECRYPTFS_DEFAULT_SEND_TIMEOUT HZ
35*4882a593Smuzhiyun #define ECRYPTFS_MAX_MSG_CTX_TTL (HZ*3)
36*4882a593Smuzhiyun #define ECRYPTFS_DEFAULT_NUM_USERS 4
37*4882a593Smuzhiyun #define ECRYPTFS_MAX_NUM_USERS 32768
38*4882a593Smuzhiyun #define ECRYPTFS_XATTR_NAME "user.ecryptfs"
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok);
41*4882a593Smuzhiyun static inline void
ecryptfs_to_hex(char * dst,char * src,size_t src_size)42*4882a593Smuzhiyun ecryptfs_to_hex(char *dst, char *src, size_t src_size)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun char *end = bin2hex(dst, src, src_size);
45*4882a593Smuzhiyun *end = '\0';
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun extern void ecryptfs_from_hex(char *dst, char *src, int dst_size);
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun struct ecryptfs_key_record {
51*4882a593Smuzhiyun unsigned char type;
52*4882a593Smuzhiyun size_t enc_key_size;
53*4882a593Smuzhiyun unsigned char sig[ECRYPTFS_SIG_SIZE];
54*4882a593Smuzhiyun unsigned char enc_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES];
55*4882a593Smuzhiyun };
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun struct ecryptfs_auth_tok_list {
58*4882a593Smuzhiyun struct ecryptfs_auth_tok *auth_tok;
59*4882a593Smuzhiyun struct list_head list;
60*4882a593Smuzhiyun };
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun struct ecryptfs_crypt_stat;
63*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun struct ecryptfs_page_crypt_context {
66*4882a593Smuzhiyun struct page *page;
67*4882a593Smuzhiyun #define ECRYPTFS_PREPARE_COMMIT_MODE 0
68*4882a593Smuzhiyun #define ECRYPTFS_WRITEPAGE_MODE 1
69*4882a593Smuzhiyun unsigned int mode;
70*4882a593Smuzhiyun union {
71*4882a593Smuzhiyun struct file *lower_file;
72*4882a593Smuzhiyun struct writeback_control *wbc;
73*4882a593Smuzhiyun } param;
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun #if defined(CONFIG_ENCRYPTED_KEYS) || defined(CONFIG_ENCRYPTED_KEYS_MODULE)
77*4882a593Smuzhiyun static inline struct ecryptfs_auth_tok *
ecryptfs_get_encrypted_key_payload_data(struct key * key)78*4882a593Smuzhiyun ecryptfs_get_encrypted_key_payload_data(struct key *key)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun struct encrypted_key_payload *payload;
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun if (key->type != &key_type_encrypted)
83*4882a593Smuzhiyun return NULL;
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun payload = key->payload.data[0];
86*4882a593Smuzhiyun if (!payload)
87*4882a593Smuzhiyun return ERR_PTR(-EKEYREVOKED);
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun return (struct ecryptfs_auth_tok *)payload->payload_data;
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun
ecryptfs_get_encrypted_key(char * sig)92*4882a593Smuzhiyun static inline struct key *ecryptfs_get_encrypted_key(char *sig)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun return request_key(&key_type_encrypted, sig, NULL);
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun #else
98*4882a593Smuzhiyun static inline struct ecryptfs_auth_tok *
ecryptfs_get_encrypted_key_payload_data(struct key * key)99*4882a593Smuzhiyun ecryptfs_get_encrypted_key_payload_data(struct key *key)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun return NULL;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun
ecryptfs_get_encrypted_key(char * sig)104*4882a593Smuzhiyun static inline struct key *ecryptfs_get_encrypted_key(char *sig)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun return ERR_PTR(-ENOKEY);
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun #endif /* CONFIG_ENCRYPTED_KEYS */
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun static inline struct ecryptfs_auth_tok *
ecryptfs_get_key_payload_data(struct key * key)112*4882a593Smuzhiyun ecryptfs_get_key_payload_data(struct key *key)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun struct ecryptfs_auth_tok *auth_tok;
115*4882a593Smuzhiyun struct user_key_payload *ukp;
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun auth_tok = ecryptfs_get_encrypted_key_payload_data(key);
118*4882a593Smuzhiyun if (auth_tok)
119*4882a593Smuzhiyun return auth_tok;
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun ukp = user_key_payload_locked(key);
122*4882a593Smuzhiyun if (!ukp)
123*4882a593Smuzhiyun return ERR_PTR(-EKEYREVOKED);
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun return (struct ecryptfs_auth_tok *)ukp->data;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun #define ECRYPTFS_MAX_KEYSET_SIZE 1024
129*4882a593Smuzhiyun #define ECRYPTFS_MAX_CIPHER_NAME_SIZE 31
130*4882a593Smuzhiyun #define ECRYPTFS_MAX_NUM_ENC_KEYS 64
131*4882a593Smuzhiyun #define ECRYPTFS_MAX_IV_BYTES 16 /* 128 bits */
132*4882a593Smuzhiyun #define ECRYPTFS_SALT_BYTES 2
133*4882a593Smuzhiyun #define MAGIC_ECRYPTFS_MARKER 0x3c81b7f5
134*4882a593Smuzhiyun #define MAGIC_ECRYPTFS_MARKER_SIZE_BYTES 8 /* 4*2 */
135*4882a593Smuzhiyun #define ECRYPTFS_FILE_SIZE_BYTES (sizeof(u64))
136*4882a593Smuzhiyun #define ECRYPTFS_SIZE_AND_MARKER_BYTES (ECRYPTFS_FILE_SIZE_BYTES \
137*4882a593Smuzhiyun + MAGIC_ECRYPTFS_MARKER_SIZE_BYTES)
138*4882a593Smuzhiyun #define ECRYPTFS_DEFAULT_CIPHER "aes"
139*4882a593Smuzhiyun #define ECRYPTFS_DEFAULT_KEY_BYTES 16
140*4882a593Smuzhiyun #define ECRYPTFS_DEFAULT_HASH "md5"
141*4882a593Smuzhiyun #define ECRYPTFS_TAG_70_DIGEST ECRYPTFS_DEFAULT_HASH
142*4882a593Smuzhiyun #define ECRYPTFS_TAG_1_PACKET_TYPE 0x01
143*4882a593Smuzhiyun #define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C
144*4882a593Smuzhiyun #define ECRYPTFS_TAG_11_PACKET_TYPE 0xED
145*4882a593Smuzhiyun #define ECRYPTFS_TAG_64_PACKET_TYPE 0x40
146*4882a593Smuzhiyun #define ECRYPTFS_TAG_65_PACKET_TYPE 0x41
147*4882a593Smuzhiyun #define ECRYPTFS_TAG_66_PACKET_TYPE 0x42
148*4882a593Smuzhiyun #define ECRYPTFS_TAG_67_PACKET_TYPE 0x43
149*4882a593Smuzhiyun #define ECRYPTFS_TAG_70_PACKET_TYPE 0x46 /* FNEK-encrypted filename
150*4882a593Smuzhiyun * as dentry name */
151*4882a593Smuzhiyun #define ECRYPTFS_TAG_71_PACKET_TYPE 0x47 /* FNEK-encrypted filename in
152*4882a593Smuzhiyun * metadata */
153*4882a593Smuzhiyun #define ECRYPTFS_TAG_72_PACKET_TYPE 0x48 /* FEK-encrypted filename as
154*4882a593Smuzhiyun * dentry name */
155*4882a593Smuzhiyun #define ECRYPTFS_TAG_73_PACKET_TYPE 0x49 /* FEK-encrypted filename as
156*4882a593Smuzhiyun * metadata */
157*4882a593Smuzhiyun #define ECRYPTFS_MIN_PKT_LEN_SIZE 1 /* Min size to specify packet length */
158*4882a593Smuzhiyun #define ECRYPTFS_MAX_PKT_LEN_SIZE 2 /* Pass at least this many bytes to
159*4882a593Smuzhiyun * ecryptfs_parse_packet_length() and
160*4882a593Smuzhiyun * ecryptfs_write_packet_length()
161*4882a593Smuzhiyun */
162*4882a593Smuzhiyun /* Constraint: ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES >=
163*4882a593Smuzhiyun * ECRYPTFS_MAX_IV_BYTES */
164*4882a593Smuzhiyun #define ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES 16
165*4882a593Smuzhiyun #define ECRYPTFS_NON_NULL 0x42 /* A reasonable substitute for NULL */
166*4882a593Smuzhiyun #define MD5_DIGEST_SIZE 16
167*4882a593Smuzhiyun #define ECRYPTFS_TAG_70_DIGEST_SIZE MD5_DIGEST_SIZE
168*4882a593Smuzhiyun #define ECRYPTFS_TAG_70_MIN_METADATA_SIZE (1 + ECRYPTFS_MIN_PKT_LEN_SIZE \
169*4882a593Smuzhiyun + ECRYPTFS_SIG_SIZE + 1 + 1)
170*4882a593Smuzhiyun #define ECRYPTFS_TAG_70_MAX_METADATA_SIZE (1 + ECRYPTFS_MAX_PKT_LEN_SIZE \
171*4882a593Smuzhiyun + ECRYPTFS_SIG_SIZE + 1 + 1)
172*4882a593Smuzhiyun #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FEK_ENCRYPTED."
173*4882a593Smuzhiyun #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX_SIZE 23
174*4882a593Smuzhiyun #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FNEK_ENCRYPTED."
175*4882a593Smuzhiyun #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE 24
176*4882a593Smuzhiyun #define ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN (18 + 1 + 4 + 1 + 32)
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun #ifdef CONFIG_ECRYPT_FS_MESSAGING
179*4882a593Smuzhiyun # define ECRYPTFS_VERSIONING_MASK_MESSAGING (ECRYPTFS_VERSIONING_DEVMISC \
180*4882a593Smuzhiyun | ECRYPTFS_VERSIONING_PUBKEY)
181*4882a593Smuzhiyun #else
182*4882a593Smuzhiyun # define ECRYPTFS_VERSIONING_MASK_MESSAGING 0
183*4882a593Smuzhiyun #endif
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun #define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \
186*4882a593Smuzhiyun | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \
187*4882a593Smuzhiyun | ECRYPTFS_VERSIONING_XATTR \
188*4882a593Smuzhiyun | ECRYPTFS_VERSIONING_MULTKEY \
189*4882a593Smuzhiyun | ECRYPTFS_VERSIONING_MASK_MESSAGING \
190*4882a593Smuzhiyun | ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION)
191*4882a593Smuzhiyun struct ecryptfs_key_sig {
192*4882a593Smuzhiyun struct list_head crypt_stat_list;
193*4882a593Smuzhiyun char keysig[ECRYPTFS_SIG_SIZE_HEX + 1];
194*4882a593Smuzhiyun };
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun struct ecryptfs_filename {
197*4882a593Smuzhiyun struct list_head crypt_stat_list;
198*4882a593Smuzhiyun #define ECRYPTFS_FILENAME_CONTAINS_DECRYPTED 0x00000001
199*4882a593Smuzhiyun u32 flags;
200*4882a593Smuzhiyun u32 seq_no;
201*4882a593Smuzhiyun char *filename;
202*4882a593Smuzhiyun char *encrypted_filename;
203*4882a593Smuzhiyun size_t filename_size;
204*4882a593Smuzhiyun size_t encrypted_filename_size;
205*4882a593Smuzhiyun char fnek_sig[ECRYPTFS_SIG_SIZE_HEX];
206*4882a593Smuzhiyun char dentry_name[ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN + 1];
207*4882a593Smuzhiyun };
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun /**
210*4882a593Smuzhiyun * This is the primary struct associated with each encrypted file.
211*4882a593Smuzhiyun *
212*4882a593Smuzhiyun * TODO: cache align/pack?
213*4882a593Smuzhiyun */
214*4882a593Smuzhiyun struct ecryptfs_crypt_stat {
215*4882a593Smuzhiyun #define ECRYPTFS_STRUCT_INITIALIZED 0x00000001
216*4882a593Smuzhiyun #define ECRYPTFS_POLICY_APPLIED 0x00000002
217*4882a593Smuzhiyun #define ECRYPTFS_ENCRYPTED 0x00000004
218*4882a593Smuzhiyun #define ECRYPTFS_SECURITY_WARNING 0x00000008
219*4882a593Smuzhiyun #define ECRYPTFS_ENABLE_HMAC 0x00000010
220*4882a593Smuzhiyun #define ECRYPTFS_ENCRYPT_IV_PAGES 0x00000020
221*4882a593Smuzhiyun #define ECRYPTFS_KEY_VALID 0x00000040
222*4882a593Smuzhiyun #define ECRYPTFS_METADATA_IN_XATTR 0x00000080
223*4882a593Smuzhiyun #define ECRYPTFS_VIEW_AS_ENCRYPTED 0x00000100
224*4882a593Smuzhiyun #define ECRYPTFS_KEY_SET 0x00000200
225*4882a593Smuzhiyun #define ECRYPTFS_ENCRYPT_FILENAMES 0x00000400
226*4882a593Smuzhiyun #define ECRYPTFS_ENCFN_USE_MOUNT_FNEK 0x00000800
227*4882a593Smuzhiyun #define ECRYPTFS_ENCFN_USE_FEK 0x00001000
228*4882a593Smuzhiyun #define ECRYPTFS_UNLINK_SIGS 0x00002000
229*4882a593Smuzhiyun #define ECRYPTFS_I_SIZE_INITIALIZED 0x00004000
230*4882a593Smuzhiyun u32 flags;
231*4882a593Smuzhiyun unsigned int file_version;
232*4882a593Smuzhiyun size_t iv_bytes;
233*4882a593Smuzhiyun size_t metadata_size;
234*4882a593Smuzhiyun size_t extent_size; /* Data extent size; default is 4096 */
235*4882a593Smuzhiyun size_t key_size;
236*4882a593Smuzhiyun size_t extent_shift;
237*4882a593Smuzhiyun unsigned int extent_mask;
238*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
239*4882a593Smuzhiyun struct crypto_skcipher *tfm;
240*4882a593Smuzhiyun struct crypto_shash *hash_tfm; /* Crypto context for generating
241*4882a593Smuzhiyun * the initialization vectors */
242*4882a593Smuzhiyun unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
243*4882a593Smuzhiyun unsigned char key[ECRYPTFS_MAX_KEY_BYTES];
244*4882a593Smuzhiyun unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES];
245*4882a593Smuzhiyun struct list_head keysig_list;
246*4882a593Smuzhiyun struct mutex keysig_list_mutex;
247*4882a593Smuzhiyun struct mutex cs_tfm_mutex;
248*4882a593Smuzhiyun struct mutex cs_mutex;
249*4882a593Smuzhiyun };
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun /* inode private data. */
252*4882a593Smuzhiyun struct ecryptfs_inode_info {
253*4882a593Smuzhiyun struct inode vfs_inode;
254*4882a593Smuzhiyun struct inode *wii_inode;
255*4882a593Smuzhiyun struct mutex lower_file_mutex;
256*4882a593Smuzhiyun atomic_t lower_file_count;
257*4882a593Smuzhiyun struct file *lower_file;
258*4882a593Smuzhiyun struct ecryptfs_crypt_stat crypt_stat;
259*4882a593Smuzhiyun };
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun /* dentry private data. Each dentry must keep track of a lower
262*4882a593Smuzhiyun * vfsmount too. */
263*4882a593Smuzhiyun struct ecryptfs_dentry_info {
264*4882a593Smuzhiyun struct path lower_path;
265*4882a593Smuzhiyun union {
266*4882a593Smuzhiyun struct ecryptfs_crypt_stat *crypt_stat;
267*4882a593Smuzhiyun struct rcu_head rcu;
268*4882a593Smuzhiyun };
269*4882a593Smuzhiyun };
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun /**
272*4882a593Smuzhiyun * ecryptfs_global_auth_tok - A key used to encrypt all new files under the mountpoint
273*4882a593Smuzhiyun * @flags: Status flags
274*4882a593Smuzhiyun * @mount_crypt_stat_list: These auth_toks hang off the mount-wide
275*4882a593Smuzhiyun * cryptographic context. Every time a new
276*4882a593Smuzhiyun * inode comes into existence, eCryptfs copies
277*4882a593Smuzhiyun * the auth_toks on that list to the set of
278*4882a593Smuzhiyun * auth_toks on the inode's crypt_stat
279*4882a593Smuzhiyun * @global_auth_tok_key: The key from the user's keyring for the sig
280*4882a593Smuzhiyun * @global_auth_tok: The key contents
281*4882a593Smuzhiyun * @sig: The key identifier
282*4882a593Smuzhiyun *
283*4882a593Smuzhiyun * ecryptfs_global_auth_tok structs refer to authentication token keys
284*4882a593Smuzhiyun * in the user keyring that apply to newly created files. A list of
285*4882a593Smuzhiyun * these objects hangs off of the mount_crypt_stat struct for any
286*4882a593Smuzhiyun * given eCryptfs mount. This struct maintains a reference to both the
287*4882a593Smuzhiyun * key contents and the key itself so that the key can be put on
288*4882a593Smuzhiyun * unmount.
289*4882a593Smuzhiyun */
290*4882a593Smuzhiyun struct ecryptfs_global_auth_tok {
291*4882a593Smuzhiyun #define ECRYPTFS_AUTH_TOK_INVALID 0x00000001
292*4882a593Smuzhiyun #define ECRYPTFS_AUTH_TOK_FNEK 0x00000002
293*4882a593Smuzhiyun u32 flags;
294*4882a593Smuzhiyun struct list_head mount_crypt_stat_list;
295*4882a593Smuzhiyun struct key *global_auth_tok_key;
296*4882a593Smuzhiyun unsigned char sig[ECRYPTFS_SIG_SIZE_HEX + 1];
297*4882a593Smuzhiyun };
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun /**
300*4882a593Smuzhiyun * ecryptfs_key_tfm - Persistent key tfm
301*4882a593Smuzhiyun * @key_tfm: crypto API handle to the key
302*4882a593Smuzhiyun * @key_size: Key size in bytes
303*4882a593Smuzhiyun * @key_tfm_mutex: Mutex to ensure only one operation in eCryptfs is
304*4882a593Smuzhiyun * using the persistent TFM at any point in time
305*4882a593Smuzhiyun * @key_tfm_list: Handle to hang this off the module-wide TFM list
306*4882a593Smuzhiyun * @cipher_name: String name for the cipher for this TFM
307*4882a593Smuzhiyun *
308*4882a593Smuzhiyun * Typically, eCryptfs will use the same ciphers repeatedly throughout
309*4882a593Smuzhiyun * the course of its operations. In order to avoid unnecessarily
310*4882a593Smuzhiyun * destroying and initializing the same cipher repeatedly, eCryptfs
311*4882a593Smuzhiyun * keeps a list of crypto API contexts around to use when needed.
312*4882a593Smuzhiyun */
313*4882a593Smuzhiyun struct ecryptfs_key_tfm {
314*4882a593Smuzhiyun struct crypto_skcipher *key_tfm;
315*4882a593Smuzhiyun size_t key_size;
316*4882a593Smuzhiyun struct mutex key_tfm_mutex;
317*4882a593Smuzhiyun struct list_head key_tfm_list;
318*4882a593Smuzhiyun unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
319*4882a593Smuzhiyun };
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun extern struct mutex key_tfm_list_mutex;
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun /**
324*4882a593Smuzhiyun * This struct is to enable a mount-wide passphrase/salt combo. This
325*4882a593Smuzhiyun * is more or less a stopgap to provide similar functionality to other
326*4882a593Smuzhiyun * crypto filesystems like EncFS or CFS until full policy support is
327*4882a593Smuzhiyun * implemented in eCryptfs.
328*4882a593Smuzhiyun */
329*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat {
330*4882a593Smuzhiyun /* Pointers to memory we do not own, do not free these */
331*4882a593Smuzhiyun #define ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED 0x00000001
332*4882a593Smuzhiyun #define ECRYPTFS_XATTR_METADATA_ENABLED 0x00000002
333*4882a593Smuzhiyun #define ECRYPTFS_ENCRYPTED_VIEW_ENABLED 0x00000004
334*4882a593Smuzhiyun #define ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED 0x00000008
335*4882a593Smuzhiyun #define ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES 0x00000010
336*4882a593Smuzhiyun #define ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK 0x00000020
337*4882a593Smuzhiyun #define ECRYPTFS_GLOBAL_ENCFN_USE_FEK 0x00000040
338*4882a593Smuzhiyun #define ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY 0x00000080
339*4882a593Smuzhiyun u32 flags;
340*4882a593Smuzhiyun struct list_head global_auth_tok_list;
341*4882a593Smuzhiyun struct mutex global_auth_tok_list_mutex;
342*4882a593Smuzhiyun size_t global_default_cipher_key_size;
343*4882a593Smuzhiyun size_t global_default_fn_cipher_key_bytes;
344*4882a593Smuzhiyun unsigned char global_default_cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE
345*4882a593Smuzhiyun + 1];
346*4882a593Smuzhiyun unsigned char global_default_fn_cipher_name[
347*4882a593Smuzhiyun ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
348*4882a593Smuzhiyun char global_default_fnek_sig[ECRYPTFS_SIG_SIZE_HEX + 1];
349*4882a593Smuzhiyun };
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun /* superblock private data. */
352*4882a593Smuzhiyun struct ecryptfs_sb_info {
353*4882a593Smuzhiyun struct super_block *wsi_sb;
354*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat mount_crypt_stat;
355*4882a593Smuzhiyun };
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun /* file private data. */
358*4882a593Smuzhiyun struct ecryptfs_file_info {
359*4882a593Smuzhiyun struct file *wfi_file;
360*4882a593Smuzhiyun struct ecryptfs_crypt_stat *crypt_stat;
361*4882a593Smuzhiyun };
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun /* auth_tok <=> encrypted_session_key mappings */
364*4882a593Smuzhiyun struct ecryptfs_auth_tok_list_item {
365*4882a593Smuzhiyun unsigned char encrypted_session_key[ECRYPTFS_MAX_KEY_BYTES];
366*4882a593Smuzhiyun struct list_head list;
367*4882a593Smuzhiyun struct ecryptfs_auth_tok auth_tok;
368*4882a593Smuzhiyun };
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun struct ecryptfs_message {
371*4882a593Smuzhiyun /* Can never be greater than ecryptfs_message_buf_len */
372*4882a593Smuzhiyun /* Used to find the parent msg_ctx */
373*4882a593Smuzhiyun /* Inherits from msg_ctx->index */
374*4882a593Smuzhiyun u32 index;
375*4882a593Smuzhiyun u32 data_len;
376*4882a593Smuzhiyun u8 data[];
377*4882a593Smuzhiyun };
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun struct ecryptfs_msg_ctx {
380*4882a593Smuzhiyun #define ECRYPTFS_MSG_CTX_STATE_FREE 0x01
381*4882a593Smuzhiyun #define ECRYPTFS_MSG_CTX_STATE_PENDING 0x02
382*4882a593Smuzhiyun #define ECRYPTFS_MSG_CTX_STATE_DONE 0x03
383*4882a593Smuzhiyun #define ECRYPTFS_MSG_CTX_STATE_NO_REPLY 0x04
384*4882a593Smuzhiyun u8 state;
385*4882a593Smuzhiyun #define ECRYPTFS_MSG_HELO 100
386*4882a593Smuzhiyun #define ECRYPTFS_MSG_QUIT 101
387*4882a593Smuzhiyun #define ECRYPTFS_MSG_REQUEST 102
388*4882a593Smuzhiyun #define ECRYPTFS_MSG_RESPONSE 103
389*4882a593Smuzhiyun u8 type;
390*4882a593Smuzhiyun u32 index;
391*4882a593Smuzhiyun /* Counter converts to a sequence number. Each message sent
392*4882a593Smuzhiyun * out for which we expect a response has an associated
393*4882a593Smuzhiyun * sequence number. The response must have the same sequence
394*4882a593Smuzhiyun * number as the counter for the msg_stc for the message to be
395*4882a593Smuzhiyun * valid. */
396*4882a593Smuzhiyun u32 counter;
397*4882a593Smuzhiyun size_t msg_size;
398*4882a593Smuzhiyun struct ecryptfs_message *msg;
399*4882a593Smuzhiyun struct task_struct *task;
400*4882a593Smuzhiyun struct list_head node;
401*4882a593Smuzhiyun struct list_head daemon_out_list;
402*4882a593Smuzhiyun struct mutex mux;
403*4882a593Smuzhiyun };
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun struct ecryptfs_daemon {
406*4882a593Smuzhiyun #define ECRYPTFS_DAEMON_IN_READ 0x00000001
407*4882a593Smuzhiyun #define ECRYPTFS_DAEMON_IN_POLL 0x00000002
408*4882a593Smuzhiyun #define ECRYPTFS_DAEMON_ZOMBIE 0x00000004
409*4882a593Smuzhiyun #define ECRYPTFS_DAEMON_MISCDEV_OPEN 0x00000008
410*4882a593Smuzhiyun u32 flags;
411*4882a593Smuzhiyun u32 num_queued_msg_ctx;
412*4882a593Smuzhiyun struct file *file;
413*4882a593Smuzhiyun struct mutex mux;
414*4882a593Smuzhiyun struct list_head msg_ctx_out_queue;
415*4882a593Smuzhiyun wait_queue_head_t wait;
416*4882a593Smuzhiyun struct hlist_node euid_chain;
417*4882a593Smuzhiyun };
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun #ifdef CONFIG_ECRYPT_FS_MESSAGING
420*4882a593Smuzhiyun extern struct mutex ecryptfs_daemon_hash_mux;
421*4882a593Smuzhiyun #endif
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun static inline size_t
ecryptfs_lower_header_size(struct ecryptfs_crypt_stat * crypt_stat)424*4882a593Smuzhiyun ecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat)
425*4882a593Smuzhiyun {
426*4882a593Smuzhiyun if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
427*4882a593Smuzhiyun return 0;
428*4882a593Smuzhiyun return crypt_stat->metadata_size;
429*4882a593Smuzhiyun }
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun static inline struct ecryptfs_file_info *
ecryptfs_file_to_private(struct file * file)432*4882a593Smuzhiyun ecryptfs_file_to_private(struct file *file)
433*4882a593Smuzhiyun {
434*4882a593Smuzhiyun return file->private_data;
435*4882a593Smuzhiyun }
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun static inline void
ecryptfs_set_file_private(struct file * file,struct ecryptfs_file_info * file_info)438*4882a593Smuzhiyun ecryptfs_set_file_private(struct file *file,
439*4882a593Smuzhiyun struct ecryptfs_file_info *file_info)
440*4882a593Smuzhiyun {
441*4882a593Smuzhiyun file->private_data = file_info;
442*4882a593Smuzhiyun }
443*4882a593Smuzhiyun
ecryptfs_file_to_lower(struct file * file)444*4882a593Smuzhiyun static inline struct file *ecryptfs_file_to_lower(struct file *file)
445*4882a593Smuzhiyun {
446*4882a593Smuzhiyun return ((struct ecryptfs_file_info *)file->private_data)->wfi_file;
447*4882a593Smuzhiyun }
448*4882a593Smuzhiyun
449*4882a593Smuzhiyun static inline void
ecryptfs_set_file_lower(struct file * file,struct file * lower_file)450*4882a593Smuzhiyun ecryptfs_set_file_lower(struct file *file, struct file *lower_file)
451*4882a593Smuzhiyun {
452*4882a593Smuzhiyun ((struct ecryptfs_file_info *)file->private_data)->wfi_file =
453*4882a593Smuzhiyun lower_file;
454*4882a593Smuzhiyun }
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun static inline struct ecryptfs_inode_info *
ecryptfs_inode_to_private(struct inode * inode)457*4882a593Smuzhiyun ecryptfs_inode_to_private(struct inode *inode)
458*4882a593Smuzhiyun {
459*4882a593Smuzhiyun return container_of(inode, struct ecryptfs_inode_info, vfs_inode);
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun
ecryptfs_inode_to_lower(struct inode * inode)462*4882a593Smuzhiyun static inline struct inode *ecryptfs_inode_to_lower(struct inode *inode)
463*4882a593Smuzhiyun {
464*4882a593Smuzhiyun return ecryptfs_inode_to_private(inode)->wii_inode;
465*4882a593Smuzhiyun }
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun static inline void
ecryptfs_set_inode_lower(struct inode * inode,struct inode * lower_inode)468*4882a593Smuzhiyun ecryptfs_set_inode_lower(struct inode *inode, struct inode *lower_inode)
469*4882a593Smuzhiyun {
470*4882a593Smuzhiyun ecryptfs_inode_to_private(inode)->wii_inode = lower_inode;
471*4882a593Smuzhiyun }
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun static inline struct ecryptfs_sb_info *
ecryptfs_superblock_to_private(struct super_block * sb)474*4882a593Smuzhiyun ecryptfs_superblock_to_private(struct super_block *sb)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun return (struct ecryptfs_sb_info *)sb->s_fs_info;
477*4882a593Smuzhiyun }
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun static inline void
ecryptfs_set_superblock_private(struct super_block * sb,struct ecryptfs_sb_info * sb_info)480*4882a593Smuzhiyun ecryptfs_set_superblock_private(struct super_block *sb,
481*4882a593Smuzhiyun struct ecryptfs_sb_info *sb_info)
482*4882a593Smuzhiyun {
483*4882a593Smuzhiyun sb->s_fs_info = sb_info;
484*4882a593Smuzhiyun }
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun static inline struct super_block *
ecryptfs_superblock_to_lower(struct super_block * sb)487*4882a593Smuzhiyun ecryptfs_superblock_to_lower(struct super_block *sb)
488*4882a593Smuzhiyun {
489*4882a593Smuzhiyun return ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb;
490*4882a593Smuzhiyun }
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun static inline void
ecryptfs_set_superblock_lower(struct super_block * sb,struct super_block * lower_sb)493*4882a593Smuzhiyun ecryptfs_set_superblock_lower(struct super_block *sb,
494*4882a593Smuzhiyun struct super_block *lower_sb)
495*4882a593Smuzhiyun {
496*4882a593Smuzhiyun ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb = lower_sb;
497*4882a593Smuzhiyun }
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun static inline struct ecryptfs_dentry_info *
ecryptfs_dentry_to_private(struct dentry * dentry)500*4882a593Smuzhiyun ecryptfs_dentry_to_private(struct dentry *dentry)
501*4882a593Smuzhiyun {
502*4882a593Smuzhiyun return (struct ecryptfs_dentry_info *)dentry->d_fsdata;
503*4882a593Smuzhiyun }
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun static inline void
ecryptfs_set_dentry_private(struct dentry * dentry,struct ecryptfs_dentry_info * dentry_info)506*4882a593Smuzhiyun ecryptfs_set_dentry_private(struct dentry *dentry,
507*4882a593Smuzhiyun struct ecryptfs_dentry_info *dentry_info)
508*4882a593Smuzhiyun {
509*4882a593Smuzhiyun dentry->d_fsdata = dentry_info;
510*4882a593Smuzhiyun }
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun static inline struct dentry *
ecryptfs_dentry_to_lower(struct dentry * dentry)513*4882a593Smuzhiyun ecryptfs_dentry_to_lower(struct dentry *dentry)
514*4882a593Smuzhiyun {
515*4882a593Smuzhiyun return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry;
516*4882a593Smuzhiyun }
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun static inline struct vfsmount *
ecryptfs_dentry_to_lower_mnt(struct dentry * dentry)519*4882a593Smuzhiyun ecryptfs_dentry_to_lower_mnt(struct dentry *dentry)
520*4882a593Smuzhiyun {
521*4882a593Smuzhiyun return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt;
522*4882a593Smuzhiyun }
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun static inline struct path *
ecryptfs_dentry_to_lower_path(struct dentry * dentry)525*4882a593Smuzhiyun ecryptfs_dentry_to_lower_path(struct dentry *dentry)
526*4882a593Smuzhiyun {
527*4882a593Smuzhiyun return &((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path;
528*4882a593Smuzhiyun }
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun #define ecryptfs_printk(type, fmt, arg...) \
531*4882a593Smuzhiyun __ecryptfs_printk(type "%s: " fmt, __func__, ## arg);
532*4882a593Smuzhiyun __printf(1, 2)
533*4882a593Smuzhiyun void __ecryptfs_printk(const char *fmt, ...);
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun extern const struct file_operations ecryptfs_main_fops;
536*4882a593Smuzhiyun extern const struct file_operations ecryptfs_dir_fops;
537*4882a593Smuzhiyun extern const struct inode_operations ecryptfs_main_iops;
538*4882a593Smuzhiyun extern const struct inode_operations ecryptfs_dir_iops;
539*4882a593Smuzhiyun extern const struct inode_operations ecryptfs_symlink_iops;
540*4882a593Smuzhiyun extern const struct super_operations ecryptfs_sops;
541*4882a593Smuzhiyun extern const struct dentry_operations ecryptfs_dops;
542*4882a593Smuzhiyun extern const struct address_space_operations ecryptfs_aops;
543*4882a593Smuzhiyun extern int ecryptfs_verbosity;
544*4882a593Smuzhiyun extern unsigned int ecryptfs_message_buf_len;
545*4882a593Smuzhiyun extern signed long ecryptfs_message_wait_timeout;
546*4882a593Smuzhiyun extern unsigned int ecryptfs_number_of_users;
547*4882a593Smuzhiyun
548*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_auth_tok_list_item_cache;
549*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_file_info_cache;
550*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_dentry_info_cache;
551*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_inode_info_cache;
552*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_sb_info_cache;
553*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_header_cache;
554*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_xattr_cache;
555*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_key_record_cache;
556*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_key_sig_cache;
557*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_global_auth_tok_cache;
558*4882a593Smuzhiyun extern struct kmem_cache *ecryptfs_key_tfm_cache;
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun struct inode *ecryptfs_get_inode(struct inode *lower_inode,
561*4882a593Smuzhiyun struct super_block *sb);
562*4882a593Smuzhiyun void ecryptfs_i_size_init(const char *page_virt, struct inode *inode);
563*4882a593Smuzhiyun int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
564*4882a593Smuzhiyun struct inode *ecryptfs_inode);
565*4882a593Smuzhiyun int ecryptfs_decode_and_decrypt_filename(char **decrypted_name,
566*4882a593Smuzhiyun size_t *decrypted_name_size,
567*4882a593Smuzhiyun struct super_block *sb,
568*4882a593Smuzhiyun const char *name, size_t name_size);
569*4882a593Smuzhiyun int ecryptfs_fill_zeros(struct file *file, loff_t new_length);
570*4882a593Smuzhiyun int ecryptfs_encrypt_and_encode_filename(
571*4882a593Smuzhiyun char **encoded_name,
572*4882a593Smuzhiyun size_t *encoded_name_size,
573*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
574*4882a593Smuzhiyun const char *name, size_t name_size);
575*4882a593Smuzhiyun struct dentry *ecryptfs_lower_dentry(struct dentry *this_dentry);
576*4882a593Smuzhiyun void ecryptfs_dump_hex(char *data, int bytes);
577*4882a593Smuzhiyun int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg,
578*4882a593Smuzhiyun int sg_size);
579*4882a593Smuzhiyun int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat);
580*4882a593Smuzhiyun void ecryptfs_rotate_iv(unsigned char *iv);
581*4882a593Smuzhiyun int ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat);
582*4882a593Smuzhiyun void ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat);
583*4882a593Smuzhiyun void ecryptfs_destroy_mount_crypt_stat(
584*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat *mount_crypt_stat);
585*4882a593Smuzhiyun int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat);
586*4882a593Smuzhiyun int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode);
587*4882a593Smuzhiyun int ecryptfs_encrypt_page(struct page *page);
588*4882a593Smuzhiyun int ecryptfs_decrypt_page(struct page *page);
589*4882a593Smuzhiyun int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry,
590*4882a593Smuzhiyun struct inode *ecryptfs_inode);
591*4882a593Smuzhiyun int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry);
592*4882a593Smuzhiyun int ecryptfs_new_file_context(struct inode *ecryptfs_inode);
593*4882a593Smuzhiyun void ecryptfs_write_crypt_stat_flags(char *page_virt,
594*4882a593Smuzhiyun struct ecryptfs_crypt_stat *crypt_stat,
595*4882a593Smuzhiyun size_t *written);
596*4882a593Smuzhiyun int ecryptfs_read_and_validate_header_region(struct inode *inode);
597*4882a593Smuzhiyun int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry,
598*4882a593Smuzhiyun struct inode *inode);
599*4882a593Smuzhiyun u8 ecryptfs_code_for_cipher_string(char *cipher_name, size_t key_bytes);
600*4882a593Smuzhiyun int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code);
601*4882a593Smuzhiyun void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat);
602*4882a593Smuzhiyun int ecryptfs_generate_key_packet_set(char *dest_base,
603*4882a593Smuzhiyun struct ecryptfs_crypt_stat *crypt_stat,
604*4882a593Smuzhiyun struct dentry *ecryptfs_dentry,
605*4882a593Smuzhiyun size_t *len, size_t max);
606*4882a593Smuzhiyun int
607*4882a593Smuzhiyun ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
608*4882a593Smuzhiyun unsigned char *src, struct dentry *ecryptfs_dentry);
609*4882a593Smuzhiyun int ecryptfs_truncate(struct dentry *dentry, loff_t new_length);
610*4882a593Smuzhiyun ssize_t
611*4882a593Smuzhiyun ecryptfs_getxattr_lower(struct dentry *lower_dentry, struct inode *lower_inode,
612*4882a593Smuzhiyun const char *name, void *value, size_t size);
613*4882a593Smuzhiyun int
614*4882a593Smuzhiyun ecryptfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
615*4882a593Smuzhiyun const void *value, size_t size, int flags);
616*4882a593Smuzhiyun int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode);
617*4882a593Smuzhiyun #ifdef CONFIG_ECRYPT_FS_MESSAGING
618*4882a593Smuzhiyun int ecryptfs_process_response(struct ecryptfs_daemon *daemon,
619*4882a593Smuzhiyun struct ecryptfs_message *msg, u32 seq);
620*4882a593Smuzhiyun int ecryptfs_send_message(char *data, int data_len,
621*4882a593Smuzhiyun struct ecryptfs_msg_ctx **msg_ctx);
622*4882a593Smuzhiyun int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
623*4882a593Smuzhiyun struct ecryptfs_message **emsg);
624*4882a593Smuzhiyun int ecryptfs_init_messaging(void);
625*4882a593Smuzhiyun void ecryptfs_release_messaging(void);
626*4882a593Smuzhiyun #else
ecryptfs_init_messaging(void)627*4882a593Smuzhiyun static inline int ecryptfs_init_messaging(void)
628*4882a593Smuzhiyun {
629*4882a593Smuzhiyun return 0;
630*4882a593Smuzhiyun }
ecryptfs_release_messaging(void)631*4882a593Smuzhiyun static inline void ecryptfs_release_messaging(void)
632*4882a593Smuzhiyun { }
ecryptfs_send_message(char * data,int data_len,struct ecryptfs_msg_ctx ** msg_ctx)633*4882a593Smuzhiyun static inline int ecryptfs_send_message(char *data, int data_len,
634*4882a593Smuzhiyun struct ecryptfs_msg_ctx **msg_ctx)
635*4882a593Smuzhiyun {
636*4882a593Smuzhiyun return -ENOTCONN;
637*4882a593Smuzhiyun }
ecryptfs_wait_for_response(struct ecryptfs_msg_ctx * msg_ctx,struct ecryptfs_message ** emsg)638*4882a593Smuzhiyun static inline int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
639*4882a593Smuzhiyun struct ecryptfs_message **emsg)
640*4882a593Smuzhiyun {
641*4882a593Smuzhiyun return -ENOMSG;
642*4882a593Smuzhiyun }
643*4882a593Smuzhiyun #endif
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun void
646*4882a593Smuzhiyun ecryptfs_write_header_metadata(char *virt,
647*4882a593Smuzhiyun struct ecryptfs_crypt_stat *crypt_stat,
648*4882a593Smuzhiyun size_t *written);
649*4882a593Smuzhiyun int ecryptfs_add_keysig(struct ecryptfs_crypt_stat *crypt_stat, char *sig);
650*4882a593Smuzhiyun int
651*4882a593Smuzhiyun ecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
652*4882a593Smuzhiyun char *sig, u32 global_auth_tok_flags);
653*4882a593Smuzhiyun int ecryptfs_get_global_auth_tok_for_sig(
654*4882a593Smuzhiyun struct ecryptfs_global_auth_tok **global_auth_tok,
655*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat *mount_crypt_stat, char *sig);
656*4882a593Smuzhiyun int
657*4882a593Smuzhiyun ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
658*4882a593Smuzhiyun size_t key_size);
659*4882a593Smuzhiyun int ecryptfs_init_crypto(void);
660*4882a593Smuzhiyun int ecryptfs_destroy_crypto(void);
661*4882a593Smuzhiyun int ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm);
662*4882a593Smuzhiyun int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_skcipher **tfm,
663*4882a593Smuzhiyun struct mutex **tfm_mutex,
664*4882a593Smuzhiyun char *cipher_name);
665*4882a593Smuzhiyun int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key,
666*4882a593Smuzhiyun struct ecryptfs_auth_tok **auth_tok,
667*4882a593Smuzhiyun char *sig);
668*4882a593Smuzhiyun int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
669*4882a593Smuzhiyun loff_t offset, size_t size);
670*4882a593Smuzhiyun int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
671*4882a593Smuzhiyun struct page *page_for_lower,
672*4882a593Smuzhiyun size_t offset_in_page, size_t size);
673*4882a593Smuzhiyun int ecryptfs_write(struct inode *inode, char *data, loff_t offset, size_t size);
674*4882a593Smuzhiyun int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
675*4882a593Smuzhiyun struct inode *ecryptfs_inode);
676*4882a593Smuzhiyun int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
677*4882a593Smuzhiyun pgoff_t page_index,
678*4882a593Smuzhiyun size_t offset_in_page, size_t size,
679*4882a593Smuzhiyun struct inode *ecryptfs_inode);
680*4882a593Smuzhiyun struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index);
681*4882a593Smuzhiyun int ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
682*4882a593Smuzhiyun size_t *length_size);
683*4882a593Smuzhiyun int ecryptfs_write_packet_length(char *dest, size_t size,
684*4882a593Smuzhiyun size_t *packet_size_length);
685*4882a593Smuzhiyun #ifdef CONFIG_ECRYPT_FS_MESSAGING
686*4882a593Smuzhiyun int ecryptfs_init_ecryptfs_miscdev(void);
687*4882a593Smuzhiyun void ecryptfs_destroy_ecryptfs_miscdev(void);
688*4882a593Smuzhiyun int ecryptfs_send_miscdev(char *data, size_t data_size,
689*4882a593Smuzhiyun struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
690*4882a593Smuzhiyun u16 msg_flags, struct ecryptfs_daemon *daemon);
691*4882a593Smuzhiyun void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx);
692*4882a593Smuzhiyun int
693*4882a593Smuzhiyun ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file);
694*4882a593Smuzhiyun int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
695*4882a593Smuzhiyun int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
696*4882a593Smuzhiyun #endif
697*4882a593Smuzhiyun int ecryptfs_init_kthread(void);
698*4882a593Smuzhiyun void ecryptfs_destroy_kthread(void);
699*4882a593Smuzhiyun int ecryptfs_privileged_open(struct file **lower_file,
700*4882a593Smuzhiyun struct dentry *lower_dentry,
701*4882a593Smuzhiyun struct vfsmount *lower_mnt,
702*4882a593Smuzhiyun const struct cred *cred);
703*4882a593Smuzhiyun int ecryptfs_get_lower_file(struct dentry *dentry, struct inode *inode);
704*4882a593Smuzhiyun void ecryptfs_put_lower_file(struct inode *inode);
705*4882a593Smuzhiyun int
706*4882a593Smuzhiyun ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
707*4882a593Smuzhiyun size_t *packet_size,
708*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
709*4882a593Smuzhiyun char *filename, size_t filename_size);
710*4882a593Smuzhiyun int
711*4882a593Smuzhiyun ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
712*4882a593Smuzhiyun size_t *packet_size,
713*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
714*4882a593Smuzhiyun char *data, size_t max_packet_size);
715*4882a593Smuzhiyun int ecryptfs_set_f_namelen(long *namelen, long lower_namelen,
716*4882a593Smuzhiyun struct ecryptfs_mount_crypt_stat *mount_crypt_stat);
717*4882a593Smuzhiyun int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat,
718*4882a593Smuzhiyun loff_t offset);
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun extern const struct xattr_handler *ecryptfs_xattr_handlers[];
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun #endif /* #ifndef ECRYPTFS_KERNEL_H */
723