From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH RFC 2/3] security: IMA: introduce ima_mr structure
Date: Wed, 30 Sep 2026 13:55:15 +0000 [thread overview]
Message-ID: <20260930135515.DB4421F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260930-ima_tgx_integration_v2-v1-2-722c35370548@arm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] ima: memory leak of ima_shash_tfm and ima_algo_array in ima_init_crypto()
- [Medium] ima: memory leak of digests array in ima_init_digests()
--
commit babc42a28171ec6623537f00a8d1222d9f72a6e2
Author: Yeoreum Yun <yeoreum.yun@arm.com>
security: IMA: introduce ima_mr structure
This commit introduces the ima_mr structure to abstract measurement registers
and operations, preparing the subsystem to integrate TSM measurement registers
with IMA. It also migrates the TPM device using PCRs as measurement registers
to use this new interface.
> diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
> index 0d72b48249ee6..efa27ce5f1282 100644
> --- a/security/integrity/ima/ima_crypto.c
> +++ b/security/integrity/ima/ima_crypto.c
[ ... ]
> @@ -77,6 +77,7 @@ int __init ima_init_crypto(void)
> enum hash_algo algo;
> long rc;
> int i;
> + mr_bank_info_t bank_info;
>
> rc = ima_init_ima_crypto();
> if (rc)
> @@ -85,8 +86,12 @@ int __init ima_init_crypto(void)
> ima_sha1_idx = -1;
> ima_hash_algo_idx = -1;
>
> - for (i = 0; i < NR_BANKS(ima_tpm_chip); i++) {
> - algo = ima_tpm_chip->allocated_banks[i].crypto_id;
> + for (i = 0; i < NR_BANKS(ima_mr); i++) {
> + rc = ima_mr->ops->mr_get_bank_info(ima_mr, i, &bank_info);
> + if (rc)
> + return rc;
[Severity: Medium]
Does this direct return bypass the cleanup for ima_shash_tfm?
Since ima_init_ima_crypto() is called earlier and allocates it, it looks
like returning rc here skips the out label where the cleanup happens.
> +
> + algo = bank_info.crypto_id;
> if (algo == HASH_ALGO_SHA1)
> ima_sha1_idx = i;
[ ... ]
> @@ -95,24 +100,28 @@ int __init ima_init_crypto(void)
> if (ima_hash_algo_idx < 0)
> - ima_hash_algo_idx = NR_BANKS(ima_tpm_chip) + ima_extra_slots++;
> + ima_hash_algo_idx = NR_BANKS(ima_mr) + ima_extra_slots++;
>
> ima_algo_array = kzalloc_objs(*ima_algo_array,
> - NR_BANKS(ima_tpm_chip) + ima_extra_slots);
> + NR_BANKS(ima_mr) + ima_extra_slots);
> if (!ima_algo_array) {
> rc = -ENOMEM;
> goto out;
> }
>
> - for (i = 0; i < NR_BANKS(ima_tpm_chip); i++) {
> - algo = ima_tpm_chip->allocated_banks[i].crypto_id;
> - digest_size = ima_tpm_chip->allocated_banks[i].digest_size;
> + for (i = 0; i < NR_BANKS(ima_mr); i++) {
> + rc = ima_mr->ops->mr_get_bank_info(ima_mr, i, &bank_info);
> + if (rc)
> + return rc;
[Severity: Medium]
Could this return cause a memory leak of ima_algo_array and any hash
transforms allocated in previous loop iterations?
Taking this path bypasses the explicitly defined out_array cleanup label.
> +
> + algo = bank_info.crypto_id;
> + digest_size = bank_info.digest_size;
> ima_algo_array[i].algo = algo;
> ima_algo_array[i].digest_size = digest_size;
[ ... ]
> diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
> index 67782c004cdf7..037979829242c 100644
> --- a/security/integrity/ima/ima_queue.c
> +++ b/security/integrity/ima/ima_queue.c
[ ... ]
> @@ -548,25 +547,27 @@ void __init ima_init_reboot_notifier(void)
>
> int __init ima_init_digests(void)
> {
> + int rc, i;
> + mr_bank_info_t bank_info;
> u16 digest_size;
> - u16 crypto_id;
> - int i;
>
> - if (!ima_tpm_chip)
> + if (!ima_mr)
> return 0;
>
> - digests = kzalloc_objs(*digests, ima_tpm_chip->nr_allocated_banks,
> - GFP_NOFS);
> + digests = kzalloc_objs(*digests, NR_BANKS(ima_mr), GFP_NOFS);
> if (!digests)
> return -ENOMEM;
>
> - for (i = 0; i < ima_tpm_chip->nr_allocated_banks; i++) {
> - digests[i].alg_id = ima_tpm_chip->allocated_banks[i].alg_id;
> - digest_size = ima_tpm_chip->allocated_banks[i].digest_size;
> - crypto_id = ima_tpm_chip->allocated_banks[i].crypto_id;
> + for (i = 0; i < NR_BANKS(ima_mr); i++) {
> + rc = ima_mr->ops->mr_get_bank_info(ima_mr, i, &bank_info);
> + if (rc)
> + return rc;
[Severity: Medium]
If mr_get_bank_info() fails here, does this return abandon the newly
allocated digests array?
It appears kfree(digests) might be needed before returning rc to prevent a
memory leak.
> +
> + digests[i].alg_id = bank_info.alg_id;
> + digest_size = bank_info.digest_size;
>
> /* for unmapped TPM algorithms digest is still a padded SHA1 */
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260930-ima_tgx_integration_v2-v1-0-722c35370548@arm.com?part=2
next prev parent reply other threads:[~2026-09-30 13:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 13:43 [PATCH RFC 0/3] security: ima: support TSM measurement registers Yeoreum Yun
2026-09-30 13:43 ` [PATCH RFC 1/3] virt: coco: introduce tsm_default_tm() and tsm_mr_read()/write() Yeoreum Yun
2026-09-30 13:55 ` sashiko-bot
2026-09-30 13:44 ` [PATCH RFC 2/3] security: IMA: introduce ima_mr structure Yeoreum Yun
2026-09-30 13:55 ` sashiko-bot [this message]
2026-09-30 13:44 ` [PATCH RFC 3/3] security: IMA: use TSM measurement registers Yeoreum Yun
2026-09-30 13:59 ` sashiko-bot
2026-10-01 11:27 ` [PATCH RFC 0/3] security: ima: support " Roberto Sassu
2026-10-01 11:45 ` Roberto Sassu
2026-10-01 14:24 ` Yeoreum Yun
2026-10-08 11:10 ` GONG Ruiqi
2026-10-01 15:18 ` Jason Gunthorpe
2026-10-01 16:39 ` Yeoreum Yun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260930135515.DB4421F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.