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