VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

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