From nobody Thu Apr 2 20:22:14 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 AD331423A77; Thu, 26 Mar 2026 17:31:00 +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=1774546268; cv=none; b=Tnp7xrMChQKkjHMBaEeLGhpGMhYMis0K8m7puRIy0twV9fB8dAatTjazuXE78d89qgWtWcFAwBsALj+UtEI8b5XnhAbcFGblfgD8jU3fVv1Bb8cKNIL3Ly1zgi5JXFMuJ4jrHHwVB22Jl4GGQ/ZVgHm75D3r+v2kMCvDSUOH45Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774546268; c=relaxed/simple; bh=GVA+pRSUc8z9qjax4x44siGnI0py36BZBiWSsjLmxJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=co+IqDSo9lAvWvWDEpOjp+JQUKiZy03ZdB7QAAOscfATr4RtuWk0qZavvS1aJYaDBm4tUSAbu/9hEP3LGEZYYFI8TQVER4y0w0GyMxjUmr6LOudPyP6f21g9CndCscedumIc2XFoL49oJSyr13Aj+gM7biPXZN/+8jaiudR7aJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none 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=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.224.196]) by frasgout13.his.huawei.com (SkyGuard) with ESMTPS id 4fhW124LvJzpVVw; Fri, 27 Mar 2026 01:27:02 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id D24DE4056C; Fri, 27 Mar 2026 01:30:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB3Yu84bcVppGUvAQ--.1881S3; Thu, 26 Mar 2026 18:30:50 +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 01/13] ima: Remove ima_h_table structure Date: Thu, 26 Mar 2026 18:29:59 +0100 Message-ID: <20260326173011.1191815-2-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--.1881S3 X-Coremail-Antispam: 1UD129KBjvJXoWxtw4rXFW5Zw1fXr1DCry7trb_yoWxtw1kpa nFga42kF48XFyI9ryDAayqkrWrW3yUKr17Wws8Gw1Fk3ZrXr12gF15AFy2kFyfGFZYyF1I qrs0qr1YkwsYyrJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPqb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW8JVW5JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCY1x0262kKe7 AKxVWrXVW3AwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02 F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_Wr ylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI 0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x 07jQ4SrUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAEBGnEnS4TtgAFs8 Content-Type: text/plain; charset="utf-8" From: Roberto Sassu With the upcoming change of dynamically allocating and replacing the hash table, the ima_h_table structure would have been replaced with a new one. However, since the ima_h_table structure contains also the counters for number of measurements entries and violations, we would have needed to preserve their values in the new ima_h_table structure. Instead, separate those counters from the hash table, remove the ima_h_table structure, and just replace the hash table pointer. Finally, rename ima_show_htable_value(), ima_show_htable_violations() and ima_htable_violations_ops respectively to ima_show_counter(), ima_show_num_violations() and ima_num_violations_ops. Link: https://github.com/linux-integrity/linux/issues/1 Signed-off-by: Roberto Sassu --- security/integrity/ima/ima.h | 9 +++------ security/integrity/ima/ima_api.c | 2 +- security/integrity/ima/ima_fs.c | 19 +++++++++---------- security/integrity/ima/ima_kexec.c | 2 +- security/integrity/ima/ima_queue.c | 17 ++++++++++------- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 0eea02ff04df..d759988fde45 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -323,12 +323,9 @@ int ima_lsm_policy_change(struct notifier_block *nb, u= nsigned long event, */ extern spinlock_t ima_queue_lock; =20 -struct ima_h_table { - atomic_long_t len; /* number of stored measurements in the list */ - atomic_long_t violations; - struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE]; -}; -extern struct ima_h_table ima_htable; +extern atomic_long_t ima_num_entries; +extern atomic_long_t ima_num_violations; +extern struct hlist_head ima_htable[IMA_MEASURE_HTABLE_SIZE]; =20 static inline unsigned int ima_hash_key(u8 *digest) { diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_= api.c index 0916f24f005f..122d127e108d 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c @@ -146,7 +146,7 @@ void ima_add_violation(struct file *file, const unsigne= d char *filename, int result; =20 /* can overflow, only indicator */ - atomic_long_inc(&ima_htable.violations); + atomic_long_inc(&ima_num_violations); =20 result =3D ima_alloc_init_template(&event_data, &entry, NULL); if (result < 0) { diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_f= s.c index ca4931a95098..aaa460d70ff7 100644 --- a/security/integrity/ima/ima_fs.c +++ b/security/integrity/ima/ima_fs.c @@ -38,8 +38,8 @@ __setup("ima_canonical_fmt", default_canonical_fmt_setup); =20 static int valid_policy =3D 1; =20 -static ssize_t ima_show_htable_value(char __user *buf, size_t count, - loff_t *ppos, atomic_long_t *val) +static ssize_t ima_show_counter(char __user *buf, size_t count, loff_t *pp= os, + atomic_long_t *val) { char tmpbuf[32]; /* greater than largest 'long' string value */ ssize_t len; @@ -48,15 +48,14 @@ static ssize_t ima_show_htable_value(char __user *buf, = size_t count, return simple_read_from_buffer(buf, count, ppos, tmpbuf, len); } =20 -static ssize_t ima_show_htable_violations(struct file *filp, - char __user *buf, - size_t count, loff_t *ppos) +static ssize_t ima_show_num_violations(struct file *filp, char __user *buf, + size_t count, loff_t *ppos) { - return ima_show_htable_value(buf, count, ppos, &ima_htable.violations); + return ima_show_counter(buf, count, ppos, &ima_num_violations); } =20 -static const struct file_operations ima_htable_violations_ops =3D { - .read =3D ima_show_htable_violations, +static const struct file_operations ima_num_violations_ops =3D { + .read =3D ima_show_num_violations, .llseek =3D generic_file_llseek, }; =20 @@ -64,7 +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_htable_value(buf, count, ppos, &ima_htable.len); + return ima_show_counter(buf, count, ppos, &ima_num_entries); =20 } =20 @@ -545,7 +544,7 @@ int __init ima_fs_init(void) } =20 dentry =3D securityfs_create_file("violations", S_IRUSR | S_IRGRP, - ima_dir, NULL, &ima_htable_violations_ops); + ima_dir, NULL, &ima_num_violations_ops); if (IS_ERR(dentry)) { ret =3D PTR_ERR(dentry); goto out; diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/im= a_kexec.c index 36a34c54de58..5801649fbbef 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_htable.len); + len =3D atomic_long_read(&ima_num_entries); =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 319522450854..1f6515f7d015 100644 --- a/security/integrity/ima/ima_queue.c +++ b/security/integrity/ima/ima_queue.c @@ -32,11 +32,14 @@ static unsigned long binary_runtime_size; 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); +/* num of violations in the list */ +atomic_long_t ima_num_violations =3D ATOMIC_LONG_INIT(0); + /* key: inode (before secure-hashing a file) */ -struct ima_h_table ima_htable =3D { - .len =3D ATOMIC_LONG_INIT(0), - .violations =3D ATOMIC_LONG_INIT(0), - .queue[0 ... IMA_MEASURE_HTABLE_SIZE - 1] =3D HLIST_HEAD_INIT +struct hlist_head ima_htable[IMA_MEASURE_HTABLE_SIZE] =3D { + [0 ... IMA_MEASURE_HTABLE_SIZE - 1] =3D HLIST_HEAD_INIT }; =20 /* mutex protects atomicity of extending measurement list @@ -61,7 +64,7 @@ static struct ima_queue_entry *ima_lookup_digest_entry(u8= *digest_value, =20 key =3D ima_hash_key(digest_value); rcu_read_lock(); - hlist_for_each_entry_rcu(qe, &ima_htable.queue[key], hnext) { + hlist_for_each_entry_rcu(qe, &ima_htable[key], hnext) { rc =3D memcmp(qe->entry->digests[ima_hash_algo_idx].digest, digest_value, hash_digest_size[ima_hash_algo]); if ((rc =3D=3D 0) && (qe->entry->pcr =3D=3D pcr)) { @@ -113,10 +116,10 @@ static int ima_add_digest_entry(struct ima_template_e= ntry *entry, INIT_LIST_HEAD(&qe->later); list_add_tail_rcu(&qe->later, &ima_measurements); =20 - atomic_long_inc(&ima_htable.len); + atomic_long_inc(&ima_num_entries); if (update_htable) { key =3D ima_hash_key(entry->digests[ima_hash_algo_idx].digest); - hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]); + hlist_add_head_rcu(&qe->hnext, &ima_htable[key]); } =20 if (binary_runtime_size !=3D ULONG_MAX) { --=20 2.43.0