From: GONG Ruiqi <gongruiqi1@huawei.com>
To: Roberto Sassu <roberto.sassu@huaweicloud.com>,
Gong Ruiqi <ruiqi.gong@huawei.com>,
Mimi Zohar <zohar@linux.ibm.com>,
Roberto Sassu <roberto.sassu@huawei.com>,
Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
Eric Snowberg <eric.snowberg@oracle.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Nayna Jain <nayna@linux.ibm.com>,
<linux-integrity@vger.kernel.org>,
Weng Jiaxuan <weng_jiaxuan@163.com>,
Lu Jialin <lujialin4@huawei.com>
Subject: Re: [PATCH] ima: Honor pcr=0 policy rules for buffer measurements
Date: Thu, 3 Dec 2026 15:38:07 +0800 [thread overview]
Message-ID: <30f23576-e4d4-4195-9f8d-98c080f5ddf2@huawei.com> (raw)
In-Reply-To: <073e15e2db3880b706caf45b9ad069a5aab2cc28.camel@huaweicloud.com>
On 12/2/2026 8:50 PM, Roberto Sassu wrote:
Hi Roberto.
> On Tue, 2026-12-01 at 09:54 +0800, Gong Ruiqi wrote:
>
> Hi Ruiqi
>
> in general, I think it is a good practice to CC the linux-security-
> module and linux-kernel mailing lists too.
Oops, my mistake. Will do when sending v2.
>
>> process_buffer_measurement() takes the target PCR as an int argument
>> and treats 0 as "no PCR given", replacing it with
>> CONFIG_IMA_MEASURE_PCR_IDX. PCR 0 is a legitimate index: it passes
>> INVALID_PCR() and ima_parse_rule() accepts a rule with pcr=0, setting
>> IMA_PCR on it. ima_match_policy() then writes that 0 back into the
>> caller's variable, and the fallback immediately overwrites it with the
>> default.
>>
>> As a result every buffer measurement governed by a pcr=0 rule lands in
>> the default PCR instead: critical data, keys, kexec cmdline, raw policy
>> writes, and the auxiliary blacklisted-hash record when the file's rule
>> says pcr=0. File measurements take the other route:
>> process_measurement() pre-seeds pcr with the default and lets a
>> matching rule override it, so pcr=0 works there. The two paths disagree.
>>
>> Use a dedicated sentinel, IMA_PCR_UNSET (-1), for "no PCR given". A
>> negative value is outside the range INVALID_PCR() accepts, so it cannot
>> be mistaken for a real index, and it is resolved before
>> ima_store_template(), which keeps it away from the u32 pcr_idx of
>> tpm_pcr_extend() and from the shifts by pcr in
>> ima_store_measurement(). Callers that used to pass 0 now pass the
>> sentinel. ima_check_blacklist() passes the PCR of the file's rule on
>> purpose and is left alone.
>
> Wouldn't be better to pass the default PCR where the callers pass 0,
> and remove the fallback?
True. No reason for another (or any) sentinel. I'll make a v2.
Thanks,
Ruiqi
>
> Thanks
>
> Roberto
>
>> Fixes: e14555e3d0e9e ("ima: Make process_buffer_measurement() generic")
>> Signed-off-by: Weng Jiaxuan <weng_jiaxuan@163.com>
>> Signed-off-by: Gong Ruiqi <ruiqi.gong@huawei.com>
>> ---
>> security/integrity/ima/ima.h | 3 +++
>> security/integrity/ima/ima_asymmetric_keys.c | 2 +-
>> security/integrity/ima/ima_main.c | 10 +++++-----
>> security/integrity/ima/ima_queue_keys.c | 2 +-
>> 4 files changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
>> index b502854f28ee..5040b8ebf501 100644
>> --- a/security/integrity/ima/ima.h
>> +++ b/security/integrity/ima/ima.h
>> @@ -28,6 +28,9 @@ enum ima_show_type { IMA_SHOW_BINARY, IMA_SHOW_BINARY_NO_FIELD_LEN,
>> IMA_SHOW_BINARY_OLD_STRING_FMT, IMA_SHOW_ASCII };
>> enum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8, TPM_PCR10 = 10 };
>>
>> +/* "no PCR given": never a valid index, see INVALID_PCR() in ima_policy.c */
>> +#define IMA_PCR_UNSET (-1)
>> +
>> /*
>> * BINARY: current binary measurements list
>> * BINARY_STAGED: staged binary measurements list
>> diff --git a/security/integrity/ima/ima_asymmetric_keys.c b/security/integrity/ima/ima_asymmetric_keys.c
>> index caacfe6860b1..223de01703a7 100644
>> --- a/security/integrity/ima/ima_asymmetric_keys.c
>> +++ b/security/integrity/ima/ima_asymmetric_keys.c
>> @@ -61,6 +61,6 @@ void ima_post_key_create_or_update(struct key *keyring, struct key *key,
>> * to the given keyring.
>> */
>> process_buffer_measurement(&nop_mnt_idmap, NULL, payload, payload_len,
>> - keyring->description, KEY_CHECK, 0,
>> + keyring->description, KEY_CHECK, IMA_PCR_UNSET,
>> keyring->description, false, NULL, 0);
>> }
>> diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
>> index fed80da3ee09..707f4073d1b5 100644
>> --- a/security/integrity/ima/ima_main.c
>> +++ b/security/integrity/ima/ima_main.c
>> @@ -1084,7 +1084,7 @@ static int ima_post_load_data(char *buf, loff_t size,
>> * @size: size of buffer(in bytes).
>> * @eventname: event name to be used for the buffer entry.
>> * @func: IMA hook
>> - * @pcr: pcr to extend the measurement
>> + * @pcr: pcr to extend the measurement, or IMA_PCR_UNSET for the default PCR
>> * @func_data: func specific data, may be NULL
>> * @buf_hash: measure buffer data hash
>> * @digest: buffer digest will be written to
>> @@ -1149,7 +1149,7 @@ int process_buffer_measurement(const struct mnt_idmap *idmap,
>> return -ENOENT;
>> }
>>
>> - if (!pcr)
>> + if (pcr == IMA_PCR_UNSET)
>> pcr = CONFIG_IMA_MEASURE_PCR_IDX;
>>
>> iint.ima_hash = hash_hdr;
>> @@ -1221,7 +1221,7 @@ void ima_kexec_cmdline(int kernel_fd, const void *buf, int size)
>> return;
>>
>> process_buffer_measurement(file_mnt_idmap(fd_file(f)), file_inode(fd_file(f)),
>> - buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0,
>> + buf, size, "kexec-cmdline", KEXEC_CMDLINE, IMA_PCR_UNSET,
>> NULL, false, NULL, 0);
>> }
>>
>> @@ -1253,7 +1253,7 @@ int ima_measure_critical_data(const char *event_label,
>> return -ENOPARAM;
>>
>> return process_buffer_measurement(&nop_mnt_idmap, NULL, buf, buf_len,
>> - event_name, CRITICAL_DATA, 0,
>> + event_name, CRITICAL_DATA, IMA_PCR_UNSET,
>> event_label, hash, digest,
>> digest_len);
>> }
>> @@ -1278,7 +1278,7 @@ int ima_measure_raw_policy(const char *buf, size_t buf_len)
>>
>> return process_buffer_measurement(&nop_mnt_idmap, NULL, buf, buf_len,
>> "ima_policy_written", POLICY_CHECK,
>> - 0, NULL, false, NULL, 0);
>> + IMA_PCR_UNSET, NULL, false, NULL, 0);
>> }
>>
>> #ifdef CONFIG_INTEGRITY_ASYMMETRIC_KEYS
>> diff --git a/security/integrity/ima/ima_queue_keys.c b/security/integrity/ima/ima_queue_keys.c
>> index 8adc8863ad5a..c3077bd0e247 100644
>> --- a/security/integrity/ima/ima_queue_keys.c
>> +++ b/security/integrity/ima/ima_queue_keys.c
>> @@ -163,7 +163,7 @@ void ima_process_queued_keys(void)
>> entry->payload,
>> entry->payload_len,
>> entry->keyring_name,
>> - KEY_CHECK, 0,
>> + KEY_CHECK, IMA_PCR_UNSET,
>> entry->keyring_name,
>> false, NULL, 0);
>> list_del(&entry->list);
>
prev parent reply other threads:[~2026-12-03 7:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 1:54 [PATCH] ima: Honor pcr=0 policy rules for buffer measurements Gong Ruiqi
2026-12-02 12:50 ` Roberto Sassu
2026-12-03 7:38 ` GONG Ruiqi [this message]
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=30f23576-e4d4-4195-9f8d-98c080f5ddf2@huawei.com \
--to=gongruiqi1@huawei.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=eric.snowberg@oracle.com \
--cc=linux-integrity@vger.kernel.org \
--cc=lujialin4@huawei.com \
--cc=mpe@ellerman.id.au \
--cc=nayna@linux.ibm.com \
--cc=roberto.sassu@huawei.com \
--cc=roberto.sassu@huaweicloud.com \
--cc=ruiqi.gong@huawei.com \
--cc=weng_jiaxuan@163.com \
--cc=zohar@linux.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox