forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/security/integrity/ima/ima_fs.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2005,2006,2007,2008 IBM Corporation
34 *
....@@ -6,21 +7,15 @@
67 * Reiner Sailer <sailer@us.ibm.com>
78 * Mimi Zohar <zohar@us.ibm.com>
89 *
9
- * This program is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU General Public License as
11
- * published by the Free Software Foundation, version 2 of the
12
- * License.
13
- *
1410 * File: ima_fs.c
1511 * implemenents security file system for reporting
1612 * current measurement list and IMA statistics
1713 */
1814
19
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
-
2115 #include <linux/fcntl.h>
16
+#include <linux/kernel_read_file.h>
2217 #include <linux/slab.h>
23
-#include <linux/module.h>
18
+#include <linux/init.h>
2419 #include <linux/seq_file.h>
2520 #include <linux/rculist.h>
2621 #include <linux/rcupdate.h>
....@@ -156,7 +151,7 @@
156151 ima_putc(m, &pcr, sizeof(e->pcr));
157152
158153 /* 2nd: template digest */
159
- ima_putc(m, e->digest, TPM_DIGEST_SIZE);
154
+ ima_putc(m, e->digests[ima_sha1_idx].digest, TPM_DIGEST_SIZE);
160155
161156 /* 3rd: template name size */
162157 namelen = !ima_canonical_fmt ? strlen(template_name) :
....@@ -179,7 +174,8 @@
179174 /* 6th: template specific data */
180175 for (i = 0; i < e->template_desc->num_fields; i++) {
181176 enum ima_show_type show = IMA_SHOW_BINARY;
182
- struct ima_template_field *field = e->template_desc->fields[i];
177
+ const struct ima_template_field *field =
178
+ e->template_desc->fields[i];
183179
184180 if (is_ima_template && strcmp(field->field_id, "d") == 0)
185181 show = IMA_SHOW_BINARY_NO_FIELD_LEN;
....@@ -238,7 +234,7 @@
238234 seq_printf(m, "%2d ", e->pcr);
239235
240236 /* 2nd: SHA1 template hash */
241
- ima_print_digest(m, e->digest, TPM_DIGEST_SIZE);
237
+ ima_print_digest(m, e->digests[ima_sha1_idx].digest, TPM_DIGEST_SIZE);
242238
243239 /* 3th: template name */
244240 seq_printf(m, " %s", template_name);
....@@ -277,9 +273,9 @@
277273
278274 static ssize_t ima_read_policy(char *path)
279275 {
280
- void *data;
276
+ void *data = NULL;
281277 char *datap;
282
- loff_t size;
278
+ size_t size;
283279 int rc, pathlen = strlen(path);
284280
285281 char *p;
....@@ -288,11 +284,14 @@
288284 datap = path;
289285 strsep(&datap, "\n");
290286
291
- rc = kernel_read_file_from_path(path, &data, &size, 0, READING_POLICY);
287
+ rc = kernel_read_file_from_path(path, 0, &data, INT_MAX, NULL,
288
+ READING_POLICY);
292289 if (rc < 0) {
293290 pr_err("Unable to open file: %s (%d)", path, rc);
294291 return rc;
295292 }
293
+ size = rc;
294
+ rc = 0;
296295
297296 datap = data;
298297 while (size > 0 && (p = strsep(&datap, "\n"))) {