]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ima: Use snprintf() in create_securityfs_measurement_lists
authorRoberto Sassu <roberto.sassu@huawei.com>
Fri, 5 Jun 2026 17:22:31 +0000 (19:22 +0200)
committerMimi Zohar <zohar@linux.ibm.com>
Mon, 8 Jun 2026 15:43:11 +0000 (11:43 -0400)
Use the more secure snprintf() function (accepting the buffer size) in
create_securityfs_measurement_lists().

No functional change: sprintf() and snprintf() have the same behavior.

Link: https://github.com/linux-integrity/linux/issues/1
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
security/integrity/ima/ima_fs.c

index 91bd831d070f2331961af5c409a877dbe41e381c..f6ecee2d769962ce650d6895f5bbbf168367c55f 100644 (file)
@@ -503,11 +503,13 @@ static int __init create_securityfs_measurement_lists(void)
                struct dentry *dentry;
 
                if (algo == HASH_ALGO__LAST)
-                       sprintf(file_name, "ascii_runtime_measurements_tpm_alg_%x",
-                               ima_tpm_chip->allocated_banks[i].alg_id);
+                       snprintf(file_name, sizeof(file_name),
+                                "ascii_runtime_measurements_tpm_alg_%x",
+                                ima_tpm_chip->allocated_banks[i].alg_id);
                else
-                       sprintf(file_name, "ascii_runtime_measurements_%s",
-                               hash_algo_name[algo]);
+                       snprintf(file_name, sizeof(file_name),
+                                "ascii_runtime_measurements_%s",
+                                hash_algo_name[algo]);
                dentry = securityfs_create_file(file_name, S_IRUSR | S_IRGRP,
                                                ima_dir, (void *)(uintptr_t)i,
                                                &ima_ascii_measurements_ops);
@@ -515,11 +517,13 @@ static int __init create_securityfs_measurement_lists(void)
                        return PTR_ERR(dentry);
 
                if (algo == HASH_ALGO__LAST)
-                       sprintf(file_name, "binary_runtime_measurements_tpm_alg_%x",
-                               ima_tpm_chip->allocated_banks[i].alg_id);
+                       snprintf(file_name, sizeof(file_name),
+                                "binary_runtime_measurements_tpm_alg_%x",
+                                ima_tpm_chip->allocated_banks[i].alg_id);
                else
-                       sprintf(file_name, "binary_runtime_measurements_%s",
-                               hash_algo_name[algo]);
+                       snprintf(file_name, sizeof(file_name),
+                                "binary_runtime_measurements_%s",
+                                hash_algo_name[algo]);
                dentry = securityfs_create_file(file_name, S_IRUSR | S_IRGRP,
                                                ima_dir, (void *)(uintptr_t)i,
                                                &ima_measurements_ops);