Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /**
0003  * eCryptfs: Linux filesystem encryption layer
0004  * Kernel declarations.
0005  *
0006  * Copyright (C) 1997-2003 Erez Zadok
0007  * Copyright (C) 2001-2003 Stony Brook University
0008  * Copyright (C) 2004-2008 International Business Machines Corp.
0009  *   Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
0010  *              Trevor S. Highland <trevor.highland@gmail.com>
0011  *              Tyler Hicks <code@tyhicks.com>
0012  */
0013 
0014 #ifndef ECRYPTFS_KERNEL_H
0015 #define ECRYPTFS_KERNEL_H
0016 
0017 #include <crypto/skcipher.h>
0018 #include <keys/user-type.h>
0019 #include <keys/encrypted-type.h>
0020 #include <linux/kernel.h>
0021 #include <linux/fs.h>
0022 #include <linux/fs_stack.h>
0023 #include <linux/namei.h>
0024 #include <linux/scatterlist.h>
0025 #include <linux/hash.h>
0026 #include <linux/nsproxy.h>
0027 #include <linux/backing-dev.h>
0028 #include <linux/ecryptfs.h>
0029 
0030 #define ECRYPTFS_DEFAULT_IV_BYTES 16
0031 #define ECRYPTFS_DEFAULT_EXTENT_SIZE 4096
0032 #define ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE 8192
0033 #define ECRYPTFS_DEFAULT_MSG_CTX_ELEMS 32
0034 #define ECRYPTFS_DEFAULT_SEND_TIMEOUT HZ
0035 #define ECRYPTFS_MAX_MSG_CTX_TTL (HZ*3)
0036 #define ECRYPTFS_DEFAULT_NUM_USERS 4
0037 #define ECRYPTFS_MAX_NUM_USERS 32768
0038 #define ECRYPTFS_XATTR_NAME "user.ecryptfs"
0039 
0040 void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok);
0041 static inline void
0042 ecryptfs_to_hex(char *dst, char *src, size_t src_size)
0043 {
0044     char *end = bin2hex(dst, src, src_size);
0045     *end = '\0';
0046 }
0047 
0048 extern void ecryptfs_from_hex(char *dst, char *src, int dst_size);
0049 
0050 struct ecryptfs_key_record {
0051     unsigned char type;
0052     size_t enc_key_size;
0053     unsigned char sig[ECRYPTFS_SIG_SIZE];
0054     unsigned char enc_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES];
0055 };
0056 
0057 struct ecryptfs_auth_tok_list {
0058     struct ecryptfs_auth_tok *auth_tok;
0059     struct list_head list;
0060 };
0061 
0062 struct ecryptfs_crypt_stat;
0063 struct ecryptfs_mount_crypt_stat;
0064 
0065 struct ecryptfs_page_crypt_context {
0066     struct page *page;
0067 #define ECRYPTFS_PREPARE_COMMIT_MODE 0
0068 #define ECRYPTFS_WRITEPAGE_MODE      1
0069     unsigned int mode;
0070     union {
0071         struct file *lower_file;
0072         struct writeback_control *wbc;
0073     } param;
0074 };
0075 
0076 #if defined(CONFIG_ENCRYPTED_KEYS) || defined(CONFIG_ENCRYPTED_KEYS_MODULE)
0077 static inline struct ecryptfs_auth_tok *
0078 ecryptfs_get_encrypted_key_payload_data(struct key *key)
0079 {
0080     struct encrypted_key_payload *payload;
0081 
0082     if (key->type != &key_type_encrypted)
0083         return NULL;
0084 
0085     payload = key->payload.data[0];
0086     if (!payload)
0087         return ERR_PTR(-EKEYREVOKED);
0088 
0089     return (struct ecryptfs_auth_tok *)payload->payload_data;
0090 }
0091 
0092 static inline struct key *ecryptfs_get_encrypted_key(char *sig)
0093 {
0094     return request_key(&key_type_encrypted, sig, NULL);
0095 }
0096 
0097 #else
0098 static inline struct ecryptfs_auth_tok *
0099 ecryptfs_get_encrypted_key_payload_data(struct key *key)
0100 {
0101     return NULL;
0102 }
0103 
0104 static inline struct key *ecryptfs_get_encrypted_key(char *sig)
0105 {
0106     return ERR_PTR(-ENOKEY);
0107 }
0108 
0109 #endif /* CONFIG_ENCRYPTED_KEYS */
0110 
0111 static inline struct ecryptfs_auth_tok *
0112 ecryptfs_get_key_payload_data(struct key *key)
0113 {
0114     struct ecryptfs_auth_tok *auth_tok;
0115     struct user_key_payload *ukp;
0116 
0117     auth_tok = ecryptfs_get_encrypted_key_payload_data(key);
0118     if (auth_tok)
0119         return auth_tok;
0120 
0121     ukp = user_key_payload_locked(key);
0122     if (!ukp)
0123         return ERR_PTR(-EKEYREVOKED);
0124 
0125     return (struct ecryptfs_auth_tok *)ukp->data;
0126 }
0127 
0128 #define ECRYPTFS_MAX_KEYSET_SIZE 1024
0129 #define ECRYPTFS_MAX_CIPHER_NAME_SIZE 31
0130 #define ECRYPTFS_MAX_NUM_ENC_KEYS 64
0131 #define ECRYPTFS_MAX_IV_BYTES 16    /* 128 bits */
0132 #define ECRYPTFS_SALT_BYTES 2
0133 #define MAGIC_ECRYPTFS_MARKER 0x3c81b7f5
0134 #define MAGIC_ECRYPTFS_MARKER_SIZE_BYTES 8  /* 4*2 */
0135 #define ECRYPTFS_FILE_SIZE_BYTES (sizeof(u64))
0136 #define ECRYPTFS_SIZE_AND_MARKER_BYTES (ECRYPTFS_FILE_SIZE_BYTES \
0137                     + MAGIC_ECRYPTFS_MARKER_SIZE_BYTES)
0138 #define ECRYPTFS_DEFAULT_CIPHER "aes"
0139 #define ECRYPTFS_DEFAULT_KEY_BYTES 16
0140 #define ECRYPTFS_DEFAULT_HASH "md5"
0141 #define ECRYPTFS_TAG_70_DIGEST ECRYPTFS_DEFAULT_HASH
0142 #define ECRYPTFS_TAG_1_PACKET_TYPE 0x01
0143 #define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C
0144 #define ECRYPTFS_TAG_11_PACKET_TYPE 0xED
0145 #define ECRYPTFS_TAG_64_PACKET_TYPE 0x40
0146 #define ECRYPTFS_TAG_65_PACKET_TYPE 0x41
0147 #define ECRYPTFS_TAG_66_PACKET_TYPE 0x42
0148 #define ECRYPTFS_TAG_67_PACKET_TYPE 0x43
0149 #define ECRYPTFS_TAG_70_PACKET_TYPE 0x46 /* FNEK-encrypted filename
0150                       * as dentry name */
0151 #define ECRYPTFS_TAG_71_PACKET_TYPE 0x47 /* FNEK-encrypted filename in
0152                       * metadata */
0153 #define ECRYPTFS_TAG_72_PACKET_TYPE 0x48 /* FEK-encrypted filename as
0154                       * dentry name */
0155 #define ECRYPTFS_TAG_73_PACKET_TYPE 0x49 /* FEK-encrypted filename as
0156                       * metadata */
0157 #define ECRYPTFS_MIN_PKT_LEN_SIZE 1 /* Min size to specify packet length */
0158 #define ECRYPTFS_MAX_PKT_LEN_SIZE 2 /* Pass at least this many bytes to
0159                      * ecryptfs_parse_packet_length() and
0160                      * ecryptfs_write_packet_length()
0161                      */
0162 /* Constraint: ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES >=
0163  * ECRYPTFS_MAX_IV_BYTES */
0164 #define ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES 16
0165 #define ECRYPTFS_NON_NULL 0x42 /* A reasonable substitute for NULL */
0166 #define MD5_DIGEST_SIZE 16
0167 #define ECRYPTFS_TAG_70_DIGEST_SIZE MD5_DIGEST_SIZE
0168 #define ECRYPTFS_TAG_70_MIN_METADATA_SIZE (1 + ECRYPTFS_MIN_PKT_LEN_SIZE \
0169                        + ECRYPTFS_SIG_SIZE + 1 + 1)
0170 #define ECRYPTFS_TAG_70_MAX_METADATA_SIZE (1 + ECRYPTFS_MAX_PKT_LEN_SIZE \
0171                        + ECRYPTFS_SIG_SIZE + 1 + 1)
0172 #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FEK_ENCRYPTED."
0173 #define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX_SIZE 23
0174 #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FNEK_ENCRYPTED."
0175 #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE 24
0176 #define ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN (18 + 1 + 4 + 1 + 32)
0177 
0178 #ifdef CONFIG_ECRYPT_FS_MESSAGING
0179 # define ECRYPTFS_VERSIONING_MASK_MESSAGING (ECRYPTFS_VERSIONING_DEVMISC \
0180                          | ECRYPTFS_VERSIONING_PUBKEY)
0181 #else
0182 # define ECRYPTFS_VERSIONING_MASK_MESSAGING 0
0183 #endif
0184 
0185 #define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \
0186                   | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \
0187                   | ECRYPTFS_VERSIONING_XATTR \
0188                   | ECRYPTFS_VERSIONING_MULTKEY \
0189                   | ECRYPTFS_VERSIONING_MASK_MESSAGING \
0190                   | ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION)
0191 struct ecryptfs_key_sig {
0192     struct list_head crypt_stat_list;
0193     char keysig[ECRYPTFS_SIG_SIZE_HEX + 1];
0194 };
0195 
0196 struct ecryptfs_filename {
0197     struct list_head crypt_stat_list;
0198 #define ECRYPTFS_FILENAME_CONTAINS_DECRYPTED 0x00000001
0199     u32 flags;
0200     u32 seq_no;
0201     char *filename;
0202     char *encrypted_filename;
0203     size_t filename_size;
0204     size_t encrypted_filename_size;
0205     char fnek_sig[ECRYPTFS_SIG_SIZE_HEX];
0206     char dentry_name[ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN + 1];
0207 };
0208 
0209 /**
0210  * This is the primary struct associated with each encrypted file.
0211  *
0212  * TODO: cache align/pack?
0213  */
0214 struct ecryptfs_crypt_stat {
0215 #define ECRYPTFS_STRUCT_INITIALIZED   0x00000001
0216 #define ECRYPTFS_POLICY_APPLIED       0x00000002
0217 #define ECRYPTFS_ENCRYPTED            0x00000004
0218 #define ECRYPTFS_SECURITY_WARNING     0x00000008
0219 #define ECRYPTFS_ENABLE_HMAC          0x00000010
0220 #define ECRYPTFS_ENCRYPT_IV_PAGES     0x00000020
0221 #define ECRYPTFS_KEY_VALID            0x00000040
0222 #define ECRYPTFS_METADATA_IN_XATTR    0x00000080
0223 #define ECRYPTFS_VIEW_AS_ENCRYPTED    0x00000100
0224 #define ECRYPTFS_KEY_SET              0x00000200
0225 #define ECRYPTFS_ENCRYPT_FILENAMES    0x00000400
0226 #define ECRYPTFS_ENCFN_USE_MOUNT_FNEK 0x00000800
0227 #define ECRYPTFS_ENCFN_USE_FEK        0x00001000
0228 #define ECRYPTFS_UNLINK_SIGS          0x00002000
0229 #define ECRYPTFS_I_SIZE_INITIALIZED   0x00004000
0230     u32 flags;
0231     unsigned int file_version;
0232     size_t iv_bytes;
0233     size_t metadata_size;
0234     size_t extent_size; /* Data extent size; default is 4096 */
0235     size_t key_size;
0236     size_t extent_shift;
0237     unsigned int extent_mask;
0238     struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
0239     struct crypto_skcipher *tfm;
0240     struct crypto_shash *hash_tfm; /* Crypto context for generating
0241                     * the initialization vectors */
0242     unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
0243     unsigned char key[ECRYPTFS_MAX_KEY_BYTES];
0244     unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES];
0245     struct list_head keysig_list;
0246     struct mutex keysig_list_mutex;
0247     struct mutex cs_tfm_mutex;
0248     struct mutex cs_mutex;
0249 };
0250 
0251 /* inode private data. */
0252 struct ecryptfs_inode_info {
0253     struct inode vfs_inode;
0254     struct inode *wii_inode;
0255     struct mutex lower_file_mutex;
0256     atomic_t lower_file_count;
0257     struct file *lower_file;
0258     struct ecryptfs_crypt_stat crypt_stat;
0259 };
0260 
0261 /* dentry private data. Each dentry must keep track of a lower
0262  * vfsmount too. */
0263 struct ecryptfs_dentry_info {
0264     struct path lower_path;
0265     struct rcu_head rcu;
0266 };
0267 
0268 /**
0269  * ecryptfs_global_auth_tok - A key used to encrypt all new files under the mountpoint
0270  * @flags: Status flags
0271  * @mount_crypt_stat_list: These auth_toks hang off the mount-wide
0272  *                         cryptographic context. Every time a new
0273  *                         inode comes into existence, eCryptfs copies
0274  *                         the auth_toks on that list to the set of
0275  *                         auth_toks on the inode's crypt_stat
0276  * @global_auth_tok_key: The key from the user's keyring for the sig
0277  * @global_auth_tok: The key contents
0278  * @sig: The key identifier
0279  *
0280  * ecryptfs_global_auth_tok structs refer to authentication token keys
0281  * in the user keyring that apply to newly created files. A list of
0282  * these objects hangs off of the mount_crypt_stat struct for any
0283  * given eCryptfs mount. This struct maintains a reference to both the
0284  * key contents and the key itself so that the key can be put on
0285  * unmount.
0286  */
0287 struct ecryptfs_global_auth_tok {
0288 #define ECRYPTFS_AUTH_TOK_INVALID 0x00000001
0289 #define ECRYPTFS_AUTH_TOK_FNEK    0x00000002
0290     u32 flags;
0291     struct list_head mount_crypt_stat_list;
0292     struct key *global_auth_tok_key;
0293     unsigned char sig[ECRYPTFS_SIG_SIZE_HEX + 1];
0294 };
0295 
0296 /**
0297  * ecryptfs_key_tfm - Persistent key tfm
0298  * @key_tfm: crypto API handle to the key
0299  * @key_size: Key size in bytes
0300  * @key_tfm_mutex: Mutex to ensure only one operation in eCryptfs is
0301  *                 using the persistent TFM at any point in time
0302  * @key_tfm_list: Handle to hang this off the module-wide TFM list
0303  * @cipher_name: String name for the cipher for this TFM
0304  *
0305  * Typically, eCryptfs will use the same ciphers repeatedly throughout
0306  * the course of its operations. In order to avoid unnecessarily
0307  * destroying and initializing the same cipher repeatedly, eCryptfs
0308  * keeps a list of crypto API contexts around to use when needed.
0309  */
0310 struct ecryptfs_key_tfm {
0311     struct crypto_skcipher *key_tfm;
0312     size_t key_size;
0313     struct mutex key_tfm_mutex;
0314     struct list_head key_tfm_list;
0315     unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
0316 };
0317 
0318 extern struct mutex key_tfm_list_mutex;
0319 
0320 /**
0321  * This struct is to enable a mount-wide passphrase/salt combo. This
0322  * is more or less a stopgap to provide similar functionality to other
0323  * crypto filesystems like EncFS or CFS until full policy support is
0324  * implemented in eCryptfs.
0325  */
0326 struct ecryptfs_mount_crypt_stat {
0327     /* Pointers to memory we do not own, do not free these */
0328 #define ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED 0x00000001
0329 #define ECRYPTFS_XATTR_METADATA_ENABLED        0x00000002
0330 #define ECRYPTFS_ENCRYPTED_VIEW_ENABLED        0x00000004
0331 #define ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED  0x00000008
0332 #define ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES      0x00000010
0333 #define ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK   0x00000020
0334 #define ECRYPTFS_GLOBAL_ENCFN_USE_FEK          0x00000040
0335 #define ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY    0x00000080
0336     u32 flags;
0337     struct list_head global_auth_tok_list;
0338     struct mutex global_auth_tok_list_mutex;
0339     size_t global_default_cipher_key_size;
0340     size_t global_default_fn_cipher_key_bytes;
0341     unsigned char global_default_cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE
0342                          + 1];
0343     unsigned char global_default_fn_cipher_name[
0344         ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
0345     char global_default_fnek_sig[ECRYPTFS_SIG_SIZE_HEX + 1];
0346 };
0347 
0348 /* superblock private data. */
0349 struct ecryptfs_sb_info {
0350     struct super_block *wsi_sb;
0351     struct ecryptfs_mount_crypt_stat mount_crypt_stat;
0352 };
0353 
0354 /* file private data. */
0355 struct ecryptfs_file_info {
0356     struct file *wfi_file;
0357     struct ecryptfs_crypt_stat *crypt_stat;
0358 };
0359 
0360 /* auth_tok <=> encrypted_session_key mappings */
0361 struct ecryptfs_auth_tok_list_item {
0362     unsigned char encrypted_session_key[ECRYPTFS_MAX_KEY_BYTES];
0363     struct list_head list;
0364     struct ecryptfs_auth_tok auth_tok;
0365 };
0366 
0367 struct ecryptfs_message {
0368     /* Can never be greater than ecryptfs_message_buf_len */
0369     /* Used to find the parent msg_ctx */
0370     /* Inherits from msg_ctx->index */
0371     u32 index;
0372     u32 data_len;
0373     u8 data[];
0374 };
0375 
0376 struct ecryptfs_msg_ctx {
0377 #define ECRYPTFS_MSG_CTX_STATE_FREE     0x01
0378 #define ECRYPTFS_MSG_CTX_STATE_PENDING  0x02
0379 #define ECRYPTFS_MSG_CTX_STATE_DONE     0x03
0380 #define ECRYPTFS_MSG_CTX_STATE_NO_REPLY 0x04
0381     u8 state;
0382 #define ECRYPTFS_MSG_HELO 100
0383 #define ECRYPTFS_MSG_QUIT 101
0384 #define ECRYPTFS_MSG_REQUEST 102
0385 #define ECRYPTFS_MSG_RESPONSE 103
0386     u8 type;
0387     u32 index;
0388     /* Counter converts to a sequence number. Each message sent
0389      * out for which we expect a response has an associated
0390      * sequence number. The response must have the same sequence
0391      * number as the counter for the msg_stc for the message to be
0392      * valid. */
0393     u32 counter;
0394     size_t msg_size;
0395     struct ecryptfs_message *msg;
0396     struct task_struct *task;
0397     struct list_head node;
0398     struct list_head daemon_out_list;
0399     struct mutex mux;
0400 };
0401 
0402 struct ecryptfs_daemon {
0403 #define ECRYPTFS_DAEMON_IN_READ      0x00000001
0404 #define ECRYPTFS_DAEMON_IN_POLL      0x00000002
0405 #define ECRYPTFS_DAEMON_ZOMBIE       0x00000004
0406 #define ECRYPTFS_DAEMON_MISCDEV_OPEN 0x00000008
0407     u32 flags;
0408     u32 num_queued_msg_ctx;
0409     struct file *file;
0410     struct mutex mux;
0411     struct list_head msg_ctx_out_queue;
0412     wait_queue_head_t wait;
0413     struct hlist_node euid_chain;
0414 };
0415 
0416 #ifdef CONFIG_ECRYPT_FS_MESSAGING
0417 extern struct mutex ecryptfs_daemon_hash_mux;
0418 #endif
0419 
0420 static inline size_t
0421 ecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat)
0422 {
0423     if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
0424         return 0;
0425     return crypt_stat->metadata_size;
0426 }
0427 
0428 static inline struct ecryptfs_file_info *
0429 ecryptfs_file_to_private(struct file *file)
0430 {
0431     return file->private_data;
0432 }
0433 
0434 static inline void
0435 ecryptfs_set_file_private(struct file *file,
0436               struct ecryptfs_file_info *file_info)
0437 {
0438     file->private_data = file_info;
0439 }
0440 
0441 static inline struct file *ecryptfs_file_to_lower(struct file *file)
0442 {
0443     return ((struct ecryptfs_file_info *)file->private_data)->wfi_file;
0444 }
0445 
0446 static inline void
0447 ecryptfs_set_file_lower(struct file *file, struct file *lower_file)
0448 {
0449     ((struct ecryptfs_file_info *)file->private_data)->wfi_file =
0450         lower_file;
0451 }
0452 
0453 static inline struct ecryptfs_inode_info *
0454 ecryptfs_inode_to_private(struct inode *inode)
0455 {
0456     return container_of(inode, struct ecryptfs_inode_info, vfs_inode);
0457 }
0458 
0459 static inline struct inode *ecryptfs_inode_to_lower(struct inode *inode)
0460 {
0461     return ecryptfs_inode_to_private(inode)->wii_inode;
0462 }
0463 
0464 static inline void
0465 ecryptfs_set_inode_lower(struct inode *inode, struct inode *lower_inode)
0466 {
0467     ecryptfs_inode_to_private(inode)->wii_inode = lower_inode;
0468 }
0469 
0470 static inline struct ecryptfs_sb_info *
0471 ecryptfs_superblock_to_private(struct super_block *sb)
0472 {
0473     return (struct ecryptfs_sb_info *)sb->s_fs_info;
0474 }
0475 
0476 static inline void
0477 ecryptfs_set_superblock_private(struct super_block *sb,
0478                 struct ecryptfs_sb_info *sb_info)
0479 {
0480     sb->s_fs_info = sb_info;
0481 }
0482 
0483 static inline struct super_block *
0484 ecryptfs_superblock_to_lower(struct super_block *sb)
0485 {
0486     return ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb;
0487 }
0488 
0489 static inline void
0490 ecryptfs_set_superblock_lower(struct super_block *sb,
0491                   struct super_block *lower_sb)
0492 {
0493     ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb = lower_sb;
0494 }
0495 
0496 static inline void
0497 ecryptfs_set_dentry_private(struct dentry *dentry,
0498                 struct ecryptfs_dentry_info *dentry_info)
0499 {
0500     dentry->d_fsdata = dentry_info;
0501 }
0502 
0503 static inline struct dentry *
0504 ecryptfs_dentry_to_lower(struct dentry *dentry)
0505 {
0506     return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry;
0507 }
0508 
0509 static inline struct path *
0510 ecryptfs_dentry_to_lower_path(struct dentry *dentry)
0511 {
0512     return &((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path;
0513 }
0514 
0515 #define ecryptfs_printk(type, fmt, arg...) \
0516         __ecryptfs_printk(type "%s: " fmt, __func__, ## arg)
0517 __printf(1, 2)
0518 void __ecryptfs_printk(const char *fmt, ...);
0519 
0520 extern const struct file_operations ecryptfs_main_fops;
0521 extern const struct file_operations ecryptfs_dir_fops;
0522 extern const struct inode_operations ecryptfs_main_iops;
0523 extern const struct inode_operations ecryptfs_dir_iops;
0524 extern const struct inode_operations ecryptfs_symlink_iops;
0525 extern const struct super_operations ecryptfs_sops;
0526 extern const struct dentry_operations ecryptfs_dops;
0527 extern const struct address_space_operations ecryptfs_aops;
0528 extern int ecryptfs_verbosity;
0529 extern unsigned int ecryptfs_message_buf_len;
0530 extern signed long ecryptfs_message_wait_timeout;
0531 extern unsigned int ecryptfs_number_of_users;
0532 
0533 extern struct kmem_cache *ecryptfs_auth_tok_list_item_cache;
0534 extern struct kmem_cache *ecryptfs_file_info_cache;
0535 extern struct kmem_cache *ecryptfs_dentry_info_cache;
0536 extern struct kmem_cache *ecryptfs_inode_info_cache;
0537 extern struct kmem_cache *ecryptfs_sb_info_cache;
0538 extern struct kmem_cache *ecryptfs_header_cache;
0539 extern struct kmem_cache *ecryptfs_xattr_cache;
0540 extern struct kmem_cache *ecryptfs_key_record_cache;
0541 extern struct kmem_cache *ecryptfs_key_sig_cache;
0542 extern struct kmem_cache *ecryptfs_global_auth_tok_cache;
0543 extern struct kmem_cache *ecryptfs_key_tfm_cache;
0544 
0545 struct inode *ecryptfs_get_inode(struct inode *lower_inode,
0546                  struct super_block *sb);
0547 void ecryptfs_i_size_init(const char *page_virt, struct inode *inode);
0548 int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
0549                  struct inode *ecryptfs_inode);
0550 int ecryptfs_decode_and_decrypt_filename(char **decrypted_name,
0551                      size_t *decrypted_name_size,
0552                      struct super_block *sb,
0553                      const char *name, size_t name_size);
0554 int ecryptfs_fill_zeros(struct file *file, loff_t new_length);
0555 int ecryptfs_encrypt_and_encode_filename(
0556     char **encoded_name,
0557     size_t *encoded_name_size,
0558     struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
0559     const char *name, size_t name_size);
0560 struct dentry *ecryptfs_lower_dentry(struct dentry *this_dentry);
0561 void ecryptfs_dump_hex(char *data, int bytes);
0562 int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg,
0563             int sg_size);
0564 int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat);
0565 void ecryptfs_rotate_iv(unsigned char *iv);
0566 int ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat);
0567 void ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat);
0568 void ecryptfs_destroy_mount_crypt_stat(
0569     struct ecryptfs_mount_crypt_stat *mount_crypt_stat);
0570 int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat);
0571 int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode);
0572 int ecryptfs_encrypt_page(struct page *page);
0573 int ecryptfs_decrypt_page(struct page *page);
0574 int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry,
0575                 struct inode *ecryptfs_inode);
0576 int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry);
0577 int ecryptfs_new_file_context(struct inode *ecryptfs_inode);
0578 void ecryptfs_write_crypt_stat_flags(char *page_virt,
0579                      struct ecryptfs_crypt_stat *crypt_stat,
0580                      size_t *written);
0581 int ecryptfs_read_and_validate_header_region(struct inode *inode);
0582 int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry,
0583                         struct inode *inode);
0584 u8 ecryptfs_code_for_cipher_string(char *cipher_name, size_t key_bytes);
0585 int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code);
0586 void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat);
0587 int ecryptfs_generate_key_packet_set(char *dest_base,
0588                      struct ecryptfs_crypt_stat *crypt_stat,
0589                      struct dentry *ecryptfs_dentry,
0590                      size_t *len, size_t max);
0591 int
0592 ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
0593               unsigned char *src, struct dentry *ecryptfs_dentry);
0594 int ecryptfs_truncate(struct dentry *dentry, loff_t new_length);
0595 ssize_t
0596 ecryptfs_getxattr_lower(struct dentry *lower_dentry, struct inode *lower_inode,
0597             const char *name, void *value, size_t size);
0598 int
0599 ecryptfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
0600           const void *value, size_t size, int flags);
0601 int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode);
0602 #ifdef CONFIG_ECRYPT_FS_MESSAGING
0603 int ecryptfs_process_response(struct ecryptfs_daemon *daemon,
0604                   struct ecryptfs_message *msg, u32 seq);
0605 int ecryptfs_send_message(char *data, int data_len,
0606               struct ecryptfs_msg_ctx **msg_ctx);
0607 int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
0608                    struct ecryptfs_message **emsg);
0609 int ecryptfs_init_messaging(void);
0610 void ecryptfs_release_messaging(void);
0611 #else
0612 static inline int ecryptfs_init_messaging(void)
0613 {
0614     return 0;
0615 }
0616 static inline void ecryptfs_release_messaging(void)
0617 { }
0618 static inline int ecryptfs_send_message(char *data, int data_len,
0619                     struct ecryptfs_msg_ctx **msg_ctx)
0620 {
0621     return -ENOTCONN;
0622 }
0623 static inline int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
0624                          struct ecryptfs_message **emsg)
0625 {
0626     return -ENOMSG;
0627 }
0628 #endif
0629 
0630 void
0631 ecryptfs_write_header_metadata(char *virt,
0632                    struct ecryptfs_crypt_stat *crypt_stat,
0633                    size_t *written);
0634 int ecryptfs_add_keysig(struct ecryptfs_crypt_stat *crypt_stat, char *sig);
0635 int
0636 ecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
0637                char *sig, u32 global_auth_tok_flags);
0638 int ecryptfs_get_global_auth_tok_for_sig(
0639     struct ecryptfs_global_auth_tok **global_auth_tok,
0640     struct ecryptfs_mount_crypt_stat *mount_crypt_stat, char *sig);
0641 int
0642 ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
0643              size_t key_size);
0644 int ecryptfs_init_crypto(void);
0645 int ecryptfs_destroy_crypto(void);
0646 int ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm);
0647 int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_skcipher **tfm,
0648                            struct mutex **tfm_mutex,
0649                            char *cipher_name);
0650 int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key,
0651                       struct ecryptfs_auth_tok **auth_tok,
0652                       char *sig);
0653 int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
0654              loff_t offset, size_t size);
0655 int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
0656                       struct page *page_for_lower,
0657                       size_t offset_in_page, size_t size);
0658 int ecryptfs_write(struct inode *inode, char *data, loff_t offset, size_t size);
0659 int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
0660             struct inode *ecryptfs_inode);
0661 int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
0662                      pgoff_t page_index,
0663                      size_t offset_in_page, size_t size,
0664                      struct inode *ecryptfs_inode);
0665 struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index);
0666 int ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
0667                  size_t *length_size);
0668 int ecryptfs_write_packet_length(char *dest, size_t size,
0669                  size_t *packet_size_length);
0670 #ifdef CONFIG_ECRYPT_FS_MESSAGING
0671 int ecryptfs_init_ecryptfs_miscdev(void);
0672 void ecryptfs_destroy_ecryptfs_miscdev(void);
0673 int ecryptfs_send_miscdev(char *data, size_t data_size,
0674               struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
0675               u16 msg_flags, struct ecryptfs_daemon *daemon);
0676 void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx);
0677 int
0678 ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file);
0679 int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
0680 int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
0681 #endif
0682 int ecryptfs_init_kthread(void);
0683 void ecryptfs_destroy_kthread(void);
0684 int ecryptfs_privileged_open(struct file **lower_file,
0685                  struct dentry *lower_dentry,
0686                  struct vfsmount *lower_mnt,
0687                  const struct cred *cred);
0688 int ecryptfs_get_lower_file(struct dentry *dentry, struct inode *inode);
0689 void ecryptfs_put_lower_file(struct inode *inode);
0690 int
0691 ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
0692                  size_t *packet_size,
0693                  struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
0694                  char *filename, size_t filename_size);
0695 int
0696 ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
0697                  size_t *packet_size,
0698                  struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
0699                  char *data, size_t max_packet_size);
0700 int ecryptfs_set_f_namelen(long *namelen, long lower_namelen,
0701                struct ecryptfs_mount_crypt_stat *mount_crypt_stat);
0702 int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat,
0703                loff_t offset);
0704 
0705 extern const struct xattr_handler *ecryptfs_xattr_handlers[];
0706 
0707 #endif /* #ifndef ECRYPTFS_KERNEL_H */