ecryptfs_kernel.h 25 KB

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