11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2237fead6SMichael Halcrow /**
3237fead6SMichael Halcrow * eCryptfs: Linux filesystem encryption layer
4237fead6SMichael Halcrow * Kernel declarations.
5237fead6SMichael Halcrow *
6237fead6SMichael Halcrow * Copyright (C) 1997-2003 Erez Zadok
7237fead6SMichael Halcrow * Copyright (C) 2001-2003 Stony Brook University
8f66e883eSMichael Halcrow * Copyright (C) 2004-2008 International Business Machines Corp.
9237fead6SMichael Halcrow * Author(s): Michael A. Halcrow <[email protected]>
1088b4a07eSMichael Halcrow * Trevor S. Highland <[email protected]>
11f8e48a84STyler Hicks * Tyler Hicks <[email protected]>
12237fead6SMichael Halcrow */
13237fead6SMichael Halcrow
14237fead6SMichael Halcrow #ifndef ECRYPTFS_KERNEL_H
15237fead6SMichael Halcrow #define ECRYPTFS_KERNEL_H
16237fead6SMichael Halcrow
173095e8e3SHerbert Xu #include <crypto/skcipher.h>
18237fead6SMichael Halcrow #include <keys/user-type.h>
191252cc3bSRoberto Sassu #include <keys/encrypted-type.h>
20abbae6d5SRasmus Villemoes #include <linux/kernel.h>
21237fead6SMichael Halcrow #include <linux/fs.h>
220cc72dc7SJosef "Jeff" Sipek #include <linux/fs_stack.h>
23b65d34fdSJosef "Jeff" Sipek #include <linux/namei.h>
24237fead6SMichael Halcrow #include <linux/scatterlist.h>
25dddfa461SMichael Halcrow #include <linux/hash.h>
266a3fd92eSMichael Halcrow #include <linux/nsproxy.h>
279df9c8b9SJens Axboe #include <linux/backing-dev.h>
28f8f85271SRoberto Sassu #include <linux/ecryptfs.h>
29237fead6SMichael Halcrow
30237fead6SMichael Halcrow #define ECRYPTFS_DEFAULT_IV_BYTES 16
31237fead6SMichael Halcrow #define ECRYPTFS_DEFAULT_EXTENT_SIZE 4096
32237fead6SMichael Halcrow #define ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE 8192
3388b4a07eSMichael Halcrow #define ECRYPTFS_DEFAULT_MSG_CTX_ELEMS 32
3488b4a07eSMichael Halcrow #define ECRYPTFS_DEFAULT_SEND_TIMEOUT HZ
3588b4a07eSMichael Halcrow #define ECRYPTFS_MAX_MSG_CTX_TTL (HZ*3)
3688b4a07eSMichael Halcrow #define ECRYPTFS_DEFAULT_NUM_USERS 4
3788b4a07eSMichael Halcrow #define ECRYPTFS_MAX_NUM_USERS 32768
38dd2a3b7aSMichael Halcrow #define ECRYPTFS_XATTR_NAME "user.ecryptfs"
39237fead6SMichael Halcrow
40237fead6SMichael Halcrow void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok);
41abbae6d5SRasmus Villemoes static inline void
ecryptfs_to_hex(char * dst,char * src,size_t src_size)42abbae6d5SRasmus Villemoes ecryptfs_to_hex(char *dst, char *src, size_t src_size)
43abbae6d5SRasmus Villemoes {
44abbae6d5SRasmus Villemoes char *end = bin2hex(dst, src, src_size);
45abbae6d5SRasmus Villemoes *end = '\0';
46abbae6d5SRasmus Villemoes }
47abbae6d5SRasmus Villemoes
48237fead6SMichael Halcrow extern void ecryptfs_from_hex(char *dst, char *src, int dst_size);
49237fead6SMichael Halcrow
50237fead6SMichael Halcrow struct ecryptfs_key_record {
51237fead6SMichael Halcrow unsigned char type;
52237fead6SMichael Halcrow size_t enc_key_size;
53237fead6SMichael Halcrow unsigned char sig[ECRYPTFS_SIG_SIZE];
54237fead6SMichael Halcrow unsigned char enc_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES];
55237fead6SMichael Halcrow };
56237fead6SMichael Halcrow
57237fead6SMichael Halcrow struct ecryptfs_auth_tok_list {
58237fead6SMichael Halcrow struct ecryptfs_auth_tok *auth_tok;
59237fead6SMichael Halcrow struct list_head list;
60237fead6SMichael Halcrow };
61237fead6SMichael Halcrow
62237fead6SMichael Halcrow struct ecryptfs_crypt_stat;
63237fead6SMichael Halcrow struct ecryptfs_mount_crypt_stat;
64237fead6SMichael Halcrow
65237fead6SMichael Halcrow struct ecryptfs_page_crypt_context {
66237fead6SMichael Halcrow struct page *page;
67237fead6SMichael Halcrow #define ECRYPTFS_PREPARE_COMMIT_MODE 0
68237fead6SMichael Halcrow #define ECRYPTFS_WRITEPAGE_MODE 1
69237fead6SMichael Halcrow unsigned int mode;
70237fead6SMichael Halcrow union {
71237fead6SMichael Halcrow struct file *lower_file;
72237fead6SMichael Halcrow struct writeback_control *wbc;
73237fead6SMichael Halcrow } param;
74237fead6SMichael Halcrow };
75237fead6SMichael Halcrow
761252cc3bSRoberto Sassu #if defined(CONFIG_ENCRYPTED_KEYS) || defined(CONFIG_ENCRYPTED_KEYS_MODULE)
771252cc3bSRoberto Sassu static inline struct ecryptfs_auth_tok *
ecryptfs_get_encrypted_key_payload_data(struct key * key)781252cc3bSRoberto Sassu ecryptfs_get_encrypted_key_payload_data(struct key *key)
791252cc3bSRoberto Sassu {
80f66665c0SEric Biggers struct encrypted_key_payload *payload;
81f66665c0SEric Biggers
82f66665c0SEric Biggers if (key->type != &key_type_encrypted)
831252cc3bSRoberto Sassu return NULL;
84f66665c0SEric Biggers
85f66665c0SEric Biggers payload = key->payload.data[0];
86f66665c0SEric Biggers if (!payload)
87f66665c0SEric Biggers return ERR_PTR(-EKEYREVOKED);
88f66665c0SEric Biggers
89f66665c0SEric Biggers return (struct ecryptfs_auth_tok *)payload->payload_data;
901252cc3bSRoberto Sassu }
911252cc3bSRoberto Sassu
ecryptfs_get_encrypted_key(char * sig)921252cc3bSRoberto Sassu static inline struct key *ecryptfs_get_encrypted_key(char *sig)
931252cc3bSRoberto Sassu {
94028db3e2SLinus Torvalds return request_key(&key_type_encrypted, sig, NULL);
951252cc3bSRoberto Sassu }
961252cc3bSRoberto Sassu
971252cc3bSRoberto Sassu #else
981252cc3bSRoberto Sassu static inline struct ecryptfs_auth_tok *
ecryptfs_get_encrypted_key_payload_data(struct key * key)991252cc3bSRoberto Sassu ecryptfs_get_encrypted_key_payload_data(struct key *key)
1001252cc3bSRoberto Sassu {
1011252cc3bSRoberto Sassu return NULL;
1021252cc3bSRoberto Sassu }
1031252cc3bSRoberto Sassu
ecryptfs_get_encrypted_key(char * sig)1041252cc3bSRoberto Sassu static inline struct key *ecryptfs_get_encrypted_key(char *sig)
1051252cc3bSRoberto Sassu {
1061252cc3bSRoberto Sassu return ERR_PTR(-ENOKEY);
1071252cc3bSRoberto Sassu }
1081252cc3bSRoberto Sassu
1091252cc3bSRoberto Sassu #endif /* CONFIG_ENCRYPTED_KEYS */
1101252cc3bSRoberto Sassu
111237fead6SMichael Halcrow static inline struct ecryptfs_auth_tok *
ecryptfs_get_key_payload_data(struct key * key)112237fead6SMichael Halcrow ecryptfs_get_key_payload_data(struct key *key)
113237fead6SMichael Halcrow {
1141252cc3bSRoberto Sassu struct ecryptfs_auth_tok *auth_tok;
115f66665c0SEric Biggers struct user_key_payload *ukp;
1161252cc3bSRoberto Sassu
1171252cc3bSRoberto Sassu auth_tok = ecryptfs_get_encrypted_key_payload_data(key);
118f66665c0SEric Biggers if (auth_tok)
1191252cc3bSRoberto Sassu return auth_tok;
120f66665c0SEric Biggers
121f66665c0SEric Biggers ukp = user_key_payload_locked(key);
122f66665c0SEric Biggers if (!ukp)
123f66665c0SEric Biggers return ERR_PTR(-EKEYREVOKED);
124f66665c0SEric Biggers
125f66665c0SEric Biggers return (struct ecryptfs_auth_tok *)ukp->data;
126237fead6SMichael Halcrow }
127237fead6SMichael Halcrow
128237fead6SMichael Halcrow #define ECRYPTFS_MAX_KEYSET_SIZE 1024
1292a559a8bSColin Ian King #define ECRYPTFS_MAX_CIPHER_NAME_SIZE 31
130237fead6SMichael Halcrow #define ECRYPTFS_MAX_NUM_ENC_KEYS 64
131237fead6SMichael Halcrow #define ECRYPTFS_MAX_IV_BYTES 16 /* 128 bits */
132237fead6SMichael Halcrow #define ECRYPTFS_SALT_BYTES 2
133237fead6SMichael Halcrow #define MAGIC_ECRYPTFS_MARKER 0x3c81b7f5
134237fead6SMichael Halcrow #define MAGIC_ECRYPTFS_MARKER_SIZE_BYTES 8 /* 4*2 */
13545eaab79SMichael Halcrow #define ECRYPTFS_FILE_SIZE_BYTES (sizeof(u64))
136778aeb42STyler Hicks #define ECRYPTFS_SIZE_AND_MARKER_BYTES (ECRYPTFS_FILE_SIZE_BYTES \
137778aeb42STyler Hicks + MAGIC_ECRYPTFS_MARKER_SIZE_BYTES)
138237fead6SMichael Halcrow #define ECRYPTFS_DEFAULT_CIPHER "aes"
139237fead6SMichael Halcrow #define ECRYPTFS_DEFAULT_KEY_BYTES 16
140565d9724SMichael Halcrow #define ECRYPTFS_DEFAULT_HASH "md5"
1419c79f34fSMichael Halcrow #define ECRYPTFS_TAG_70_DIGEST ECRYPTFS_DEFAULT_HASH
14288b4a07eSMichael Halcrow #define ECRYPTFS_TAG_1_PACKET_TYPE 0x01
143237fead6SMichael Halcrow #define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C
144237fead6SMichael Halcrow #define ECRYPTFS_TAG_11_PACKET_TYPE 0xED
14588b4a07eSMichael Halcrow #define ECRYPTFS_TAG_64_PACKET_TYPE 0x40
14688b4a07eSMichael Halcrow #define ECRYPTFS_TAG_65_PACKET_TYPE 0x41
14788b4a07eSMichael Halcrow #define ECRYPTFS_TAG_66_PACKET_TYPE 0x42
14888b4a07eSMichael Halcrow #define ECRYPTFS_TAG_67_PACKET_TYPE 0x43
1499c79f34fSMichael Halcrow #define ECRYPTFS_TAG_70_PACKET_TYPE 0x46 /* FNEK-encrypted filename
1509c79f34fSMichael Halcrow * as dentry name */
1519c79f34fSMichael Halcrow #define ECRYPTFS_TAG_71_PACKET_TYPE 0x47 /* FNEK-encrypted filename in
1529c79f34fSMichael Halcrow * metadata */
1539c79f34fSMichael Halcrow #define ECRYPTFS_TAG_72_PACKET_TYPE 0x48 /* FEK-encrypted filename as
1549c79f34fSMichael Halcrow * dentry name */
1559c79f34fSMichael Halcrow #define ECRYPTFS_TAG_73_PACKET_TYPE 0x49 /* FEK-encrypted filename as
1569c79f34fSMichael Halcrow * metadata */
15748399c0bSTyler Hicks #define ECRYPTFS_MIN_PKT_LEN_SIZE 1 /* Min size to specify packet length */
15848399c0bSTyler Hicks #define ECRYPTFS_MAX_PKT_LEN_SIZE 2 /* Pass at least this many bytes to
15948399c0bSTyler Hicks * ecryptfs_parse_packet_length() and
16048399c0bSTyler Hicks * ecryptfs_write_packet_length()
16148399c0bSTyler Hicks */
1629c79f34fSMichael Halcrow /* Constraint: ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES >=
1639c79f34fSMichael Halcrow * ECRYPTFS_MAX_IV_BYTES */
1649c79f34fSMichael Halcrow #define ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES 16
1659c79f34fSMichael Halcrow #define ECRYPTFS_NON_NULL 0x42 /* A reasonable substitute for NULL */
166237fead6SMichael Halcrow #define MD5_DIGEST_SIZE 16
1679c79f34fSMichael Halcrow #define ECRYPTFS_TAG_70_DIGEST_SIZE MD5_DIGEST_SIZE
1684a26620dSTyler Hicks #define ECRYPTFS_TAG_70_MIN_METADATA_SIZE (1 + ECRYPTFS_MIN_PKT_LEN_SIZE \
1694a26620dSTyler Hicks + ECRYPTFS_SIG_SIZE + 1 + 1)
1704a26620dSTyler Hicks #define ECRYPTFS_TAG_70_MAX_METADATA_SIZE (1 + ECRYPTFS_MAX_PKT_LEN_SIZE \
1714a26620dSTyler Hicks + ECRYPTFS_SIG_SIZE + 1 + 1)
1729c79f34fSMichael Halcrow #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FEK_ENCRYPTED."
1739c79f34fSMichael Halcrow #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX_SIZE 23
1749c79f34fSMichael Halcrow #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FNEK_ENCRYPTED."
1759c79f34fSMichael Halcrow #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE 24
1769c79f34fSMichael Halcrow #define ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN (18 + 1 + 4 + 1 + 32)
177237fead6SMichael Halcrow
178290502beSKees Cook #ifdef CONFIG_ECRYPT_FS_MESSAGING
179290502beSKees Cook # define ECRYPTFS_VERSIONING_MASK_MESSAGING (ECRYPTFS_VERSIONING_DEVMISC \
180290502beSKees Cook | ECRYPTFS_VERSIONING_PUBKEY)
181290502beSKees Cook #else
182290502beSKees Cook # define ECRYPTFS_VERSIONING_MASK_MESSAGING 0
183290502beSKees Cook #endif
184290502beSKees Cook
185290502beSKees Cook #define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \
186290502beSKees Cook | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \
187290502beSKees Cook | ECRYPTFS_VERSIONING_XATTR \
188290502beSKees Cook | ECRYPTFS_VERSIONING_MULTKEY \
189290502beSKees Cook | ECRYPTFS_VERSIONING_MASK_MESSAGING \
190290502beSKees Cook | ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION)
191f4aad16aSMichael Halcrow struct ecryptfs_key_sig {
192f4aad16aSMichael Halcrow struct list_head crypt_stat_list;
1937762e230SRoberto Sassu char keysig[ECRYPTFS_SIG_SIZE_HEX + 1];
194f4aad16aSMichael Halcrow };
195f4aad16aSMichael Halcrow
196a34f60f7SMichael Halcrow struct ecryptfs_filename {
197a34f60f7SMichael Halcrow struct list_head crypt_stat_list;
198a34f60f7SMichael Halcrow #define ECRYPTFS_FILENAME_CONTAINS_DECRYPTED 0x00000001
199a34f60f7SMichael Halcrow u32 flags;
200a34f60f7SMichael Halcrow u32 seq_no;
201a34f60f7SMichael Halcrow char *filename;
202a34f60f7SMichael Halcrow char *encrypted_filename;
203a34f60f7SMichael Halcrow size_t filename_size;
204a34f60f7SMichael Halcrow size_t encrypted_filename_size;
205a34f60f7SMichael Halcrow char fnek_sig[ECRYPTFS_SIG_SIZE_HEX];
206a34f60f7SMichael Halcrow char dentry_name[ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN + 1];
207a34f60f7SMichael Halcrow };
208a34f60f7SMichael Halcrow
209237fead6SMichael Halcrow /**
210237fead6SMichael Halcrow * This is the primary struct associated with each encrypted file.
211237fead6SMichael Halcrow *
212237fead6SMichael Halcrow * TODO: cache align/pack?
213237fead6SMichael Halcrow */
214237fead6SMichael Halcrow struct ecryptfs_crypt_stat {
215237fead6SMichael Halcrow #define ECRYPTFS_STRUCT_INITIALIZED 0x00000001
216237fead6SMichael Halcrow #define ECRYPTFS_POLICY_APPLIED 0x00000002
217fed8859bSTyler Hicks #define ECRYPTFS_ENCRYPTED 0x00000004
218fed8859bSTyler Hicks #define ECRYPTFS_SECURITY_WARNING 0x00000008
219fed8859bSTyler Hicks #define ECRYPTFS_ENABLE_HMAC 0x00000010
220fed8859bSTyler Hicks #define ECRYPTFS_ENCRYPT_IV_PAGES 0x00000020
221fed8859bSTyler Hicks #define ECRYPTFS_KEY_VALID 0x00000040
222fed8859bSTyler Hicks #define ECRYPTFS_METADATA_IN_XATTR 0x00000080
223fed8859bSTyler Hicks #define ECRYPTFS_VIEW_AS_ENCRYPTED 0x00000100
224fed8859bSTyler Hicks #define ECRYPTFS_KEY_SET 0x00000200
225fed8859bSTyler Hicks #define ECRYPTFS_ENCRYPT_FILENAMES 0x00000400
226fed8859bSTyler Hicks #define ECRYPTFS_ENCFN_USE_MOUNT_FNEK 0x00000800
227fed8859bSTyler Hicks #define ECRYPTFS_ENCFN_USE_FEK 0x00001000
228fed8859bSTyler Hicks #define ECRYPTFS_UNLINK_SIGS 0x00002000
2293aeb86eaSTyler Hicks #define ECRYPTFS_I_SIZE_INITIALIZED 0x00004000
230237fead6SMichael Halcrow u32 flags;
231237fead6SMichael Halcrow unsigned int file_version;
232237fead6SMichael Halcrow size_t iv_bytes;
233fa3ef1cbSTyler Hicks size_t metadata_size;
234237fead6SMichael Halcrow size_t extent_size; /* Data extent size; default is 4096 */
235237fead6SMichael Halcrow size_t key_size;
236237fead6SMichael Halcrow size_t extent_shift;
237237fead6SMichael Halcrow unsigned int extent_mask;
238237fead6SMichael Halcrow struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
2393095e8e3SHerbert Xu struct crypto_skcipher *tfm;
2403095e8e3SHerbert Xu struct crypto_shash *hash_tfm; /* Crypto context for generating
241237fead6SMichael Halcrow * the initialization vectors */
2422a559a8bSColin Ian King unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
243237fead6SMichael Halcrow unsigned char key[ECRYPTFS_MAX_KEY_BYTES];
244237fead6SMichael Halcrow unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES];
245f4aad16aSMichael Halcrow struct list_head keysig_list;
246f4aad16aSMichael Halcrow struct mutex keysig_list_mutex;
247237fead6SMichael Halcrow struct mutex cs_tfm_mutex;
248237fead6SMichael Halcrow struct mutex cs_mutex;
249237fead6SMichael Halcrow };
250237fead6SMichael Halcrow
251237fead6SMichael Halcrow /* inode private data. */
252237fead6SMichael Halcrow struct ecryptfs_inode_info {
253237fead6SMichael Halcrow struct inode vfs_inode;
254237fead6SMichael Halcrow struct inode *wii_inode;
255332ab16fSTyler Hicks struct mutex lower_file_mutex;
256332ab16fSTyler Hicks atomic_t lower_file_count;
257da0102a1SMichael Halcrow struct file *lower_file;
258237fead6SMichael Halcrow struct ecryptfs_crypt_stat crypt_stat;
259237fead6SMichael Halcrow };
260237fead6SMichael Halcrow
261237fead6SMichael Halcrow /* dentry private data. Each dentry must keep track of a lower
262237fead6SMichael Halcrow * vfsmount too. */
263237fead6SMichael Halcrow struct ecryptfs_dentry_info {
264b65d34fdSJosef "Jeff" Sipek struct path lower_path;
2652edbfbf1SAl Viro struct rcu_head rcu;
2662edbfbf1SAl Viro };
267237fead6SMichael Halcrow
2686c6f57f3SMichael Halcrow /**
26945eaab79SMichael Halcrow * ecryptfs_global_auth_tok - A key used to encrypt all new files under the mountpoint
27045eaab79SMichael Halcrow * @flags: Status flags
27145eaab79SMichael Halcrow * @mount_crypt_stat_list: These auth_toks hang off the mount-wide
27245eaab79SMichael Halcrow * cryptographic context. Every time a new
27345eaab79SMichael Halcrow * inode comes into existence, eCryptfs copies
27445eaab79SMichael Halcrow * the auth_toks on that list to the set of
27545eaab79SMichael Halcrow * auth_toks on the inode's crypt_stat
27645eaab79SMichael Halcrow * @global_auth_tok_key: The key from the user's keyring for the sig
27745eaab79SMichael Halcrow * @global_auth_tok: The key contents
27845eaab79SMichael Halcrow * @sig: The key identifier
27945eaab79SMichael Halcrow *
2806c6f57f3SMichael Halcrow * ecryptfs_global_auth_tok structs refer to authentication token keys
2816c6f57f3SMichael Halcrow * in the user keyring that apply to newly created files. A list of
2826c6f57f3SMichael Halcrow * these objects hangs off of the mount_crypt_stat struct for any
2836c6f57f3SMichael Halcrow * given eCryptfs mount. This struct maintains a reference to both the
2846c6f57f3SMichael Halcrow * key contents and the key itself so that the key can be put on
2856c6f57f3SMichael Halcrow * unmount.
2866c6f57f3SMichael Halcrow */
287f4aad16aSMichael Halcrow struct ecryptfs_global_auth_tok {
288f4aad16aSMichael Halcrow #define ECRYPTFS_AUTH_TOK_INVALID 0x00000001
28984814d64STyler Hicks #define ECRYPTFS_AUTH_TOK_FNEK 0x00000002
290f4aad16aSMichael Halcrow u32 flags;
29145eaab79SMichael Halcrow struct list_head mount_crypt_stat_list;
29245eaab79SMichael Halcrow struct key *global_auth_tok_key;
29345eaab79SMichael Halcrow unsigned char sig[ECRYPTFS_SIG_SIZE_HEX + 1];
294f4aad16aSMichael Halcrow };
295f4aad16aSMichael Halcrow
2966c6f57f3SMichael Halcrow /**
29745eaab79SMichael Halcrow * ecryptfs_key_tfm - Persistent key tfm
29845eaab79SMichael Halcrow * @key_tfm: crypto API handle to the key
29945eaab79SMichael Halcrow * @key_size: Key size in bytes
30045eaab79SMichael Halcrow * @key_tfm_mutex: Mutex to ensure only one operation in eCryptfs is
30145eaab79SMichael Halcrow * using the persistent TFM at any point in time
30245eaab79SMichael Halcrow * @key_tfm_list: Handle to hang this off the module-wide TFM list
30345eaab79SMichael Halcrow * @cipher_name: String name for the cipher for this TFM
30445eaab79SMichael Halcrow *
3056c6f57f3SMichael Halcrow * Typically, eCryptfs will use the same ciphers repeatedly throughout
3066c6f57f3SMichael Halcrow * the course of its operations. In order to avoid unnecessarily
3076c6f57f3SMichael Halcrow * destroying and initializing the same cipher repeatedly, eCryptfs
3086c6f57f3SMichael Halcrow * keeps a list of crypto API contexts around to use when needed.
3096c6f57f3SMichael Halcrow */
310f4aad16aSMichael Halcrow struct ecryptfs_key_tfm {
3113095e8e3SHerbert Xu struct crypto_skcipher *key_tfm;
312f4aad16aSMichael Halcrow size_t key_size;
313f4aad16aSMichael Halcrow struct mutex key_tfm_mutex;
31445eaab79SMichael Halcrow struct list_head key_tfm_list;
315f4aad16aSMichael Halcrow unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
316f4aad16aSMichael Halcrow };
317f4aad16aSMichael Halcrow
318af440f52SEric Sandeen extern struct mutex key_tfm_list_mutex;
319af440f52SEric Sandeen
320237fead6SMichael Halcrow /**
321237fead6SMichael Halcrow * This struct is to enable a mount-wide passphrase/salt combo. This
322237fead6SMichael Halcrow * is more or less a stopgap to provide similar functionality to other
323237fead6SMichael Halcrow * crypto filesystems like EncFS or CFS until full policy support is
324237fead6SMichael Halcrow * implemented in eCryptfs.
325237fead6SMichael Halcrow */
326237fead6SMichael Halcrow struct ecryptfs_mount_crypt_stat {
327237fead6SMichael Halcrow /* Pointers to memory we do not own, do not free these */
328237fead6SMichael Halcrow #define ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED 0x00000001
32917398957SMichael Halcrow #define ECRYPTFS_XATTR_METADATA_ENABLED 0x00000002
33017398957SMichael Halcrow #define ECRYPTFS_ENCRYPTED_VIEW_ENABLED 0x00000004
331f4aad16aSMichael Halcrow #define ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED 0x00000008
3329c79f34fSMichael Halcrow #define ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES 0x00000010
3339c79f34fSMichael Halcrow #define ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK 0x00000020
3349c79f34fSMichael Halcrow #define ECRYPTFS_GLOBAL_ENCFN_USE_FEK 0x00000040
335f16feb51SRoberto Sassu #define ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY 0x00000080
336237fead6SMichael Halcrow u32 flags;
337f4aad16aSMichael Halcrow struct list_head global_auth_tok_list;
338f4aad16aSMichael Halcrow struct mutex global_auth_tok_list_mutex;
339237fead6SMichael Halcrow size_t global_default_cipher_key_size;
3409c79f34fSMichael Halcrow size_t global_default_fn_cipher_key_bytes;
341237fead6SMichael Halcrow unsigned char global_default_cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE
342237fead6SMichael Halcrow + 1];
3439c79f34fSMichael Halcrow unsigned char global_default_fn_cipher_name[
3449c79f34fSMichael Halcrow ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
3459c79f34fSMichael Halcrow char global_default_fnek_sig[ECRYPTFS_SIG_SIZE_HEX + 1];
346237fead6SMichael Halcrow };
347237fead6SMichael Halcrow
348237fead6SMichael Halcrow /* superblock private data. */
349237fead6SMichael Halcrow struct ecryptfs_sb_info {
350237fead6SMichael Halcrow struct super_block *wsi_sb;
351237fead6SMichael Halcrow struct ecryptfs_mount_crypt_stat mount_crypt_stat;
352237fead6SMichael Halcrow };
353237fead6SMichael Halcrow
354237fead6SMichael Halcrow /* file private data. */
355237fead6SMichael Halcrow struct ecryptfs_file_info {
356237fead6SMichael Halcrow struct file *wfi_file;
357237fead6SMichael Halcrow struct ecryptfs_crypt_stat *crypt_stat;
358237fead6SMichael Halcrow };
359237fead6SMichael Halcrow
360237fead6SMichael Halcrow /* auth_tok <=> encrypted_session_key mappings */
361237fead6SMichael Halcrow struct ecryptfs_auth_tok_list_item {
362237fead6SMichael Halcrow unsigned char encrypted_session_key[ECRYPTFS_MAX_KEY_BYTES];
363237fead6SMichael Halcrow struct list_head list;
364237fead6SMichael Halcrow struct ecryptfs_auth_tok auth_tok;
365237fead6SMichael Halcrow };
366237fead6SMichael Halcrow
36788b4a07eSMichael Halcrow struct ecryptfs_message {
368f66e883eSMichael Halcrow /* Can never be greater than ecryptfs_message_buf_len */
369f66e883eSMichael Halcrow /* Used to find the parent msg_ctx */
370f66e883eSMichael Halcrow /* Inherits from msg_ctx->index */
37188b4a07eSMichael Halcrow u32 index;
37288b4a07eSMichael Halcrow u32 data_len;
37388b4a07eSMichael Halcrow u8 data[];
37488b4a07eSMichael Halcrow };
37588b4a07eSMichael Halcrow
37688b4a07eSMichael Halcrow struct ecryptfs_msg_ctx {
377f66e883eSMichael Halcrow #define ECRYPTFS_MSG_CTX_STATE_FREE 0x01
378f66e883eSMichael Halcrow #define ECRYPTFS_MSG_CTX_STATE_PENDING 0x02
379f66e883eSMichael Halcrow #define ECRYPTFS_MSG_CTX_STATE_DONE 0x03
380f66e883eSMichael Halcrow #define ECRYPTFS_MSG_CTX_STATE_NO_REPLY 0x04
381f66e883eSMichael Halcrow u8 state;
382f66e883eSMichael Halcrow #define ECRYPTFS_MSG_HELO 100
383f66e883eSMichael Halcrow #define ECRYPTFS_MSG_QUIT 101
384f66e883eSMichael Halcrow #define ECRYPTFS_MSG_REQUEST 102
385f66e883eSMichael Halcrow #define ECRYPTFS_MSG_RESPONSE 103
386f66e883eSMichael Halcrow u8 type;
387f66e883eSMichael Halcrow u32 index;
388f66e883eSMichael Halcrow /* Counter converts to a sequence number. Each message sent
389f66e883eSMichael Halcrow * out for which we expect a response has an associated
390f66e883eSMichael Halcrow * sequence number. The response must have the same sequence
391f66e883eSMichael Halcrow * number as the counter for the msg_stc for the message to be
392f66e883eSMichael Halcrow * valid. */
393f66e883eSMichael Halcrow u32 counter;
394f66e883eSMichael Halcrow size_t msg_size;
39588b4a07eSMichael Halcrow struct ecryptfs_message *msg;
39688b4a07eSMichael Halcrow struct task_struct *task;
39788b4a07eSMichael Halcrow struct list_head node;
398f66e883eSMichael Halcrow struct list_head daemon_out_list;
39988b4a07eSMichael Halcrow struct mutex mux;
40088b4a07eSMichael Halcrow };
40188b4a07eSMichael Halcrow
402f66e883eSMichael Halcrow struct ecryptfs_daemon {
403f66e883eSMichael Halcrow #define ECRYPTFS_DAEMON_IN_READ 0x00000001
404f66e883eSMichael Halcrow #define ECRYPTFS_DAEMON_IN_POLL 0x00000002
405f66e883eSMichael Halcrow #define ECRYPTFS_DAEMON_ZOMBIE 0x00000004
406f66e883eSMichael Halcrow #define ECRYPTFS_DAEMON_MISCDEV_OPEN 0x00000008
407f66e883eSMichael Halcrow u32 flags;
408f66e883eSMichael Halcrow u32 num_queued_msg_ctx;
4092ecaf55dSTyler Hicks struct file *file;
410f66e883eSMichael Halcrow struct mutex mux;
411f66e883eSMichael Halcrow struct list_head msg_ctx_out_queue;
412f66e883eSMichael Halcrow wait_queue_head_t wait;
413f66e883eSMichael Halcrow struct hlist_node euid_chain;
41488b4a07eSMichael Halcrow };
41588b4a07eSMichael Halcrow
416290502beSKees Cook #ifdef CONFIG_ECRYPT_FS_MESSAGING
417f66e883eSMichael Halcrow extern struct mutex ecryptfs_daemon_hash_mux;
418290502beSKees Cook #endif
419f66e883eSMichael Halcrow
420157f1071STyler Hicks static inline size_t
ecryptfs_lower_header_size(struct ecryptfs_crypt_stat * crypt_stat)421157f1071STyler Hicks ecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat)
422157f1071STyler Hicks {
423157f1071STyler Hicks if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
424157f1071STyler Hicks return 0;
425fa3ef1cbSTyler Hicks return crypt_stat->metadata_size;
426157f1071STyler Hicks }
427157f1071STyler Hicks
428237fead6SMichael Halcrow static inline struct ecryptfs_file_info *
ecryptfs_file_to_private(struct file * file)429237fead6SMichael Halcrow ecryptfs_file_to_private(struct file *file)
430237fead6SMichael Halcrow {
4310c6d7d5dSJoe Perches return file->private_data;
432237fead6SMichael Halcrow }
433237fead6SMichael Halcrow
434237fead6SMichael Halcrow static inline void
ecryptfs_set_file_private(struct file * file,struct ecryptfs_file_info * file_info)435237fead6SMichael Halcrow ecryptfs_set_file_private(struct file *file,
436237fead6SMichael Halcrow struct ecryptfs_file_info *file_info)
437237fead6SMichael Halcrow {
438237fead6SMichael Halcrow file->private_data = file_info;
439237fead6SMichael Halcrow }
440237fead6SMichael Halcrow
ecryptfs_file_to_lower(struct file * file)441237fead6SMichael Halcrow static inline struct file *ecryptfs_file_to_lower(struct file *file)
442237fead6SMichael Halcrow {
443237fead6SMichael Halcrow return ((struct ecryptfs_file_info *)file->private_data)->wfi_file;
444237fead6SMichael Halcrow }
445237fead6SMichael Halcrow
446237fead6SMichael Halcrow static inline void
ecryptfs_set_file_lower(struct file * file,struct file * lower_file)447237fead6SMichael Halcrow ecryptfs_set_file_lower(struct file *file, struct file *lower_file)
448237fead6SMichael Halcrow {
449237fead6SMichael Halcrow ((struct ecryptfs_file_info *)file->private_data)->wfi_file =
450237fead6SMichael Halcrow lower_file;
451237fead6SMichael Halcrow }
452237fead6SMichael Halcrow
453237fead6SMichael Halcrow static inline struct ecryptfs_inode_info *
ecryptfs_inode_to_private(struct inode * inode)454237fead6SMichael Halcrow ecryptfs_inode_to_private(struct inode *inode)
455237fead6SMichael Halcrow {
456237fead6SMichael Halcrow return container_of(inode, struct ecryptfs_inode_info, vfs_inode);
457237fead6SMichael Halcrow }
458237fead6SMichael Halcrow
ecryptfs_inode_to_lower(struct inode * inode)459237fead6SMichael Halcrow static inline struct inode *ecryptfs_inode_to_lower(struct inode *inode)
460237fead6SMichael Halcrow {
461237fead6SMichael Halcrow return ecryptfs_inode_to_private(inode)->wii_inode;
462237fead6SMichael Halcrow }
463237fead6SMichael Halcrow
464237fead6SMichael Halcrow static inline void
ecryptfs_set_inode_lower(struct inode * inode,struct inode * lower_inode)465237fead6SMichael Halcrow ecryptfs_set_inode_lower(struct inode *inode, struct inode *lower_inode)
466237fead6SMichael Halcrow {
467237fead6SMichael Halcrow ecryptfs_inode_to_private(inode)->wii_inode = lower_inode;
468237fead6SMichael Halcrow }
469237fead6SMichael Halcrow
470237fead6SMichael Halcrow static inline struct ecryptfs_sb_info *
ecryptfs_superblock_to_private(struct super_block * sb)471237fead6SMichael Halcrow ecryptfs_superblock_to_private(struct super_block *sb)
472237fead6SMichael Halcrow {
473237fead6SMichael Halcrow return (struct ecryptfs_sb_info *)sb->s_fs_info;
474237fead6SMichael Halcrow }
475237fead6SMichael Halcrow
476237fead6SMichael Halcrow static inline void
ecryptfs_set_superblock_private(struct super_block * sb,struct ecryptfs_sb_info * sb_info)477237fead6SMichael Halcrow ecryptfs_set_superblock_private(struct super_block *sb,
478237fead6SMichael Halcrow struct ecryptfs_sb_info *sb_info)
479237fead6SMichael Halcrow {
480237fead6SMichael Halcrow sb->s_fs_info = sb_info;
481237fead6SMichael Halcrow }
482237fead6SMichael Halcrow
483237fead6SMichael Halcrow static inline struct super_block *
ecryptfs_superblock_to_lower(struct super_block * sb)484237fead6SMichael Halcrow ecryptfs_superblock_to_lower(struct super_block *sb)
485237fead6SMichael Halcrow {
486237fead6SMichael Halcrow return ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb;
487237fead6SMichael Halcrow }
488237fead6SMichael Halcrow
489237fead6SMichael Halcrow static inline void
ecryptfs_set_superblock_lower(struct super_block * sb,struct super_block * lower_sb)490237fead6SMichael Halcrow ecryptfs_set_superblock_lower(struct super_block *sb,
491237fead6SMichael Halcrow struct super_block *lower_sb)
492237fead6SMichael Halcrow {
493237fead6SMichael Halcrow ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb = lower_sb;
494237fead6SMichael Halcrow }
495237fead6SMichael Halcrow
496237fead6SMichael Halcrow static inline void
ecryptfs_set_dentry_private(struct dentry * dentry,struct ecryptfs_dentry_info * dentry_info)497237fead6SMichael Halcrow ecryptfs_set_dentry_private(struct dentry *dentry,
498237fead6SMichael Halcrow struct ecryptfs_dentry_info *dentry_info)
499237fead6SMichael Halcrow {
500237fead6SMichael Halcrow dentry->d_fsdata = dentry_info;
501237fead6SMichael Halcrow }
502237fead6SMichael Halcrow
503237fead6SMichael Halcrow static inline struct dentry *
ecryptfs_dentry_to_lower(struct dentry * dentry)504237fead6SMichael Halcrow ecryptfs_dentry_to_lower(struct dentry *dentry)
505237fead6SMichael Halcrow {
506b65d34fdSJosef "Jeff" Sipek return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry;
507237fead6SMichael Halcrow }
508237fead6SMichael Halcrow
50988569546SAl Viro static inline const struct path *
ecryptfs_dentry_to_lower_path(struct dentry * dentry)5103dadecceSAl Viro ecryptfs_dentry_to_lower_path(struct dentry *dentry)
5113dadecceSAl Viro {
5123dadecceSAl Viro return &((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path;
5133dadecceSAl Viro }
5143dadecceSAl Viro
515237fead6SMichael Halcrow #define ecryptfs_printk(type, fmt, arg...) \
516d0eb2d86STom Rix __ecryptfs_printk(type "%s: " fmt, __func__, ## arg)
517b9075fa9SJoe Perches __printf(1, 2)
518237fead6SMichael Halcrow void __ecryptfs_printk(const char *fmt, ...);
519237fead6SMichael Halcrow
520237fead6SMichael Halcrow extern const struct file_operations ecryptfs_main_fops;
521237fead6SMichael Halcrow extern const struct file_operations ecryptfs_dir_fops;
522754661f1SArjan van de Ven extern const struct inode_operations ecryptfs_main_iops;
523754661f1SArjan van de Ven extern const struct inode_operations ecryptfs_dir_iops;
524754661f1SArjan van de Ven extern const struct inode_operations ecryptfs_symlink_iops;
525ee9b6d61SJosef 'Jeff' Sipek extern const struct super_operations ecryptfs_sops;
5265a3fd05aSAl Viro extern const struct dentry_operations ecryptfs_dops;
5277f09410bSAlexey Dobriyan extern const struct address_space_operations ecryptfs_aops;
528237fead6SMichael Halcrow extern int ecryptfs_verbosity;
52988b4a07eSMichael Halcrow extern unsigned int ecryptfs_message_buf_len;
53088b4a07eSMichael Halcrow extern signed long ecryptfs_message_wait_timeout;
53188b4a07eSMichael Halcrow extern unsigned int ecryptfs_number_of_users;
532237fead6SMichael Halcrow
533237fead6SMichael Halcrow extern struct kmem_cache *ecryptfs_auth_tok_list_item_cache;
534237fead6SMichael Halcrow extern struct kmem_cache *ecryptfs_file_info_cache;
535237fead6SMichael Halcrow extern struct kmem_cache *ecryptfs_dentry_info_cache;
536237fead6SMichael Halcrow extern struct kmem_cache *ecryptfs_inode_info_cache;
537237fead6SMichael Halcrow extern struct kmem_cache *ecryptfs_sb_info_cache;
53830632870STyler Hicks extern struct kmem_cache *ecryptfs_header_cache;
539dd2a3b7aSMichael Halcrow extern struct kmem_cache *ecryptfs_xattr_cache;
540eb95e7ffSMichael Halcrow extern struct kmem_cache *ecryptfs_key_record_cache;
541f4aad16aSMichael Halcrow extern struct kmem_cache *ecryptfs_key_sig_cache;
542f4aad16aSMichael Halcrow extern struct kmem_cache *ecryptfs_global_auth_tok_cache;
543f4aad16aSMichael Halcrow extern struct kmem_cache *ecryptfs_key_tfm_cache;
544237fead6SMichael Halcrow
545c4f79073STyler Hicks struct inode *ecryptfs_get_inode(struct inode *lower_inode,
546c4f79073STyler Hicks struct super_block *sb);
5473aeb86eaSTyler Hicks void ecryptfs_i_size_init(const char *page_virt, struct inode *inode);
548e3ccaa97STyler Hicks int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
549e3ccaa97STyler Hicks struct inode *ecryptfs_inode);
550a34f60f7SMichael Halcrow int ecryptfs_decode_and_decrypt_filename(char **decrypted_name,
551a34f60f7SMichael Halcrow size_t *decrypted_name_size,
5520747fdb2SAl Viro struct super_block *sb,
553a34f60f7SMichael Halcrow const char *name, size_t name_size);
554237fead6SMichael Halcrow int ecryptfs_fill_zeros(struct file *file, loff_t new_length);
555a34f60f7SMichael Halcrow int ecryptfs_encrypt_and_encode_filename(
556a34f60f7SMichael Halcrow char **encoded_name,
557a34f60f7SMichael Halcrow size_t *encoded_name_size,
558a34f60f7SMichael Halcrow struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
559a34f60f7SMichael Halcrow const char *name, size_t name_size);
560237fead6SMichael Halcrow struct dentry *ecryptfs_lower_dentry(struct dentry *this_dentry);
561237fead6SMichael Halcrow void ecryptfs_dump_hex(char *data, int bytes);
562237fead6SMichael Halcrow int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg,
563237fead6SMichael Halcrow int sg_size);
564237fead6SMichael Halcrow int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat);
565237fead6SMichael Halcrow void ecryptfs_rotate_iv(unsigned char *iv);
566e81f3340SHerbert Xu int ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat);
567fcd12835SMichael Halcrow void ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat);
568fcd12835SMichael Halcrow void ecryptfs_destroy_mount_crypt_stat(
569237fead6SMichael Halcrow struct ecryptfs_mount_crypt_stat *mount_crypt_stat);
570237fead6SMichael Halcrow int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat);
571b6c1d8fcSMichael Halcrow int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode);
5726b9c0e81SMatthew Wilcox (Oracle) int ecryptfs_encrypt_page(struct folio *folio);
573*c15b8146SMatthew Wilcox (Oracle) int ecryptfs_decrypt_page(struct folio *folio);
574b59db43aSTyler Hicks int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry,
575b59db43aSTyler Hicks struct inode *ecryptfs_inode);
576d7cdc5feSMichael Halcrow int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry);
577b59db43aSTyler Hicks int ecryptfs_new_file_context(struct inode *ecryptfs_inode);
578f4e60e6bSTyler Hicks void ecryptfs_write_crypt_stat_flags(char *page_virt,
579f4e60e6bSTyler Hicks struct ecryptfs_crypt_stat *crypt_stat,
580f4e60e6bSTyler Hicks size_t *written);
581778aeb42STyler Hicks int ecryptfs_read_and_validate_header_region(struct inode *inode);
582778aeb42STyler Hicks int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry,
5833b06b3ebSTyler Hicks struct inode *inode);
5849c79f34fSMichael Halcrow u8 ecryptfs_code_for_cipher_string(char *cipher_name, size_t key_bytes);
58519e66a67STrevor Highland int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code);
586237fead6SMichael Halcrow void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat);
587237fead6SMichael Halcrow int ecryptfs_generate_key_packet_set(char *dest_base,
588237fead6SMichael Halcrow struct ecryptfs_crypt_stat *crypt_stat,
589237fead6SMichael Halcrow struct dentry *ecryptfs_dentry,
590237fead6SMichael Halcrow size_t *len, size_t max);
591237fead6SMichael Halcrow int
592237fead6SMichael Halcrow ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
593237fead6SMichael Halcrow unsigned char *src, struct dentry *ecryptfs_dentry);
594237fead6SMichael Halcrow int ecryptfs_truncate(struct dentry *dentry, loff_t new_length);
595d7cdc5feSMichael Halcrow ssize_t
596ce23e640SAl Viro ecryptfs_getxattr_lower(struct dentry *lower_dentry, struct inode *lower_inode,
597ce23e640SAl Viro const char *name, void *value, size_t size);
598dd2a3b7aSMichael Halcrow int
5993767e255SAl Viro ecryptfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
6003767e255SAl Viro const void *value, size_t size, int flags);
601d7cdc5feSMichael Halcrow int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode);
602290502beSKees Cook #ifdef CONFIG_ECRYPT_FS_MESSAGING
6032ecaf55dSTyler Hicks int ecryptfs_process_response(struct ecryptfs_daemon *daemon,
6042ecaf55dSTyler Hicks struct ecryptfs_message *msg, u32 seq);
605624ae528STyler Hicks int ecryptfs_send_message(char *data, int data_len,
60688b4a07eSMichael Halcrow struct ecryptfs_msg_ctx **msg_ctx);
60788b4a07eSMichael Halcrow int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
60888b4a07eSMichael Halcrow struct ecryptfs_message **emsg);
609624ae528STyler Hicks int ecryptfs_init_messaging(void);
610624ae528STyler Hicks void ecryptfs_release_messaging(void);
611290502beSKees Cook #else
ecryptfs_init_messaging(void)612290502beSKees Cook static inline int ecryptfs_init_messaging(void)
613290502beSKees Cook {
614290502beSKees Cook return 0;
615290502beSKees Cook }
ecryptfs_release_messaging(void)616290502beSKees Cook static inline void ecryptfs_release_messaging(void)
617290502beSKees Cook { }
ecryptfs_send_message(char * data,int data_len,struct ecryptfs_msg_ctx ** msg_ctx)618290502beSKees Cook static inline int ecryptfs_send_message(char *data, int data_len,
619290502beSKees Cook struct ecryptfs_msg_ctx **msg_ctx)
620290502beSKees Cook {
621290502beSKees Cook return -ENOTCONN;
622290502beSKees Cook }
ecryptfs_wait_for_response(struct ecryptfs_msg_ctx * msg_ctx,struct ecryptfs_message ** emsg)623290502beSKees Cook static inline int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
624290502beSKees Cook struct ecryptfs_message **emsg)
625290502beSKees Cook {
626290502beSKees Cook return -ENOMSG;
627290502beSKees Cook }
628290502beSKees Cook #endif
62988b4a07eSMichael Halcrow
630e77a56ddSMichael Halcrow void
631e77a56ddSMichael Halcrow ecryptfs_write_header_metadata(char *virt,
632e77a56ddSMichael Halcrow struct ecryptfs_crypt_stat *crypt_stat,
633e77a56ddSMichael Halcrow size_t *written);
634f4aad16aSMichael Halcrow int ecryptfs_add_keysig(struct ecryptfs_crypt_stat *crypt_stat, char *sig);
635f4aad16aSMichael Halcrow int
636f4aad16aSMichael Halcrow ecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
63784814d64STyler Hicks char *sig, u32 global_auth_tok_flags);
638f4aad16aSMichael Halcrow int ecryptfs_get_global_auth_tok_for_sig(
639f4aad16aSMichael Halcrow struct ecryptfs_global_auth_tok **global_auth_tok,
640f4aad16aSMichael Halcrow struct ecryptfs_mount_crypt_stat *mount_crypt_stat, char *sig);
641f4aad16aSMichael Halcrow int
642f4aad16aSMichael Halcrow ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
643f4aad16aSMichael Halcrow size_t key_size);
644f4aad16aSMichael Halcrow int ecryptfs_init_crypto(void);
645fcd12835SMichael Halcrow int ecryptfs_destroy_crypto(void);
646af440f52SEric Sandeen int ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm);
6473095e8e3SHerbert Xu int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_skcipher **tfm,
648f4aad16aSMichael Halcrow struct mutex **tfm_mutex,
649f4aad16aSMichael Halcrow char *cipher_name);
650f4aad16aSMichael Halcrow int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key,
651f4aad16aSMichael Halcrow struct ecryptfs_auth_tok **auth_tok,
652f4aad16aSMichael Halcrow char *sig);
653da0102a1SMichael Halcrow int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
654da0102a1SMichael Halcrow loff_t offset, size_t size);
655da0102a1SMichael Halcrow int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
656de5ced27SMatthew Wilcox (Oracle) struct folio *folio_for_lower,
657da0102a1SMichael Halcrow size_t offset_in_page, size_t size);
65848c1e44aSAl Viro int ecryptfs_write(struct inode *inode, char *data, loff_t offset, size_t size);
659da0102a1SMichael Halcrow int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
660da0102a1SMichael Halcrow struct inode *ecryptfs_inode);
661890d477aSMatthew Wilcox (Oracle) int ecryptfs_read_lower_page_segment(struct folio *folio_for_ecryptfs,
662da0102a1SMichael Halcrow pgoff_t page_index,
663da0102a1SMichael Halcrow size_t offset_in_page, size_t size,
664da0102a1SMichael Halcrow struct inode *ecryptfs_inode);
665f66e883eSMichael Halcrow int ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
666f66e883eSMichael Halcrow size_t *length_size);
667f66e883eSMichael Halcrow int ecryptfs_write_packet_length(char *dest, size_t size,
668f66e883eSMichael Halcrow size_t *packet_size_length);
669290502beSKees Cook #ifdef CONFIG_ECRYPT_FS_MESSAGING
670f66e883eSMichael Halcrow int ecryptfs_init_ecryptfs_miscdev(void);
671f66e883eSMichael Halcrow void ecryptfs_destroy_ecryptfs_miscdev(void);
672f66e883eSMichael Halcrow int ecryptfs_send_miscdev(char *data, size_t data_size,
673f66e883eSMichael Halcrow struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
674f66e883eSMichael Halcrow u16 msg_flags, struct ecryptfs_daemon *daemon);
675f66e883eSMichael Halcrow void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx);
676f66e883eSMichael Halcrow int
6772ecaf55dSTyler Hicks ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file);
678290502beSKees Cook int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
679290502beSKees Cook int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
680290502beSKees Cook #endif
681746f1e55SMichael Halcrow int ecryptfs_init_kthread(void);
682746f1e55SMichael Halcrow void ecryptfs_destroy_kthread(void);
683746f1e55SMichael Halcrow int ecryptfs_privileged_open(struct file **lower_file,
684746f1e55SMichael Halcrow struct dentry *lower_dentry,
685745ca247SDavid Howells struct vfsmount *lower_mnt,
686745ca247SDavid Howells const struct cred *cred);
6873b06b3ebSTyler Hicks int ecryptfs_get_lower_file(struct dentry *dentry, struct inode *inode);
688332ab16fSTyler Hicks void ecryptfs_put_lower_file(struct inode *inode);
6899c79f34fSMichael Halcrow int
6909c79f34fSMichael Halcrow ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
6919c79f34fSMichael Halcrow size_t *packet_size,
6929c79f34fSMichael Halcrow struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
6939c79f34fSMichael Halcrow char *filename, size_t filename_size);
6949c79f34fSMichael Halcrow int
6959c79f34fSMichael Halcrow ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
6969c79f34fSMichael Halcrow size_t *packet_size,
6979c79f34fSMichael Halcrow struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
6989c79f34fSMichael Halcrow char *data, size_t max_packet_size);
6994a26620dSTyler Hicks int ecryptfs_set_f_namelen(long *namelen, long lower_namelen,
7004a26620dSTyler Hicks struct ecryptfs_mount_crypt_stat *mount_crypt_stat);
701a34f60f7SMichael Halcrow int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat,
702a34f60f7SMichael Halcrow loff_t offset);
70388b4a07eSMichael Halcrow
704f354ed98SWedson Almeida Filho extern const struct xattr_handler * const ecryptfs_xattr_handlers[];
7054b899da5SAndreas Gruenbacher
706237fead6SMichael Halcrow #endif /* #ifndef ECRYPTFS_KERNEL_H */
707