From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=113.46.200.225 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796283501; b=wD5ia/HZwI8ZmklFKJXU759Mn+vWgBAXd7FCLl9ZOd2/Pda+gkbsu+Ilodramz/zcYgq EZKMwBmhROgW2ZBkAdQHf9IWo0ZhKI+obRaKe3u+cJlK08bkNwkHcyGGXliilpJX2b2Xa T5hDSg1vImSESZMy2E8lJ5umusjsJS9mLxqNJ6y/brBpq2IbfezvOX2fJS955Htp1gyz5 vGboEPR4Hxgkt9JaxkO0yrJ1HFVoPFqahbCOYXj/ga5OzGIy0wxO53m1qfYFMfQ0b8qj4 8mQxXM8W4ssxgOPHU6x8NlUYe1qfqPzrP4aFL4nJ7HueL8fsbzmKnZBtsQe4E9FnkRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796283501; h=DMARC-Filter:dkim-signature:Received:Received:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:CC:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Originating-IP:X-ClientProxiedBy; bh=/jb9MVjBYLto6Qi+L9o3KcAzI957XheHojhVG1ZHBpw=; b=iwqQ7FCVc4a037PAusgRTPbeuaNUnA3m1G3SiKd6rxx47AEQR/x3QwaqRz+I5UBGOi// /GKNzopwLTo1ETwGLVEoXsoPSFcThK53da09O2PeOl7T/u0IDRGd/Vz0Bn9whnONbpCfK yoERVDgSIgXIvy3MTiOzkDxsdPg/WrvB3tYbGFZRM7228ldR05Uh9R9/x311NljGgcMuT qydvtktpSNudB0vcbxZ9mJqHI3uQMQ7xd1lYYHw6ubc9NSy/LyYoNTqwvWBgTfxaXjH// rRLwBOmeG8wR9wOpmn2ynXDjVrTyJbWHLPLCBC9kpegy8OZS/izJl/pLYHnLGJyuGgw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=yF5HQVZi; arc=none smtp.remote-ip=113.46.200.225 Received: from canpmsgout10.his.huawei.com (canpmsgout10.his.huawei.com [113.46.200.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 928E0606A322 for ; Thu, 3 Dec 2026 07:38:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 928E0606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=yF5HQVZi dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=/jb9MVjBYLto6Qi+L9o3KcAzI957XheHojhVG1ZHBpw=; b=yF5HQVZioMy4dj1sgVg6cIeRtDhLFJESXowhEHNqdynQ9ejtQReicQXPFoauwieQAaq+hVpms swcesyTlkPCkrSq6XRWH+PzC0PI3Z4XiBmZC4gEIV/meENo4PQz2vWUQTuyD2rP2csLXTYxTz2P Ogm826NFJZFBsWEGmuTywM4= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4jg5zk3yP6z1K9Br; Thu, 3 Dec 2026 15:36:50 +0800 (CST) Received: from kwepemo100015.china.huawei.com (unknown [7.202.195.69]) by mail.maildlp.com (Postfix) with ESMTPS id B4C3E40565; Thu, 3 Dec 2026 15:38:14 +0800 (CST) Received: from [10.67.111.244] (10.67.111.244) by kwepemo100015.china.huawei.com (7.202.195.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Thu, 3 Dec 2026 15:38:14 +0800 Message-ID: <30f23576-e4d4-4195-9f8d-98c080f5ddf2@huawei.com> Date: Thu, 3 Dec 2026 15:38:07 +0800 X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] ima: Honor pcr=0 policy rules for buffer measurements To: Roberto Sassu , Gong Ruiqi , Mimi Zohar , Roberto Sassu , Dmitry Kasatkin , Eric Snowberg CC: Michael Ellerman , Nayna Jain , , Weng Jiaxuan , Lu Jialin References: <20261201015448.2340726-1-ruiqi.gong@huawei.com> <073e15e2db3880b706caf45b9ad069a5aab2cc28.camel@huaweicloud.com> Content-Language: en-US From: GONG Ruiqi In-Reply-To: <073e15e2db3880b706caf45b9ad069a5aab2cc28.camel@huaweicloud.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemo100015.china.huawei.com (7.202.195.69) 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 >> Signed-off-by: Gong Ruiqi >> --- >> 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); >