crypto.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*
  2. * This contains encryption functions for per-file encryption.
  3. *
  4. * Copyright (C) 2015, Google, Inc.
  5. * Copyright (C) 2015, Motorola Mobility
  6. *
  7. * Written by Michael Halcrow, 2014.
  8. *
  9. * Filename encryption additions
  10. * Uday Savagaonkar, 2014
  11. * Encryption policy handling additions
  12. * Ildar Muslukhov, 2014
  13. * Add fscrypt_pullback_bio_page()
  14. * Jaegeuk Kim, 2015.
  15. *
  16. * This has not yet undergone a rigorous security audit.
  17. *
  18. * The usage of AES-XTS should conform to recommendations in NIST
  19. * Special Publication 800-38E and IEEE P1619/D16.
  20. */
  21. #include <linux/pagemap.h>
  22. #include <linux/mempool.h>
  23. #include <linux/module.h>
  24. #include <linux/scatterlist.h>
  25. #include <linux/ratelimit.h>
  26. #include <linux/bio.h>
  27. #include <linux/dcache.h>
  28. #include <linux/namei.h>
  29. #include "fscrypt_private.h"
  30. static unsigned int num_prealloc_crypto_pages = 32;
  31. static unsigned int num_prealloc_crypto_ctxs = 128;
  32. module_param(num_prealloc_crypto_pages, uint, 0444);
  33. MODULE_PARM_DESC(num_prealloc_crypto_pages,
  34. "Number of crypto pages to preallocate");
  35. module_param(num_prealloc_crypto_ctxs, uint, 0444);
  36. MODULE_PARM_DESC(num_prealloc_crypto_ctxs,
  37. "Number of crypto contexts to preallocate");
  38. static mempool_t *fscrypt_bounce_page_pool = NULL;
  39. static LIST_HEAD(fscrypt_free_ctxs);
  40. static DEFINE_SPINLOCK(fscrypt_ctx_lock);
  41. static struct workqueue_struct *fscrypt_read_workqueue;
  42. static DEFINE_MUTEX(fscrypt_init_mutex);
  43. static struct kmem_cache *fscrypt_ctx_cachep;
  44. struct kmem_cache *fscrypt_info_cachep;
  45. /**
  46. * fscrypt_release_ctx() - Releases an encryption context
  47. * @ctx: The encryption context to release.
  48. *
  49. * If the encryption context was allocated from the pre-allocated pool, returns
  50. * it to that pool. Else, frees it.
  51. *
  52. * If there's a bounce page in the context, this frees that.
  53. */
  54. void fscrypt_release_ctx(struct fscrypt_ctx *ctx)
  55. {
  56. unsigned long flags;
  57. if (ctx->flags & FS_CTX_HAS_BOUNCE_BUFFER_FL && ctx->w.bounce_page) {
  58. mempool_free(ctx->w.bounce_page, fscrypt_bounce_page_pool);
  59. ctx->w.bounce_page = NULL;
  60. }
  61. ctx->w.control_page = NULL;
  62. if (ctx->flags & FS_CTX_REQUIRES_FREE_ENCRYPT_FL) {
  63. kmem_cache_free(fscrypt_ctx_cachep, ctx);
  64. } else {
  65. spin_lock_irqsave(&fscrypt_ctx_lock, flags);
  66. list_add(&ctx->free_list, &fscrypt_free_ctxs);
  67. spin_unlock_irqrestore(&fscrypt_ctx_lock, flags);
  68. }
  69. }
  70. EXPORT_SYMBOL(fscrypt_release_ctx);
  71. /**
  72. * fscrypt_get_ctx() - Gets an encryption context
  73. * @inode: The inode for which we are doing the crypto
  74. * @gfp_flags: The gfp flag for memory allocation
  75. *
  76. * Allocates and initializes an encryption context.
  77. *
  78. * Return: An allocated and initialized encryption context on success; error
  79. * value or NULL otherwise.
  80. */
  81. struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode, gfp_t gfp_flags)
  82. {
  83. struct fscrypt_ctx *ctx = NULL;
  84. struct fscrypt_info *ci = inode->i_crypt_info;
  85. unsigned long flags;
  86. if (ci == NULL)
  87. return ERR_PTR(-ENOKEY);
  88. /*
  89. * We first try getting the ctx from a free list because in
  90. * the common case the ctx will have an allocated and
  91. * initialized crypto tfm, so it's probably a worthwhile
  92. * optimization. For the bounce page, we first try getting it
  93. * from the kernel allocator because that's just about as fast
  94. * as getting it from a list and because a cache of free pages
  95. * should generally be a "last resort" option for a filesystem
  96. * to be able to do its job.
  97. */
  98. spin_lock_irqsave(&fscrypt_ctx_lock, flags);
  99. ctx = list_first_entry_or_null(&fscrypt_free_ctxs,
  100. struct fscrypt_ctx, free_list);
  101. if (ctx)
  102. list_del(&ctx->free_list);
  103. spin_unlock_irqrestore(&fscrypt_ctx_lock, flags);
  104. if (!ctx) {
  105. ctx = kmem_cache_zalloc(fscrypt_ctx_cachep, gfp_flags);
  106. if (!ctx)
  107. return ERR_PTR(-ENOMEM);
  108. ctx->flags |= FS_CTX_REQUIRES_FREE_ENCRYPT_FL;
  109. } else {
  110. ctx->flags &= ~FS_CTX_REQUIRES_FREE_ENCRYPT_FL;
  111. }
  112. ctx->flags &= ~FS_CTX_HAS_BOUNCE_BUFFER_FL;
  113. return ctx;
  114. }
  115. EXPORT_SYMBOL(fscrypt_get_ctx);
  116. /**
  117. * page_crypt_complete() - completion callback for page crypto
  118. * @req: The asynchronous cipher request context
  119. * @res: The result of the cipher operation
  120. */
  121. static void page_crypt_complete(struct crypto_async_request *req, int res)
  122. {
  123. struct fscrypt_completion_result *ecr = req->data;
  124. if (res == -EINPROGRESS)
  125. return;
  126. ecr->res = res;
  127. complete(&ecr->completion);
  128. }
  129. typedef enum {
  130. FS_DECRYPT = 0,
  131. FS_ENCRYPT,
  132. } fscrypt_direction_t;
  133. static int do_page_crypto(const struct inode *inode,
  134. fscrypt_direction_t rw, u64 lblk_num,
  135. struct page *src_page, struct page *dest_page,
  136. unsigned int len, unsigned int offs,
  137. gfp_t gfp_flags)
  138. {
  139. struct {
  140. __le64 index;
  141. u8 padding[FS_XTS_TWEAK_SIZE - sizeof(__le64)];
  142. } xts_tweak;
  143. struct skcipher_request *req = NULL;
  144. DECLARE_FS_COMPLETION_RESULT(ecr);
  145. struct scatterlist dst, src;
  146. struct fscrypt_info *ci = inode->i_crypt_info;
  147. struct crypto_skcipher *tfm = ci->ci_ctfm;
  148. int res = 0;
  149. BUG_ON(len == 0);
  150. req = skcipher_request_alloc(tfm, gfp_flags);
  151. if (!req) {
  152. printk_ratelimited(KERN_ERR
  153. "%s: crypto_request_alloc() failed\n",
  154. __func__);
  155. return -ENOMEM;
  156. }
  157. skcipher_request_set_callback(
  158. req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
  159. page_crypt_complete, &ecr);
  160. BUILD_BUG_ON(sizeof(xts_tweak) != FS_XTS_TWEAK_SIZE);
  161. xts_tweak.index = cpu_to_le64(lblk_num);
  162. memset(xts_tweak.padding, 0, sizeof(xts_tweak.padding));
  163. sg_init_table(&dst, 1);
  164. sg_set_page(&dst, dest_page, len, offs);
  165. sg_init_table(&src, 1);
  166. sg_set_page(&src, src_page, len, offs);
  167. skcipher_request_set_crypt(req, &src, &dst, len, &xts_tweak);
  168. if (rw == FS_DECRYPT)
  169. res = crypto_skcipher_decrypt(req);
  170. else
  171. res = crypto_skcipher_encrypt(req);
  172. if (res == -EINPROGRESS || res == -EBUSY) {
  173. BUG_ON(req->base.data != &ecr);
  174. wait_for_completion(&ecr.completion);
  175. res = ecr.res;
  176. }
  177. skcipher_request_free(req);
  178. if (res) {
  179. printk_ratelimited(KERN_ERR
  180. "%s: crypto_skcipher_encrypt() returned %d\n",
  181. __func__, res);
  182. return res;
  183. }
  184. return 0;
  185. }
  186. static struct page *alloc_bounce_page(struct fscrypt_ctx *ctx, gfp_t gfp_flags)
  187. {
  188. ctx->w.bounce_page = mempool_alloc(fscrypt_bounce_page_pool, gfp_flags);
  189. if (ctx->w.bounce_page == NULL)
  190. return ERR_PTR(-ENOMEM);
  191. ctx->flags |= FS_CTX_HAS_BOUNCE_BUFFER_FL;
  192. return ctx->w.bounce_page;
  193. }
  194. /**
  195. * fscypt_encrypt_page() - Encrypts a page
  196. * @inode: The inode for which the encryption should take place
  197. * @page: The page to encrypt. Must be locked for bounce-page
  198. * encryption.
  199. * @len: Length of data to encrypt in @page and encrypted
  200. * data in returned page.
  201. * @offs: Offset of data within @page and returned
  202. * page holding encrypted data.
  203. * @lblk_num: Logical block number. This must be unique for multiple
  204. * calls with same inode, except when overwriting
  205. * previously written data.
  206. * @gfp_flags: The gfp flag for memory allocation
  207. *
  208. * Encrypts @page using the ctx encryption context. Performs encryption
  209. * either in-place or into a newly allocated bounce page.
  210. * Called on the page write path.
  211. *
  212. * Bounce page allocation is the default.
  213. * In this case, the contents of @page are encrypted and stored in an
  214. * allocated bounce page. @page has to be locked and the caller must call
  215. * fscrypt_restore_control_page() on the returned ciphertext page to
  216. * release the bounce buffer and the encryption context.
  217. *
  218. * In-place encryption is used by setting the FS_CFLG_OWN_PAGES flag in
  219. * fscrypt_operations. Here, the input-page is returned with its content
  220. * encrypted.
  221. *
  222. * Return: A page with the encrypted content on success. Else, an
  223. * error value or NULL.
  224. */
  225. struct page *fscrypt_encrypt_page(const struct inode *inode,
  226. struct page *page,
  227. unsigned int len,
  228. unsigned int offs,
  229. u64 lblk_num, gfp_t gfp_flags)
  230. {
  231. struct fscrypt_ctx *ctx;
  232. struct page *ciphertext_page = page;
  233. int err;
  234. BUG_ON(len % FS_CRYPTO_BLOCK_SIZE != 0);
  235. if (inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES) {
  236. /* with inplace-encryption we just encrypt the page */
  237. err = do_page_crypto(inode, FS_ENCRYPT, lblk_num,
  238. page, ciphertext_page,
  239. len, offs, gfp_flags);
  240. if (err)
  241. return ERR_PTR(err);
  242. return ciphertext_page;
  243. }
  244. BUG_ON(!PageLocked(page));
  245. ctx = fscrypt_get_ctx(inode, gfp_flags);
  246. if (IS_ERR(ctx))
  247. return (struct page *)ctx;
  248. /* The encryption operation will require a bounce page. */
  249. ciphertext_page = alloc_bounce_page(ctx, gfp_flags);
  250. if (IS_ERR(ciphertext_page))
  251. goto errout;
  252. ctx->w.control_page = page;
  253. err = do_page_crypto(inode, FS_ENCRYPT, lblk_num,
  254. page, ciphertext_page,
  255. len, offs, gfp_flags);
  256. if (err) {
  257. ciphertext_page = ERR_PTR(err);
  258. goto errout;
  259. }
  260. SetPagePrivate(ciphertext_page);
  261. set_page_private(ciphertext_page, (unsigned long)ctx);
  262. lock_page(ciphertext_page);
  263. return ciphertext_page;
  264. errout:
  265. fscrypt_release_ctx(ctx);
  266. return ciphertext_page;
  267. }
  268. EXPORT_SYMBOL(fscrypt_encrypt_page);
  269. /**
  270. * fscrypt_decrypt_page() - Decrypts a page in-place
  271. * @inode: The corresponding inode for the page to decrypt.
  272. * @page: The page to decrypt. Must be locked in case
  273. * it is a writeback page (FS_CFLG_OWN_PAGES unset).
  274. * @len: Number of bytes in @page to be decrypted.
  275. * @offs: Start of data in @page.
  276. * @lblk_num: Logical block number.
  277. *
  278. * Decrypts page in-place using the ctx encryption context.
  279. *
  280. * Called from the read completion callback.
  281. *
  282. * Return: Zero on success, non-zero otherwise.
  283. */
  284. int fscrypt_decrypt_page(const struct inode *inode, struct page *page,
  285. unsigned int len, unsigned int offs, u64 lblk_num)
  286. {
  287. if (!(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES))
  288. BUG_ON(!PageLocked(page));
  289. return do_page_crypto(inode, FS_DECRYPT, lblk_num, page, page, len,
  290. offs, GFP_NOFS);
  291. }
  292. EXPORT_SYMBOL(fscrypt_decrypt_page);
  293. int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
  294. sector_t pblk, unsigned int len)
  295. {
  296. struct fscrypt_ctx *ctx;
  297. struct page *ciphertext_page = NULL;
  298. struct bio *bio;
  299. int ret, err = 0;
  300. BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE);
  301. ctx = fscrypt_get_ctx(inode, GFP_NOFS);
  302. if (IS_ERR(ctx))
  303. return PTR_ERR(ctx);
  304. ciphertext_page = alloc_bounce_page(ctx, GFP_NOWAIT);
  305. if (IS_ERR(ciphertext_page)) {
  306. err = PTR_ERR(ciphertext_page);
  307. goto errout;
  308. }
  309. while (len--) {
  310. err = do_page_crypto(inode, FS_ENCRYPT, lblk,
  311. ZERO_PAGE(0), ciphertext_page,
  312. PAGE_SIZE, 0, GFP_NOFS);
  313. if (err)
  314. goto errout;
  315. bio = bio_alloc(GFP_NOWAIT, 1);
  316. if (!bio) {
  317. err = -ENOMEM;
  318. goto errout;
  319. }
  320. bio->bi_bdev = inode->i_sb->s_bdev;
  321. bio->bi_iter.bi_sector =
  322. pblk << (inode->i_sb->s_blocksize_bits - 9);
  323. bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
  324. ret = bio_add_page(bio, ciphertext_page,
  325. inode->i_sb->s_blocksize, 0);
  326. if (ret != inode->i_sb->s_blocksize) {
  327. /* should never happen! */
  328. WARN_ON(1);
  329. bio_put(bio);
  330. err = -EIO;
  331. goto errout;
  332. }
  333. err = submit_bio_wait(bio);
  334. if ((err == 0) && bio->bi_error)
  335. err = -EIO;
  336. bio_put(bio);
  337. if (err)
  338. goto errout;
  339. lblk++;
  340. pblk++;
  341. }
  342. err = 0;
  343. errout:
  344. fscrypt_release_ctx(ctx);
  345. return err;
  346. }
  347. EXPORT_SYMBOL(fscrypt_zeroout_range);
  348. /*
  349. * Validate dentries for encrypted directories to make sure we aren't
  350. * potentially caching stale data after a key has been added or
  351. * removed.
  352. */
  353. static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags)
  354. {
  355. struct dentry *dir;
  356. struct fscrypt_info *ci;
  357. int dir_has_key, cached_with_key;
  358. if (flags & LOOKUP_RCU)
  359. return -ECHILD;
  360. dir = dget_parent(dentry);
  361. if (!d_inode(dir)->i_sb->s_cop->is_encrypted(d_inode(dir))) {
  362. dput(dir);
  363. return 0;
  364. }
  365. ci = d_inode(dir)->i_crypt_info;
  366. if (ci && ci->ci_keyring_key &&
  367. (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) |
  368. (1 << KEY_FLAG_REVOKED) |
  369. (1 << KEY_FLAG_DEAD))))
  370. ci = NULL;
  371. /* this should eventually be an flag in d_flags */
  372. spin_lock(&dentry->d_lock);
  373. cached_with_key = dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY;
  374. spin_unlock(&dentry->d_lock);
  375. dir_has_key = (ci != NULL);
  376. dput(dir);
  377. /*
  378. * If the dentry was cached without the key, and it is a
  379. * negative dentry, it might be a valid name. We can't check
  380. * if the key has since been made available due to locking
  381. * reasons, so we fail the validation so ext4_lookup() can do
  382. * this check.
  383. *
  384. * We also fail the validation if the dentry was created with
  385. * the key present, but we no longer have the key, or vice versa.
  386. */
  387. if ((!cached_with_key && d_is_negative(dentry)) ||
  388. (!cached_with_key && dir_has_key) ||
  389. (cached_with_key && !dir_has_key))
  390. return 0;
  391. return 1;
  392. }
  393. const struct dentry_operations fscrypt_d_ops = {
  394. .d_revalidate = fscrypt_d_revalidate,
  395. };
  396. EXPORT_SYMBOL(fscrypt_d_ops);
  397. /*
  398. * Call fscrypt_decrypt_page on every single page, reusing the encryption
  399. * context.
  400. */
  401. static void completion_pages(struct work_struct *work)
  402. {
  403. struct fscrypt_ctx *ctx =
  404. container_of(work, struct fscrypt_ctx, r.work);
  405. struct bio *bio = ctx->r.bio;
  406. struct bio_vec *bv;
  407. int i;
  408. bio_for_each_segment_all(bv, bio, i) {
  409. struct page *page = bv->bv_page;
  410. int ret = fscrypt_decrypt_page(page->mapping->host, page,
  411. PAGE_SIZE, 0, page->index);
  412. if (ret) {
  413. WARN_ON_ONCE(1);
  414. SetPageError(page);
  415. } else {
  416. SetPageUptodate(page);
  417. }
  418. unlock_page(page);
  419. }
  420. fscrypt_release_ctx(ctx);
  421. bio_put(bio);
  422. }
  423. void fscrypt_decrypt_bio_pages(struct fscrypt_ctx *ctx, struct bio *bio)
  424. {
  425. INIT_WORK(&ctx->r.work, completion_pages);
  426. ctx->r.bio = bio;
  427. queue_work(fscrypt_read_workqueue, &ctx->r.work);
  428. }
  429. EXPORT_SYMBOL(fscrypt_decrypt_bio_pages);
  430. void fscrypt_pullback_bio_page(struct page **page, bool restore)
  431. {
  432. struct fscrypt_ctx *ctx;
  433. struct page *bounce_page;
  434. /* The bounce data pages are unmapped. */
  435. if ((*page)->mapping)
  436. return;
  437. /* The bounce data page is unmapped. */
  438. bounce_page = *page;
  439. ctx = (struct fscrypt_ctx *)page_private(bounce_page);
  440. /* restore control page */
  441. *page = ctx->w.control_page;
  442. if (restore)
  443. fscrypt_restore_control_page(bounce_page);
  444. }
  445. EXPORT_SYMBOL(fscrypt_pullback_bio_page);
  446. void fscrypt_restore_control_page(struct page *page)
  447. {
  448. struct fscrypt_ctx *ctx;
  449. ctx = (struct fscrypt_ctx *)page_private(page);
  450. set_page_private(page, (unsigned long)NULL);
  451. ClearPagePrivate(page);
  452. unlock_page(page);
  453. fscrypt_release_ctx(ctx);
  454. }
  455. EXPORT_SYMBOL(fscrypt_restore_control_page);
  456. static void fscrypt_destroy(void)
  457. {
  458. struct fscrypt_ctx *pos, *n;
  459. list_for_each_entry_safe(pos, n, &fscrypt_free_ctxs, free_list)
  460. kmem_cache_free(fscrypt_ctx_cachep, pos);
  461. INIT_LIST_HEAD(&fscrypt_free_ctxs);
  462. mempool_destroy(fscrypt_bounce_page_pool);
  463. fscrypt_bounce_page_pool = NULL;
  464. }
  465. /**
  466. * fscrypt_initialize() - allocate major buffers for fs encryption.
  467. * @cop_flags: fscrypt operations flags
  468. *
  469. * We only call this when we start accessing encrypted files, since it
  470. * results in memory getting allocated that wouldn't otherwise be used.
  471. *
  472. * Return: Zero on success, non-zero otherwise.
  473. */
  474. int fscrypt_initialize(unsigned int cop_flags)
  475. {
  476. int i, res = -ENOMEM;
  477. /*
  478. * No need to allocate a bounce page pool if there already is one or
  479. * this FS won't use it.
  480. */
  481. if (cop_flags & FS_CFLG_OWN_PAGES || fscrypt_bounce_page_pool)
  482. return 0;
  483. mutex_lock(&fscrypt_init_mutex);
  484. if (fscrypt_bounce_page_pool)
  485. goto already_initialized;
  486. for (i = 0; i < num_prealloc_crypto_ctxs; i++) {
  487. struct fscrypt_ctx *ctx;
  488. ctx = kmem_cache_zalloc(fscrypt_ctx_cachep, GFP_NOFS);
  489. if (!ctx)
  490. goto fail;
  491. list_add(&ctx->free_list, &fscrypt_free_ctxs);
  492. }
  493. fscrypt_bounce_page_pool =
  494. mempool_create_page_pool(num_prealloc_crypto_pages, 0);
  495. if (!fscrypt_bounce_page_pool)
  496. goto fail;
  497. already_initialized:
  498. mutex_unlock(&fscrypt_init_mutex);
  499. return 0;
  500. fail:
  501. fscrypt_destroy();
  502. mutex_unlock(&fscrypt_init_mutex);
  503. return res;
  504. }
  505. /**
  506. * fscrypt_init() - Set up for fs encryption.
  507. */
  508. static int __init fscrypt_init(void)
  509. {
  510. fscrypt_read_workqueue = alloc_workqueue("fscrypt_read_queue",
  511. WQ_HIGHPRI, 0);
  512. if (!fscrypt_read_workqueue)
  513. goto fail;
  514. fscrypt_ctx_cachep = KMEM_CACHE(fscrypt_ctx, SLAB_RECLAIM_ACCOUNT);
  515. if (!fscrypt_ctx_cachep)
  516. goto fail_free_queue;
  517. fscrypt_info_cachep = KMEM_CACHE(fscrypt_info, SLAB_RECLAIM_ACCOUNT);
  518. if (!fscrypt_info_cachep)
  519. goto fail_free_ctx;
  520. return 0;
  521. fail_free_ctx:
  522. kmem_cache_destroy(fscrypt_ctx_cachep);
  523. fail_free_queue:
  524. destroy_workqueue(fscrypt_read_workqueue);
  525. fail:
  526. return -ENOMEM;
  527. }
  528. module_init(fscrypt_init)
  529. /**
  530. * fscrypt_exit() - Shutdown the fs encryption system
  531. */
  532. static void __exit fscrypt_exit(void)
  533. {
  534. fscrypt_destroy();
  535. if (fscrypt_read_workqueue)
  536. destroy_workqueue(fscrypt_read_workqueue);
  537. kmem_cache_destroy(fscrypt_ctx_cachep);
  538. kmem_cache_destroy(fscrypt_info_cachep);
  539. }
  540. module_exit(fscrypt_exit);
  541. MODULE_LICENSE("GPL");