ima_crypto.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * Copyright (C) 2005,2006,2007,2008 IBM Corporation
  3. *
  4. * Authors:
  5. * Mimi Zohar <zohar@us.ibm.com>
  6. * Kylene Hall <kjhall@us.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, version 2 of the License.
  11. *
  12. * File: ima_crypto.c
  13. * Calculates md5/sha1 file hash, template hash, boot-aggreate hash
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16. #include <linux/kernel.h>
  17. #include <linux/moduleparam.h>
  18. #include <linux/ratelimit.h>
  19. #include <linux/file.h>
  20. #include <linux/crypto.h>
  21. #include <linux/scatterlist.h>
  22. #include <linux/err.h>
  23. #include <linux/slab.h>
  24. #include <crypto/hash.h>
  25. #include "ima.h"
  26. /* minimum file size for ahash use */
  27. static unsigned long ima_ahash_minsize;
  28. module_param_named(ahash_minsize, ima_ahash_minsize, ulong, 0644);
  29. MODULE_PARM_DESC(ahash_minsize, "Minimum file size for ahash use");
  30. /* default is 0 - 1 page. */
  31. static int ima_maxorder;
  32. static unsigned int ima_bufsize = PAGE_SIZE;
  33. static int param_set_bufsize(const char *val, const struct kernel_param *kp)
  34. {
  35. unsigned long long size;
  36. int order;
  37. size = memparse(val, NULL);
  38. order = get_order(size);
  39. if (order >= MAX_ORDER)
  40. return -EINVAL;
  41. ima_maxorder = order;
  42. ima_bufsize = PAGE_SIZE << order;
  43. return 0;
  44. }
  45. static const struct kernel_param_ops param_ops_bufsize = {
  46. .set = param_set_bufsize,
  47. .get = param_get_uint,
  48. };
  49. #define param_check_bufsize(name, p) __param_check(name, p, unsigned int)
  50. module_param_named(ahash_bufsize, ima_bufsize, bufsize, 0644);
  51. MODULE_PARM_DESC(ahash_bufsize, "Maximum ahash buffer size");
  52. static struct crypto_shash *ima_shash_tfm;
  53. static struct crypto_ahash *ima_ahash_tfm;
  54. int __init ima_init_crypto(void)
  55. {
  56. long rc;
  57. ima_shash_tfm = crypto_alloc_shash(hash_algo_name[ima_hash_algo], 0, 0);
  58. if (IS_ERR(ima_shash_tfm)) {
  59. rc = PTR_ERR(ima_shash_tfm);
  60. pr_err("Can not allocate %s (reason: %ld)\n",
  61. hash_algo_name[ima_hash_algo], rc);
  62. return rc;
  63. }
  64. pr_info("Allocated hash algorithm: %s\n",
  65. hash_algo_name[ima_hash_algo]);
  66. return 0;
  67. }
  68. static struct crypto_shash *ima_alloc_tfm(enum hash_algo algo)
  69. {
  70. struct crypto_shash *tfm = ima_shash_tfm;
  71. int rc;
  72. if (algo < 0 || algo >= HASH_ALGO__LAST)
  73. algo = ima_hash_algo;
  74. if (algo != ima_hash_algo) {
  75. tfm = crypto_alloc_shash(hash_algo_name[algo], 0, 0);
  76. if (IS_ERR(tfm)) {
  77. rc = PTR_ERR(tfm);
  78. pr_err("Can not allocate %s (reason: %d)\n",
  79. hash_algo_name[algo], rc);
  80. }
  81. }
  82. return tfm;
  83. }
  84. static void ima_free_tfm(struct crypto_shash *tfm)
  85. {
  86. if (tfm != ima_shash_tfm)
  87. crypto_free_shash(tfm);
  88. }
  89. /**
  90. * ima_alloc_pages() - Allocate contiguous pages.
  91. * @max_size: Maximum amount of memory to allocate.
  92. * @allocated_size: Returned size of actual allocation.
  93. * @last_warn: Should the min_size allocation warn or not.
  94. *
  95. * Tries to do opportunistic allocation for memory first trying to allocate
  96. * max_size amount of memory and then splitting that until zero order is
  97. * reached. Allocation is tried without generating allocation warnings unless
  98. * last_warn is set. Last_warn set affects only last allocation of zero order.
  99. *
  100. * By default, ima_maxorder is 0 and it is equivalent to kmalloc(GFP_KERNEL)
  101. *
  102. * Return pointer to allocated memory, or NULL on failure.
  103. */
  104. static void *ima_alloc_pages(loff_t max_size, size_t *allocated_size,
  105. int last_warn)
  106. {
  107. void *ptr;
  108. int order = ima_maxorder;
  109. gfp_t gfp_mask = __GFP_RECLAIM | __GFP_NOWARN | __GFP_NORETRY;
  110. if (order)
  111. order = min(get_order(max_size), order);
  112. for (; order; order--) {
  113. ptr = (void *)__get_free_pages(gfp_mask, order);
  114. if (ptr) {
  115. *allocated_size = PAGE_SIZE << order;
  116. return ptr;
  117. }
  118. }
  119. /* order is zero - one page */
  120. gfp_mask = GFP_KERNEL;
  121. if (!last_warn)
  122. gfp_mask |= __GFP_NOWARN;
  123. ptr = (void *)__get_free_pages(gfp_mask, 0);
  124. if (ptr) {
  125. *allocated_size = PAGE_SIZE;
  126. return ptr;
  127. }
  128. *allocated_size = 0;
  129. return NULL;
  130. }
  131. /**
  132. * ima_free_pages() - Free pages allocated by ima_alloc_pages().
  133. * @ptr: Pointer to allocated pages.
  134. * @size: Size of allocated buffer.
  135. */
  136. static void ima_free_pages(void *ptr, size_t size)
  137. {
  138. if (!ptr)
  139. return;
  140. free_pages((unsigned long)ptr, get_order(size));
  141. }
  142. static struct crypto_ahash *ima_alloc_atfm(enum hash_algo algo)
  143. {
  144. struct crypto_ahash *tfm = ima_ahash_tfm;
  145. int rc;
  146. if (algo < 0 || algo >= HASH_ALGO__LAST)
  147. algo = ima_hash_algo;
  148. if (algo != ima_hash_algo || !tfm) {
  149. tfm = crypto_alloc_ahash(hash_algo_name[algo], 0, 0);
  150. if (!IS_ERR(tfm)) {
  151. if (algo == ima_hash_algo)
  152. ima_ahash_tfm = tfm;
  153. } else {
  154. rc = PTR_ERR(tfm);
  155. pr_err("Can not allocate %s (reason: %d)\n",
  156. hash_algo_name[algo], rc);
  157. }
  158. }
  159. return tfm;
  160. }
  161. static void ima_free_atfm(struct crypto_ahash *tfm)
  162. {
  163. if (tfm != ima_ahash_tfm)
  164. crypto_free_ahash(tfm);
  165. }
  166. static inline int ahash_wait(int err, struct crypto_wait *wait)
  167. {
  168. err = crypto_wait_req(err, wait);
  169. if (err)
  170. pr_crit_ratelimited("ahash calculation failed: err: %d\n", err);
  171. return err;
  172. }
  173. static int ima_calc_file_hash_atfm(struct file *file,
  174. struct ima_digest_data *hash,
  175. struct crypto_ahash *tfm)
  176. {
  177. loff_t i_size, offset;
  178. char *rbuf[2] = { NULL, };
  179. int rc, rbuf_len, active = 0, ahash_rc = 0;
  180. struct ahash_request *req;
  181. struct scatterlist sg[1];
  182. struct crypto_wait wait;
  183. size_t rbuf_size[2];
  184. hash->length = crypto_ahash_digestsize(tfm);
  185. req = ahash_request_alloc(tfm, GFP_KERNEL);
  186. if (!req)
  187. return -ENOMEM;
  188. crypto_init_wait(&wait);
  189. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG |
  190. CRYPTO_TFM_REQ_MAY_SLEEP,
  191. crypto_req_done, &wait);
  192. rc = ahash_wait(crypto_ahash_init(req), &wait);
  193. if (rc)
  194. goto out1;
  195. i_size = i_size_read(file_inode(file));
  196. if (i_size == 0)
  197. goto out2;
  198. /*
  199. * Try to allocate maximum size of memory.
  200. * Fail if even a single page cannot be allocated.
  201. */
  202. rbuf[0] = ima_alloc_pages(i_size, &rbuf_size[0], 1);
  203. if (!rbuf[0]) {
  204. rc = -ENOMEM;
  205. goto out1;
  206. }
  207. /* Only allocate one buffer if that is enough. */
  208. if (i_size > rbuf_size[0]) {
  209. /*
  210. * Try to allocate secondary buffer. If that fails fallback to
  211. * using single buffering. Use previous memory allocation size
  212. * as baseline for possible allocation size.
  213. */
  214. rbuf[1] = ima_alloc_pages(i_size - rbuf_size[0],
  215. &rbuf_size[1], 0);
  216. }
  217. for (offset = 0; offset < i_size; offset += rbuf_len) {
  218. if (!rbuf[1] && offset) {
  219. /* Not using two buffers, and it is not the first
  220. * read/request, wait for the completion of the
  221. * previous ahash_update() request.
  222. */
  223. rc = ahash_wait(ahash_rc, &wait);
  224. if (rc)
  225. goto out3;
  226. }
  227. /* read buffer */
  228. rbuf_len = min_t(loff_t, i_size - offset, rbuf_size[active]);
  229. rc = integrity_kernel_read(file, offset, rbuf[active],
  230. rbuf_len);
  231. if (rc != rbuf_len)
  232. goto out3;
  233. if (rbuf[1] && offset) {
  234. /* Using two buffers, and it is not the first
  235. * read/request, wait for the completion of the
  236. * previous ahash_update() request.
  237. */
  238. rc = ahash_wait(ahash_rc, &wait);
  239. if (rc)
  240. goto out3;
  241. }
  242. sg_init_one(&sg[0], rbuf[active], rbuf_len);
  243. ahash_request_set_crypt(req, sg, NULL, rbuf_len);
  244. ahash_rc = crypto_ahash_update(req);
  245. if (rbuf[1])
  246. active = !active; /* swap buffers, if we use two */
  247. }
  248. /* wait for the last update request to complete */
  249. rc = ahash_wait(ahash_rc, &wait);
  250. out3:
  251. ima_free_pages(rbuf[0], rbuf_size[0]);
  252. ima_free_pages(rbuf[1], rbuf_size[1]);
  253. out2:
  254. if (!rc) {
  255. ahash_request_set_crypt(req, NULL, hash->digest, 0);
  256. rc = ahash_wait(crypto_ahash_final(req), &wait);
  257. }
  258. out1:
  259. ahash_request_free(req);
  260. return rc;
  261. }
  262. static int ima_calc_file_ahash(struct file *file, struct ima_digest_data *hash)
  263. {
  264. struct crypto_ahash *tfm;
  265. int rc;
  266. tfm = ima_alloc_atfm(hash->algo);
  267. if (IS_ERR(tfm))
  268. return PTR_ERR(tfm);
  269. rc = ima_calc_file_hash_atfm(file, hash, tfm);
  270. ima_free_atfm(tfm);
  271. return rc;
  272. }
  273. static int ima_calc_file_hash_tfm(struct file *file,
  274. struct ima_digest_data *hash,
  275. struct crypto_shash *tfm)
  276. {
  277. loff_t i_size, offset = 0;
  278. char *rbuf;
  279. int rc;
  280. SHASH_DESC_ON_STACK(shash, tfm);
  281. shash->tfm = tfm;
  282. shash->flags = 0;
  283. hash->length = crypto_shash_digestsize(tfm);
  284. rc = crypto_shash_init(shash);
  285. if (rc != 0)
  286. return rc;
  287. i_size = i_size_read(file_inode(file));
  288. if (i_size == 0)
  289. goto out;
  290. rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
  291. if (!rbuf)
  292. return -ENOMEM;
  293. while (offset < i_size) {
  294. int rbuf_len;
  295. rbuf_len = integrity_kernel_read(file, offset, rbuf, PAGE_SIZE);
  296. if (rbuf_len < 0) {
  297. rc = rbuf_len;
  298. break;
  299. }
  300. if (rbuf_len == 0)
  301. break;
  302. offset += rbuf_len;
  303. rc = crypto_shash_update(shash, rbuf, rbuf_len);
  304. if (rc)
  305. break;
  306. }
  307. kfree(rbuf);
  308. out:
  309. if (!rc)
  310. rc = crypto_shash_final(shash, hash->digest);
  311. return rc;
  312. }
  313. static int ima_calc_file_shash(struct file *file, struct ima_digest_data *hash)
  314. {
  315. struct crypto_shash *tfm;
  316. int rc;
  317. tfm = ima_alloc_tfm(hash->algo);
  318. if (IS_ERR(tfm))
  319. return PTR_ERR(tfm);
  320. rc = ima_calc_file_hash_tfm(file, hash, tfm);
  321. ima_free_tfm(tfm);
  322. return rc;
  323. }
  324. /*
  325. * ima_calc_file_hash - calculate file hash
  326. *
  327. * Asynchronous hash (ahash) allows using HW acceleration for calculating
  328. * a hash. ahash performance varies for different data sizes on different
  329. * crypto accelerators. shash performance might be better for smaller files.
  330. * The 'ima.ahash_minsize' module parameter allows specifying the best
  331. * minimum file size for using ahash on the system.
  332. *
  333. * If the ima.ahash_minsize parameter is not specified, this function uses
  334. * shash for the hash calculation. If ahash fails, it falls back to using
  335. * shash.
  336. */
  337. int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash)
  338. {
  339. loff_t i_size;
  340. int rc;
  341. struct file *f = file;
  342. bool new_file_instance = false, modified_flags = false;
  343. /*
  344. * For consistency, fail file's opened with the O_DIRECT flag on
  345. * filesystems mounted with/without DAX option.
  346. */
  347. if (file->f_flags & O_DIRECT) {
  348. hash->length = hash_digest_size[ima_hash_algo];
  349. hash->algo = ima_hash_algo;
  350. return -EINVAL;
  351. }
  352. /* Open a new file instance in O_RDONLY if we cannot read */
  353. if (!(file->f_mode & FMODE_READ)) {
  354. int flags = file->f_flags & ~(O_WRONLY | O_APPEND |
  355. O_TRUNC | O_CREAT | O_NOCTTY | O_EXCL);
  356. flags |= O_RDONLY;
  357. f = dentry_open(&file->f_path, flags, file->f_cred);
  358. if (IS_ERR(f)) {
  359. /*
  360. * Cannot open the file again, lets modify f_flags
  361. * of original and continue
  362. */
  363. pr_info_ratelimited("Unable to reopen file for reading.\n");
  364. f = file;
  365. f->f_flags |= FMODE_READ;
  366. modified_flags = true;
  367. } else {
  368. new_file_instance = true;
  369. }
  370. }
  371. i_size = i_size_read(file_inode(f));
  372. if (ima_ahash_minsize && i_size >= ima_ahash_minsize) {
  373. rc = ima_calc_file_ahash(f, hash);
  374. if (!rc)
  375. goto out;
  376. }
  377. rc = ima_calc_file_shash(f, hash);
  378. out:
  379. if (new_file_instance)
  380. fput(f);
  381. else if (modified_flags)
  382. f->f_flags &= ~FMODE_READ;
  383. return rc;
  384. }
  385. /*
  386. * Calculate the hash of template data
  387. */
  388. static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data,
  389. struct ima_template_desc *td,
  390. int num_fields,
  391. struct ima_digest_data *hash,
  392. struct crypto_shash *tfm)
  393. {
  394. SHASH_DESC_ON_STACK(shash, tfm);
  395. int rc, i;
  396. shash->tfm = tfm;
  397. shash->flags = 0;
  398. hash->length = crypto_shash_digestsize(tfm);
  399. rc = crypto_shash_init(shash);
  400. if (rc != 0)
  401. return rc;
  402. for (i = 0; i < num_fields; i++) {
  403. u8 buffer[IMA_EVENT_NAME_LEN_MAX + 1] = { 0 };
  404. u8 *data_to_hash = field_data[i].data;
  405. u32 datalen = field_data[i].len;
  406. u32 datalen_to_hash =
  407. !ima_canonical_fmt ? datalen : cpu_to_le32(datalen);
  408. if (strcmp(td->name, IMA_TEMPLATE_IMA_NAME) != 0) {
  409. rc = crypto_shash_update(shash,
  410. (const u8 *) &datalen_to_hash,
  411. sizeof(datalen_to_hash));
  412. if (rc)
  413. break;
  414. } else if (strcmp(td->fields[i]->field_id, "n") == 0) {
  415. memcpy(buffer, data_to_hash, datalen);
  416. data_to_hash = buffer;
  417. datalen = IMA_EVENT_NAME_LEN_MAX + 1;
  418. }
  419. rc = crypto_shash_update(shash, data_to_hash, datalen);
  420. if (rc)
  421. break;
  422. }
  423. if (!rc)
  424. rc = crypto_shash_final(shash, hash->digest);
  425. return rc;
  426. }
  427. int ima_calc_field_array_hash(struct ima_field_data *field_data,
  428. struct ima_template_desc *desc, int num_fields,
  429. struct ima_digest_data *hash)
  430. {
  431. struct crypto_shash *tfm;
  432. int rc;
  433. tfm = ima_alloc_tfm(hash->algo);
  434. if (IS_ERR(tfm))
  435. return PTR_ERR(tfm);
  436. rc = ima_calc_field_array_hash_tfm(field_data, desc, num_fields,
  437. hash, tfm);
  438. ima_free_tfm(tfm);
  439. return rc;
  440. }
  441. static int calc_buffer_ahash_atfm(const void *buf, loff_t len,
  442. struct ima_digest_data *hash,
  443. struct crypto_ahash *tfm)
  444. {
  445. struct ahash_request *req;
  446. struct scatterlist sg;
  447. struct crypto_wait wait;
  448. int rc, ahash_rc = 0;
  449. hash->length = crypto_ahash_digestsize(tfm);
  450. req = ahash_request_alloc(tfm, GFP_KERNEL);
  451. if (!req)
  452. return -ENOMEM;
  453. crypto_init_wait(&wait);
  454. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG |
  455. CRYPTO_TFM_REQ_MAY_SLEEP,
  456. crypto_req_done, &wait);
  457. rc = ahash_wait(crypto_ahash_init(req), &wait);
  458. if (rc)
  459. goto out;
  460. sg_init_one(&sg, buf, len);
  461. ahash_request_set_crypt(req, &sg, NULL, len);
  462. ahash_rc = crypto_ahash_update(req);
  463. /* wait for the update request to complete */
  464. rc = ahash_wait(ahash_rc, &wait);
  465. if (!rc) {
  466. ahash_request_set_crypt(req, NULL, hash->digest, 0);
  467. rc = ahash_wait(crypto_ahash_final(req), &wait);
  468. }
  469. out:
  470. ahash_request_free(req);
  471. return rc;
  472. }
  473. static int calc_buffer_ahash(const void *buf, loff_t len,
  474. struct ima_digest_data *hash)
  475. {
  476. struct crypto_ahash *tfm;
  477. int rc;
  478. tfm = ima_alloc_atfm(hash->algo);
  479. if (IS_ERR(tfm))
  480. return PTR_ERR(tfm);
  481. rc = calc_buffer_ahash_atfm(buf, len, hash, tfm);
  482. ima_free_atfm(tfm);
  483. return rc;
  484. }
  485. static int calc_buffer_shash_tfm(const void *buf, loff_t size,
  486. struct ima_digest_data *hash,
  487. struct crypto_shash *tfm)
  488. {
  489. SHASH_DESC_ON_STACK(shash, tfm);
  490. unsigned int len;
  491. int rc;
  492. shash->tfm = tfm;
  493. shash->flags = 0;
  494. hash->length = crypto_shash_digestsize(tfm);
  495. rc = crypto_shash_init(shash);
  496. if (rc != 0)
  497. return rc;
  498. while (size) {
  499. len = size < PAGE_SIZE ? size : PAGE_SIZE;
  500. rc = crypto_shash_update(shash, buf, len);
  501. if (rc)
  502. break;
  503. buf += len;
  504. size -= len;
  505. }
  506. if (!rc)
  507. rc = crypto_shash_final(shash, hash->digest);
  508. return rc;
  509. }
  510. static int calc_buffer_shash(const void *buf, loff_t len,
  511. struct ima_digest_data *hash)
  512. {
  513. struct crypto_shash *tfm;
  514. int rc;
  515. tfm = ima_alloc_tfm(hash->algo);
  516. if (IS_ERR(tfm))
  517. return PTR_ERR(tfm);
  518. rc = calc_buffer_shash_tfm(buf, len, hash, tfm);
  519. ima_free_tfm(tfm);
  520. return rc;
  521. }
  522. int ima_calc_buffer_hash(const void *buf, loff_t len,
  523. struct ima_digest_data *hash)
  524. {
  525. int rc;
  526. if (ima_ahash_minsize && len >= ima_ahash_minsize) {
  527. rc = calc_buffer_ahash(buf, len, hash);
  528. if (!rc)
  529. return 0;
  530. }
  531. return calc_buffer_shash(buf, len, hash);
  532. }
  533. static void __init ima_pcrread(int idx, u8 *pcr)
  534. {
  535. if (!ima_tpm_chip)
  536. return;
  537. if (tpm_pcr_read(ima_tpm_chip, idx, pcr) != 0)
  538. pr_err("Error Communicating to TPM chip\n");
  539. }
  540. /*
  541. * Calculate the boot aggregate hash
  542. */
  543. static int __init ima_calc_boot_aggregate_tfm(char *digest,
  544. struct crypto_shash *tfm)
  545. {
  546. u8 pcr_i[TPM_DIGEST_SIZE];
  547. int rc, i;
  548. SHASH_DESC_ON_STACK(shash, tfm);
  549. shash->tfm = tfm;
  550. shash->flags = 0;
  551. rc = crypto_shash_init(shash);
  552. if (rc != 0)
  553. return rc;
  554. /* cumulative sha1 over tpm registers 0-7 */
  555. for (i = TPM_PCR0; i < TPM_PCR8; i++) {
  556. ima_pcrread(i, pcr_i);
  557. /* now accumulate with current aggregate */
  558. rc = crypto_shash_update(shash, pcr_i, TPM_DIGEST_SIZE);
  559. }
  560. if (!rc)
  561. crypto_shash_final(shash, digest);
  562. return rc;
  563. }
  564. int __init ima_calc_boot_aggregate(struct ima_digest_data *hash)
  565. {
  566. struct crypto_shash *tfm;
  567. int rc;
  568. tfm = ima_alloc_tfm(hash->algo);
  569. if (IS_ERR(tfm))
  570. return PTR_ERR(tfm);
  571. hash->length = crypto_shash_digestsize(tfm);
  572. rc = ima_calc_boot_aggregate_tfm(hash->digest, tfm);
  573. ima_free_tfm(tfm);
  574. return rc;
  575. }