From nobody Thu Apr 2 20:22:11 2026 Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD6F2423A60; Thu, 26 Mar 2026 17:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774546274; cv=none; b=s66i9vQz0Lqcl2ZqlQRwwVrmHyxyJ/aJ7Z1YwYcrwjwyDcOklA6iTnVFBfiis5/h5QUgeDaW/uZjuI/KF1GRT7aK/xBrOsAokqxhFBYNHnmVDVYbpyOgGDfcuNIbPB171rJ+PSLd2rv2PXuLnigZbLiQmzI/2NE5t38BZNRryuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774546274; c=relaxed/simple; bh=eFIWqqy1wtC225lm99O/cnD1/2fRP8mqzqJR8Px3QK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oln76301pikBgQoLE6BAKIWqoVfzML5gcgKsV6DSUY7+krtkcEgXxxek0ZshuQhQk8oWA0QYT5NKGHKIXGkvWzl2yqTOfxBGqKX1GsXMNV9Sy9UWiNsNBSZbN+kAnTFqfXMqdVFUVHs5xxkPo49eXtOpo3YNkQwFeituhcSpO1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.224.196]) by frasgout13.his.huawei.com (SkyGuard) with ESMTPS id 4fhW1M1WtHzpVwq; Fri, 27 Mar 2026 01:27:19 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id 714974056B; Fri, 27 Mar 2026 01:31:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB3Yu84bcVppGUvAQ--.1881S5; Thu, 26 Mar 2026 18:31:06 +0100 (CET) From: Roberto Sassu To: corbet@lwn.net, skhan@linuxfoundation.org, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, eric.snowberg@oracle.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, gregorylumen@linux.microsoft.com, chenste@linux.microsoft.com, nramas@linux.microsoft.com, Roberto Sassu Subject: [PATCH v4 03/13] ima: Introduce per binary measurements list type ima_num_entries counter Date: Thu, 26 Mar 2026 18:30:01 +0100 Message-ID: <20260326173011.1191815-4-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260326173011.1191815-1-roberto.sassu@huaweicloud.com> References: <20260326173011.1191815-1-roberto.sassu@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: LxC2BwB3Yu84bcVppGUvAQ--.1881S5 X-Coremail-Antispam: 1UD129KBjvJXoWxGw1kZr4fKFy3CF45tF1kKrg_yoWrXF17pa nIgF1UJr18XFy2krykCa47Aa9ag3yrKryUWw45W3say3ZrXr1UXFn8AF12kFn5Gr90yr1I qwn0qw45Aa1vyrJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPqb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW8JVW5JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCY1x0262kKe7 AKxVWrXVW3AwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02 F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_Wr ylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI 0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x 07jSiihUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAEBGnEnSsT2QABsR Content-Type: text/plain; charset="utf-8" From: Roberto Sassu Make ima_num_entries as an array, to have separate counters per binary measurements list type. Currently, define the BINARY type for the existing binary measurements list. No functional change: the BINARY type is equivalent to the value without the array. Link: https://github.com/linux-integrity/linux/issues/1 Signed-off-by: Roberto Sassu --- security/integrity/ima/ima.h | 9 ++++++++- security/integrity/ima/ima_fs.c | 3 +-- security/integrity/ima/ima_kexec.c | 2 +- security/integrity/ima/ima_queue.c | 7 +++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 9cdc4c5afd3b..199237e2d2e3 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -28,6 +28,13 @@ 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 =3D 0, TPM_PCR8 =3D 8, TPM_PCR10 =3D 10 }; =20 +/* + * BINARY: current binary measurements list + */ +enum binary_lists { + BINARY, BINARY__LAST +}; + /* digest size for IMA, fits SHA1 or MD5 */ #define IMA_DIGEST_SIZE SHA1_DIGEST_SIZE #define IMA_EVENT_NAME_LEN_MAX 255 @@ -324,7 +331,7 @@ int ima_lsm_policy_change(struct notifier_block *nb, un= signed long event, */ extern spinlock_t ima_queue_lock; =20 -extern atomic_long_t ima_num_entries; +extern atomic_long_t ima_num_entries[BINARY__LAST]; extern atomic_long_t ima_num_violations; extern struct hlist_head __rcu *ima_htable; =20 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_f= s.c index aaa460d70ff7..79b0f287c668 100644 --- a/security/integrity/ima/ima_fs.c +++ b/security/integrity/ima/ima_fs.c @@ -63,8 +63,7 @@ static ssize_t ima_show_measurements_count(struct file *f= ilp, char __user *buf, size_t count, loff_t *ppos) { - return ima_show_counter(buf, count, ppos, &ima_num_entries); - + return ima_show_counter(buf, count, ppos, &ima_num_entries[BINARY]); } =20 static const struct file_operations ima_measurements_count_ops =3D { diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/im= a_kexec.c index 5801649fbbef..40962dc0ca86 100644 --- a/security/integrity/ima/ima_kexec.c +++ b/security/integrity/ima/ima_kexec.c @@ -43,7 +43,7 @@ void ima_measure_kexec_event(const char *event_name) int n; =20 buf_size =3D ima_get_binary_runtime_size(); - len =3D atomic_long_read(&ima_num_entries); + len =3D atomic_long_read(&ima_num_entries[BINARY]); =20 n =3D scnprintf(ima_kexec_event, IMA_KEXEC_EVENT_LEN, "kexec_segment_size=3D%lu;ima_binary_runtime_size=3D%lu;" diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/im= a_queue.c index 41f4941ceaad..952172a4905d 100644 --- a/security/integrity/ima/ima_queue.c +++ b/security/integrity/ima/ima_queue.c @@ -33,7 +33,10 @@ static unsigned long binary_runtime_size =3D ULONG_MAX; #endif =20 /* num of stored measurements in the list */ -atomic_long_t ima_num_entries =3D ATOMIC_LONG_INIT(0); +atomic_long_t ima_num_entries[BINARY__LAST] =3D { + [0 ... BINARY__LAST - 1] =3D ATOMIC_LONG_INIT(0) +}; + /* num of violations in the list */ atomic_long_t ima_num_violations =3D ATOMIC_LONG_INIT(0); =20 @@ -154,7 +157,7 @@ static int ima_add_digest_entry(struct ima_template_ent= ry *entry, htable =3D rcu_dereference_protected(ima_htable, lockdep_is_held(&ima_extend_list_mutex)); =20 - atomic_long_inc(&ima_num_entries); + atomic_long_inc(&ima_num_entries[BINARY]); if (update_htable) { key =3D ima_hash_key(entry->digests[ima_hash_algo_idx].digest); hlist_add_head_rcu(&qe->hnext, &htable[key]); --=20 2.43.0