.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2005,2006,2007,2008 IBM Corporation |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * Reiner Sailer <sailer@us.ibm.com> |
---|
7 | 8 | * Mimi Zohar <zohar@us.ibm.com> |
---|
8 | 9 | * |
---|
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 | | - * |
---|
14 | 10 | * File: ima_fs.c |
---|
15 | 11 | * implemenents security file system for reporting |
---|
16 | 12 | * current measurement list and IMA statistics |
---|
17 | 13 | */ |
---|
18 | 14 | |
---|
19 | | -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
20 | | - |
---|
21 | 15 | #include <linux/fcntl.h> |
---|
| 16 | +#include <linux/kernel_read_file.h> |
---|
22 | 17 | #include <linux/slab.h> |
---|
23 | | -#include <linux/module.h> |
---|
| 18 | +#include <linux/init.h> |
---|
24 | 19 | #include <linux/seq_file.h> |
---|
25 | 20 | #include <linux/rculist.h> |
---|
26 | 21 | #include <linux/rcupdate.h> |
---|
.. | .. |
---|
156 | 151 | ima_putc(m, &pcr, sizeof(e->pcr)); |
---|
157 | 152 | |
---|
158 | 153 | /* 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); |
---|
160 | 155 | |
---|
161 | 156 | /* 3rd: template name size */ |
---|
162 | 157 | namelen = !ima_canonical_fmt ? strlen(template_name) : |
---|
.. | .. |
---|
179 | 174 | /* 6th: template specific data */ |
---|
180 | 175 | for (i = 0; i < e->template_desc->num_fields; i++) { |
---|
181 | 176 | 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]; |
---|
183 | 179 | |
---|
184 | 180 | if (is_ima_template && strcmp(field->field_id, "d") == 0) |
---|
185 | 181 | show = IMA_SHOW_BINARY_NO_FIELD_LEN; |
---|
.. | .. |
---|
238 | 234 | seq_printf(m, "%2d ", e->pcr); |
---|
239 | 235 | |
---|
240 | 236 | /* 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); |
---|
242 | 238 | |
---|
243 | 239 | /* 3th: template name */ |
---|
244 | 240 | seq_printf(m, " %s", template_name); |
---|
.. | .. |
---|
277 | 273 | |
---|
278 | 274 | static ssize_t ima_read_policy(char *path) |
---|
279 | 275 | { |
---|
280 | | - void *data; |
---|
| 276 | + void *data = NULL; |
---|
281 | 277 | char *datap; |
---|
282 | | - loff_t size; |
---|
| 278 | + size_t size; |
---|
283 | 279 | int rc, pathlen = strlen(path); |
---|
284 | 280 | |
---|
285 | 281 | char *p; |
---|
.. | .. |
---|
288 | 284 | datap = path; |
---|
289 | 285 | strsep(&datap, "\n"); |
---|
290 | 286 | |
---|
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); |
---|
292 | 289 | if (rc < 0) { |
---|
293 | 290 | pr_err("Unable to open file: %s (%d)", path, rc); |
---|
294 | 291 | return rc; |
---|
295 | 292 | } |
---|
| 293 | + size = rc; |
---|
| 294 | + rc = 0; |
---|
296 | 295 | |
---|
297 | 296 | datap = data; |
---|
298 | 297 | while (size > 0 && (p = strsep(&datap, "\n"))) { |
---|