Thomas Gleixner | b886d83 | 2019-06-01 10:08:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2005-2010 IBM Corporation |
| 4 | * |
| 5 | * Author: |
| 6 | * Mimi Zohar <zohar@us.ibm.com> |
| 7 | * Kylene Hall <kjhall@us.ibm.com> |
| 8 | * |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 9 | * File: evm_main.c |
| 10 | * implements evm_inode_setxattr, evm_inode_post_setxattr, |
| 11 | * evm_inode_removexattr, and evm_verifyxattr |
| 12 | */ |
| 13 | |
Paul Gortmaker | 3aafb1f | 2018-12-09 15:36:32 -0500 | [diff] [blame] | 14 | #include <linux/init.h> |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 15 | #include <linux/crypto.h> |
Mimi Zohar | 9b97b6c | 2013-02-21 09:31:22 -0500 | [diff] [blame] | 16 | #include <linux/audit.h> |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 17 | #include <linux/xattr.h> |
| 18 | #include <linux/integrity.h> |
Mimi Zohar | 3e1be52 | 2011-03-09 14:38:26 -0500 | [diff] [blame] | 19 | #include <linux/evm.h> |
Ingo Molnar | 50d3439 | 2017-02-05 16:03:58 +0100 | [diff] [blame] | 20 | #include <linux/magic.h> |
| 21 | |
Dmitry Kasatkin | d46eb36 | 2011-03-09 15:07:36 -0500 | [diff] [blame] | 22 | #include <crypto/hash.h> |
Matthew Garrett | 5feeb61 | 2018-06-08 14:57:43 -0700 | [diff] [blame] | 23 | #include <crypto/hash_info.h> |
Ryan Ware | 613317b | 2016-02-11 15:58:44 -0800 | [diff] [blame] | 24 | #include <crypto/algapi.h> |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 25 | #include "evm.h" |
| 26 | |
| 27 | int evm_initialized; |
| 28 | |
HernĂ¡n Gonzalez | 17d7b0a | 2018-02-27 19:17:00 -0300 | [diff] [blame] | 29 | static const char * const integrity_status_msg[] = { |
Matthew Garrett | 50b9774 | 2017-11-07 07:17:42 -0800 | [diff] [blame] | 30 | "pass", "pass_immutable", "fail", "no_label", "no_xattrs", "unknown" |
Mimi Zohar | 9b97b6c | 2013-02-21 09:31:22 -0500 | [diff] [blame] | 31 | }; |
Dmitry Kasatkin | d3b3367 | 2014-03-28 14:31:04 +0200 | [diff] [blame] | 32 | int evm_hmac_attrs; |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 33 | |
Matthew Garrett | fa516b6 | 2018-05-15 10:38:26 -0700 | [diff] [blame] | 34 | static struct xattr_list evm_config_default_xattrnames[] = { |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 35 | #ifdef CONFIG_SECURITY_SELINUX |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 36 | {.name = XATTR_NAME_SELINUX}, |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 37 | #endif |
| 38 | #ifdef CONFIG_SECURITY_SMACK |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 39 | {.name = XATTR_NAME_SMACK}, |
Dmitry Kasatkin | 3e38df5 | 2014-03-28 14:31:14 +0200 | [diff] [blame] | 40 | #ifdef CONFIG_EVM_EXTRA_SMACK_XATTRS |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 41 | {.name = XATTR_NAME_SMACKEXEC}, |
| 42 | {.name = XATTR_NAME_SMACKTRANSMUTE}, |
| 43 | {.name = XATTR_NAME_SMACKMMAP}, |
Dmitry Kasatkin | 3e38df5 | 2014-03-28 14:31:14 +0200 | [diff] [blame] | 44 | #endif |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 45 | #endif |
Matthew Garrett | 096b854 | 2017-10-13 15:09:25 -0700 | [diff] [blame] | 46 | #ifdef CONFIG_SECURITY_APPARMOR |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 47 | {.name = XATTR_NAME_APPARMOR}, |
Matthew Garrett | 096b854 | 2017-10-13 15:09:25 -0700 | [diff] [blame] | 48 | #endif |
Mimi Zohar | 2fe5d6d | 2012-02-13 10:15:05 -0500 | [diff] [blame] | 49 | #ifdef CONFIG_IMA_APPRAISE |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 50 | {.name = XATTR_NAME_IMA}, |
Mimi Zohar | 2fe5d6d | 2012-02-13 10:15:05 -0500 | [diff] [blame] | 51 | #endif |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 52 | {.name = XATTR_NAME_CAPS}, |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 53 | }; |
| 54 | |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 55 | LIST_HEAD(evm_config_xattrnames); |
| 56 | |
Austin Kim | c7400e2 | 2021-10-28 12:26:42 +0100 | [diff] [blame] | 57 | static int evm_fixmode __ro_after_init; |
Mimi Zohar | 7102ebc | 2011-05-12 18:33:20 -0400 | [diff] [blame] | 58 | static int __init evm_set_fixmode(char *str) |
| 59 | { |
| 60 | if (strncmp(str, "fix", 3) == 0) |
| 61 | evm_fixmode = 1; |
Bruno Meneguele | 7fe2bb7 | 2020-09-04 16:40:58 -0300 | [diff] [blame] | 62 | else |
| 63 | pr_err("invalid \"%s\" mode", str); |
| 64 | |
Mimi Zohar | 7102ebc | 2011-05-12 18:33:20 -0400 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | __setup("evm=", evm_set_fixmode); |
| 68 | |
Dmitry Kasatkin | d3b3367 | 2014-03-28 14:31:04 +0200 | [diff] [blame] | 69 | static void __init evm_init_config(void) |
| 70 | { |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 71 | int i, xattrs; |
| 72 | |
| 73 | xattrs = ARRAY_SIZE(evm_config_default_xattrnames); |
| 74 | |
| 75 | pr_info("Initialising EVM extended attributes:\n"); |
| 76 | for (i = 0; i < xattrs; i++) { |
| 77 | pr_info("%s\n", evm_config_default_xattrnames[i].name); |
| 78 | list_add_tail(&evm_config_default_xattrnames[i].list, |
| 79 | &evm_config_xattrnames); |
| 80 | } |
| 81 | |
Dmitry Kasatkin | d3b3367 | 2014-03-28 14:31:04 +0200 | [diff] [blame] | 82 | #ifdef CONFIG_EVM_ATTR_FSUUID |
| 83 | evm_hmac_attrs |= EVM_ATTR_FSUUID; |
| 84 | #endif |
| 85 | pr_info("HMAC attrs: 0x%x\n", evm_hmac_attrs); |
| 86 | } |
| 87 | |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 88 | static bool evm_key_loaded(void) |
| 89 | { |
| 90 | return (bool)(evm_initialized & EVM_KEY_MASK); |
| 91 | } |
| 92 | |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 93 | static int evm_find_protected_xattrs(struct dentry *dentry) |
| 94 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 95 | struct inode *inode = d_backing_inode(dentry); |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 96 | struct xattr_list *xattr; |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 97 | int error; |
| 98 | int count = 0; |
| 99 | |
Andreas Gruenbacher | 5d6c319 | 2016-09-29 17:48:42 +0200 | [diff] [blame] | 100 | if (!(inode->i_opflags & IOP_XATTR)) |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 101 | return -EOPNOTSUPP; |
| 102 | |
Madhuparna Bhowmik | 770f605 | 2020-04-30 21:32:05 +0530 | [diff] [blame] | 103 | list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) { |
Mark Salyzyn | 3484eba | 2019-11-04 08:57:10 -0800 | [diff] [blame] | 104 | error = __vfs_getxattr(dentry, inode, xattr->name, NULL, 0, |
| 105 | XATTR_NOSECURITY); |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 106 | if (error < 0) { |
| 107 | if (error == -ENODATA) |
| 108 | continue; |
| 109 | return error; |
| 110 | } |
| 111 | count++; |
| 112 | } |
| 113 | |
| 114 | return count; |
| 115 | } |
| 116 | |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 117 | /* |
| 118 | * evm_verify_hmac - calculate and compare the HMAC with the EVM xattr |
| 119 | * |
| 120 | * Compute the HMAC on the dentry's protected set of extended attributes |
Mimi Zohar | 7102ebc | 2011-05-12 18:33:20 -0400 | [diff] [blame] | 121 | * and compare it against the stored security.evm xattr. |
| 122 | * |
| 123 | * For performance: |
| 124 | * - use the previoulsy retrieved xattr value and length to calculate the |
| 125 | * HMAC.) |
| 126 | * - cache the verification result in the iint, when available. |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 127 | * |
| 128 | * Returns integrity status |
| 129 | */ |
| 130 | static enum integrity_status evm_verify_hmac(struct dentry *dentry, |
| 131 | const char *xattr_name, |
| 132 | char *xattr_value, |
| 133 | size_t xattr_value_len, |
| 134 | struct integrity_iint_cache *iint) |
| 135 | { |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 136 | struct evm_ima_xattr_data *xattr_data = NULL; |
Matthew Garrett | 5feeb61 | 2018-06-08 14:57:43 -0700 | [diff] [blame] | 137 | struct signature_v2_hdr *hdr; |
Mimi Zohar | 566be59 | 2011-08-22 09:14:18 -0400 | [diff] [blame] | 138 | enum integrity_status evm_status = INTEGRITY_PASS; |
Matthew Garrett | 5feeb61 | 2018-06-08 14:57:43 -0700 | [diff] [blame] | 139 | struct evm_digest digest; |
Sascha Hauer | 70946c4a | 2018-03-01 13:38:45 +0100 | [diff] [blame] | 140 | struct inode *inode; |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 141 | int rc, xattr_len; |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 142 | |
Matthew Garrett | 50b9774 | 2017-11-07 07:17:42 -0800 | [diff] [blame] | 143 | if (iint && (iint->evm_status == INTEGRITY_PASS || |
| 144 | iint->evm_status == INTEGRITY_PASS_IMMUTABLE)) |
Dmitry Kasatkin | 24e0198 | 2011-05-06 11:34:17 +0300 | [diff] [blame] | 145 | return iint->evm_status; |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 146 | |
Dmitry Kasatkin | 6d38ca01 | 2011-05-06 11:34:14 +0300 | [diff] [blame] | 147 | /* if status is not PASS, try to check again - against -ENOMEM */ |
| 148 | |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 149 | /* first need to know the sig type */ |
| 150 | rc = vfs_getxattr_alloc(dentry, XATTR_NAME_EVM, (char **)&xattr_data, 0, |
| 151 | GFP_NOFS); |
| 152 | if (rc <= 0) { |
Dmitry Kasatkin | 1f10097 | 2014-08-15 13:49:22 +0300 | [diff] [blame] | 153 | evm_status = INTEGRITY_FAIL; |
| 154 | if (rc == -ENODATA) { |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 155 | rc = evm_find_protected_xattrs(dentry); |
| 156 | if (rc > 0) |
| 157 | evm_status = INTEGRITY_NOLABEL; |
| 158 | else if (rc == 0) |
| 159 | evm_status = INTEGRITY_NOXATTRS; /* new file */ |
Dmitry Kasatkin | 1f10097 | 2014-08-15 13:49:22 +0300 | [diff] [blame] | 160 | } else if (rc == -EOPNOTSUPP) { |
| 161 | evm_status = INTEGRITY_UNKNOWN; |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 162 | } |
Mimi Zohar | 566be59 | 2011-08-22 09:14:18 -0400 | [diff] [blame] | 163 | goto out; |
| 164 | } |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 165 | |
Dmitry Kasatkin | b1aaab2 | 2013-10-10 16:12:03 +0900 | [diff] [blame] | 166 | xattr_len = rc; |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 167 | |
| 168 | /* check value type */ |
| 169 | switch (xattr_data->type) { |
| 170 | case EVM_XATTR_HMAC: |
Thiago Jung Bauermann | 650b29d | 2019-06-11 03:28:08 -0300 | [diff] [blame] | 171 | if (xattr_len != sizeof(struct evm_xattr)) { |
Seth Forshee | b4bfec7 | 2016-08-01 08:19:10 -0500 | [diff] [blame] | 172 | evm_status = INTEGRITY_FAIL; |
| 173 | goto out; |
| 174 | } |
Matthew Garrett | 5feeb61 | 2018-06-08 14:57:43 -0700 | [diff] [blame] | 175 | |
| 176 | digest.hdr.algo = HASH_ALGO_SHA1; |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 177 | rc = evm_calc_hmac(dentry, xattr_name, xattr_value, |
Matthew Garrett | 5feeb61 | 2018-06-08 14:57:43 -0700 | [diff] [blame] | 178 | xattr_value_len, &digest); |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 179 | if (rc) |
| 180 | break; |
Thiago Jung Bauermann | 650b29d | 2019-06-11 03:28:08 -0300 | [diff] [blame] | 181 | rc = crypto_memneq(xattr_data->data, digest.digest, |
Matthew Garrett | 5feeb61 | 2018-06-08 14:57:43 -0700 | [diff] [blame] | 182 | SHA1_DIGEST_SIZE); |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 183 | if (rc) |
| 184 | rc = -EINVAL; |
| 185 | break; |
| 186 | case EVM_IMA_XATTR_DIGSIG: |
Matthew Garrett | 50b9774 | 2017-11-07 07:17:42 -0800 | [diff] [blame] | 187 | case EVM_XATTR_PORTABLE_DIGSIG: |
Roberto Sassu | 455b6c9 | 2020-09-04 11:23:30 +0200 | [diff] [blame] | 188 | /* accept xattr with non-empty signature field */ |
| 189 | if (xattr_len <= sizeof(struct signature_v2_hdr)) { |
| 190 | evm_status = INTEGRITY_FAIL; |
| 191 | goto out; |
| 192 | } |
| 193 | |
Matthew Garrett | 5feeb61 | 2018-06-08 14:57:43 -0700 | [diff] [blame] | 194 | hdr = (struct signature_v2_hdr *)xattr_data; |
| 195 | digest.hdr.algo = hdr->hash_algo; |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 196 | rc = evm_calc_hash(dentry, xattr_name, xattr_value, |
Matthew Garrett | 5feeb61 | 2018-06-08 14:57:43 -0700 | [diff] [blame] | 197 | xattr_value_len, xattr_data->type, &digest); |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 198 | if (rc) |
| 199 | break; |
| 200 | rc = integrity_digsig_verify(INTEGRITY_KEYRING_EVM, |
Dmitry Kasatkin | b1aaab2 | 2013-10-10 16:12:03 +0900 | [diff] [blame] | 201 | (const char *)xattr_data, xattr_len, |
Matthew Garrett | 5feeb61 | 2018-06-08 14:57:43 -0700 | [diff] [blame] | 202 | digest.digest, digest.hdr.length); |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 203 | if (!rc) { |
Sascha Hauer | 70946c4a | 2018-03-01 13:38:45 +0100 | [diff] [blame] | 204 | inode = d_backing_inode(dentry); |
| 205 | |
Matthew Garrett | 50b9774 | 2017-11-07 07:17:42 -0800 | [diff] [blame] | 206 | if (xattr_data->type == EVM_XATTR_PORTABLE_DIGSIG) { |
| 207 | if (iint) |
| 208 | iint->flags |= EVM_IMMUTABLE_DIGSIG; |
| 209 | evm_status = INTEGRITY_PASS_IMMUTABLE; |
Sascha Hauer | 70946c4a | 2018-03-01 13:38:45 +0100 | [diff] [blame] | 210 | } else if (!IS_RDONLY(inode) && |
| 211 | !(inode->i_sb->s_readonly_remount) && |
| 212 | !IS_IMMUTABLE(inode)) { |
Dmitry Kasatkin | c2baec7 | 2014-10-01 21:43:08 +0300 | [diff] [blame] | 213 | evm_update_evmxattr(dentry, xattr_name, |
| 214 | xattr_value, |
| 215 | xattr_value_len); |
Matthew Garrett | 50b9774 | 2017-11-07 07:17:42 -0800 | [diff] [blame] | 216 | } |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 217 | } |
| 218 | break; |
| 219 | default: |
| 220 | rc = -EINVAL; |
| 221 | break; |
| 222 | } |
| 223 | |
| 224 | if (rc) |
| 225 | evm_status = (rc == -ENODATA) ? |
| 226 | INTEGRITY_NOXATTRS : INTEGRITY_FAIL; |
Mimi Zohar | 7102ebc | 2011-05-12 18:33:20 -0400 | [diff] [blame] | 227 | out: |
| 228 | if (iint) |
| 229 | iint->evm_status = evm_status; |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 230 | kfree(xattr_data); |
Mimi Zohar | 7102ebc | 2011-05-12 18:33:20 -0400 | [diff] [blame] | 231 | return evm_status; |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static int evm_protected_xattr(const char *req_xattr_name) |
| 235 | { |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 236 | int namelen; |
| 237 | int found = 0; |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 238 | struct xattr_list *xattr; |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 239 | |
| 240 | namelen = strlen(req_xattr_name); |
Madhuparna Bhowmik | 770f605 | 2020-04-30 21:32:05 +0530 | [diff] [blame] | 241 | list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) { |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 242 | if ((strlen(xattr->name) == namelen) |
| 243 | && (strncmp(req_xattr_name, xattr->name, namelen) == 0)) { |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 244 | found = 1; |
| 245 | break; |
| 246 | } |
Mimi Zohar | cb723180 | 2011-03-09 14:40:44 -0500 | [diff] [blame] | 247 | if (strncmp(req_xattr_name, |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 248 | xattr->name + XATTR_SECURITY_PREFIX_LEN, |
Mimi Zohar | cb723180 | 2011-03-09 14:40:44 -0500 | [diff] [blame] | 249 | strlen(req_xattr_name)) == 0) { |
| 250 | found = 1; |
| 251 | break; |
| 252 | } |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 253 | } |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 254 | |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 255 | return found; |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * evm_verifyxattr - verify the integrity of the requested xattr |
| 260 | * @dentry: object of the verify xattr |
| 261 | * @xattr_name: requested xattr |
| 262 | * @xattr_value: requested xattr value |
| 263 | * @xattr_value_len: requested xattr value length |
| 264 | * |
| 265 | * Calculate the HMAC for the given dentry and verify it against the stored |
| 266 | * security.evm xattr. For performance, use the xattr value and length |
| 267 | * previously retrieved to calculate the HMAC. |
| 268 | * |
| 269 | * Returns the xattr integrity status. |
| 270 | * |
| 271 | * This function requires the caller to lock the inode's i_mutex before it |
| 272 | * is executed. |
| 273 | */ |
| 274 | enum integrity_status evm_verifyxattr(struct dentry *dentry, |
| 275 | const char *xattr_name, |
Dmitry Kasatkin | 2960e6c | 2011-05-06 11:34:13 +0300 | [diff] [blame] | 276 | void *xattr_value, size_t xattr_value_len, |
| 277 | struct integrity_iint_cache *iint) |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 278 | { |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 279 | if (!evm_key_loaded() || !evm_protected_xattr(xattr_name)) |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 280 | return INTEGRITY_UNKNOWN; |
| 281 | |
Dmitry Kasatkin | 2960e6c | 2011-05-06 11:34:13 +0300 | [diff] [blame] | 282 | if (!iint) { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 283 | iint = integrity_iint_find(d_backing_inode(dentry)); |
Dmitry Kasatkin | 2960e6c | 2011-05-06 11:34:13 +0300 | [diff] [blame] | 284 | if (!iint) |
| 285 | return INTEGRITY_UNKNOWN; |
| 286 | } |
| 287 | return evm_verify_hmac(dentry, xattr_name, xattr_value, |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 288 | xattr_value_len, iint); |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 289 | } |
| 290 | EXPORT_SYMBOL_GPL(evm_verifyxattr); |
| 291 | |
| 292 | /* |
Mimi Zohar | 7102ebc | 2011-05-12 18:33:20 -0400 | [diff] [blame] | 293 | * evm_verify_current_integrity - verify the dentry's metadata integrity |
| 294 | * @dentry: pointer to the affected dentry |
| 295 | * |
| 296 | * Verify and return the dentry's metadata integrity. The exceptions are |
| 297 | * before EVM is initialized or in 'fix' mode. |
| 298 | */ |
| 299 | static enum integrity_status evm_verify_current_integrity(struct dentry *dentry) |
| 300 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 301 | struct inode *inode = d_backing_inode(dentry); |
Mimi Zohar | 7102ebc | 2011-05-12 18:33:20 -0400 | [diff] [blame] | 302 | |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 303 | if (!evm_key_loaded() || !S_ISREG(inode->i_mode) || evm_fixmode) |
Mimi Zohar | 7102ebc | 2011-05-12 18:33:20 -0400 | [diff] [blame] | 304 | return 0; |
| 305 | return evm_verify_hmac(dentry, NULL, NULL, 0, NULL); |
| 306 | } |
| 307 | |
Mimi Zohar | a924ce0 | 2011-08-11 01:22:30 -0400 | [diff] [blame] | 308 | /* |
| 309 | * evm_protect_xattr - protect the EVM extended attribute |
| 310 | * |
Mimi Zohar | bf6d0f5 | 2011-08-18 18:07:44 -0400 | [diff] [blame] | 311 | * Prevent security.evm from being modified or removed without the |
| 312 | * necessary permissions or when the existing value is invalid. |
| 313 | * |
| 314 | * The posix xattr acls are 'system' prefixed, which normally would not |
| 315 | * affect security.evm. An interesting side affect of writing posix xattr |
| 316 | * acls is their modifying of the i_mode, which is included in security.evm. |
| 317 | * For posix xattr acls only, permit security.evm, even if it currently |
Matthew Garrett | 50b9774 | 2017-11-07 07:17:42 -0800 | [diff] [blame] | 318 | * doesn't exist, to be updated unless the EVM signature is immutable. |
Mimi Zohar | a924ce0 | 2011-08-11 01:22:30 -0400 | [diff] [blame] | 319 | */ |
| 320 | static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name, |
| 321 | const void *xattr_value, size_t xattr_value_len) |
| 322 | { |
| 323 | enum integrity_status evm_status; |
| 324 | |
| 325 | if (strcmp(xattr_name, XATTR_NAME_EVM) == 0) { |
| 326 | if (!capable(CAP_SYS_ADMIN)) |
| 327 | return -EPERM; |
Mimi Zohar | bf6d0f5 | 2011-08-18 18:07:44 -0400 | [diff] [blame] | 328 | } else if (!evm_protected_xattr(xattr_name)) { |
| 329 | if (!posix_xattr_acl(xattr_name)) |
| 330 | return 0; |
| 331 | evm_status = evm_verify_current_integrity(dentry); |
| 332 | if ((evm_status == INTEGRITY_PASS) || |
Mimi Zohar | 566be59 | 2011-08-22 09:14:18 -0400 | [diff] [blame] | 333 | (evm_status == INTEGRITY_NOXATTRS)) |
Mimi Zohar | bf6d0f5 | 2011-08-18 18:07:44 -0400 | [diff] [blame] | 334 | return 0; |
Mimi Zohar | 9b97b6c | 2013-02-21 09:31:22 -0500 | [diff] [blame] | 335 | goto out; |
Mimi Zohar | bf6d0f5 | 2011-08-18 18:07:44 -0400 | [diff] [blame] | 336 | } |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 337 | |
Mimi Zohar | a924ce0 | 2011-08-11 01:22:30 -0400 | [diff] [blame] | 338 | evm_status = evm_verify_current_integrity(dentry); |
Dmitry Kasatkin | 3dcbad5 | 2014-09-02 16:31:43 +0300 | [diff] [blame] | 339 | if (evm_status == INTEGRITY_NOXATTRS) { |
| 340 | struct integrity_iint_cache *iint; |
| 341 | |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 342 | iint = integrity_iint_find(d_backing_inode(dentry)); |
Dmitry Kasatkin | 3dcbad5 | 2014-09-02 16:31:43 +0300 | [diff] [blame] | 343 | if (iint && (iint->flags & IMA_NEW_FILE)) |
| 344 | return 0; |
Mimi Zohar | 5101a18 | 2015-04-21 13:59:31 -0400 | [diff] [blame] | 345 | |
| 346 | /* exception for pseudo filesystems */ |
Al Viro | fc64005 | 2016-04-10 01:33:30 -0400 | [diff] [blame] | 347 | if (dentry->d_sb->s_magic == TMPFS_MAGIC |
| 348 | || dentry->d_sb->s_magic == SYSFS_MAGIC) |
Mimi Zohar | 5101a18 | 2015-04-21 13:59:31 -0400 | [diff] [blame] | 349 | return 0; |
| 350 | |
| 351 | integrity_audit_msg(AUDIT_INTEGRITY_METADATA, |
| 352 | dentry->d_inode, dentry->d_name.name, |
| 353 | "update_metadata", |
| 354 | integrity_status_msg[evm_status], |
| 355 | -EPERM, 0); |
Dmitry Kasatkin | 3dcbad5 | 2014-09-02 16:31:43 +0300 | [diff] [blame] | 356 | } |
Mimi Zohar | 9b97b6c | 2013-02-21 09:31:22 -0500 | [diff] [blame] | 357 | out: |
| 358 | if (evm_status != INTEGRITY_PASS) |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 359 | integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry), |
Mimi Zohar | 9b97b6c | 2013-02-21 09:31:22 -0500 | [diff] [blame] | 360 | dentry->d_name.name, "appraise_metadata", |
| 361 | integrity_status_msg[evm_status], |
| 362 | -EPERM, 0); |
Mimi Zohar | a924ce0 | 2011-08-11 01:22:30 -0400 | [diff] [blame] | 363 | return evm_status == INTEGRITY_PASS ? 0 : -EPERM; |
| 364 | } |
| 365 | |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 366 | /** |
| 367 | * evm_inode_setxattr - protect the EVM extended attribute |
| 368 | * @dentry: pointer to the affected dentry |
| 369 | * @xattr_name: pointer to the affected extended attribute name |
| 370 | * @xattr_value: pointer to the new extended attribute value |
| 371 | * @xattr_value_len: pointer to the new extended attribute value length |
| 372 | * |
Mimi Zohar | 2fb1c9a | 2014-05-11 00:05:23 -0400 | [diff] [blame] | 373 | * Before allowing the 'security.evm' protected xattr to be updated, |
| 374 | * verify the existing value is valid. As only the kernel should have |
| 375 | * access to the EVM encrypted key needed to calculate the HMAC, prevent |
| 376 | * userspace from writing HMAC value. Writing 'security.evm' requires |
| 377 | * requires CAP_SYS_ADMIN privileges. |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 378 | */ |
| 379 | int evm_inode_setxattr(struct dentry *dentry, const char *xattr_name, |
| 380 | const void *xattr_value, size_t xattr_value_len) |
| 381 | { |
Mimi Zohar | 2fb1c9a | 2014-05-11 00:05:23 -0400 | [diff] [blame] | 382 | const struct evm_ima_xattr_data *xattr_data = xattr_value; |
| 383 | |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 384 | /* Policy permits modification of the protected xattrs even though |
| 385 | * there's no HMAC key loaded |
| 386 | */ |
| 387 | if (evm_initialized & EVM_ALLOW_METADATA_WRITES) |
| 388 | return 0; |
| 389 | |
Dmitry Kasatkin | 3b1deef | 2014-10-28 14:28:49 +0200 | [diff] [blame] | 390 | if (strcmp(xattr_name, XATTR_NAME_EVM) == 0) { |
| 391 | if (!xattr_value_len) |
| 392 | return -EINVAL; |
Matthew Garrett | 50b9774 | 2017-11-07 07:17:42 -0800 | [diff] [blame] | 393 | if (xattr_data->type != EVM_IMA_XATTR_DIGSIG && |
| 394 | xattr_data->type != EVM_XATTR_PORTABLE_DIGSIG) |
Dmitry Kasatkin | 3b1deef | 2014-10-28 14:28:49 +0200 | [diff] [blame] | 395 | return -EPERM; |
| 396 | } |
Mimi Zohar | a924ce0 | 2011-08-11 01:22:30 -0400 | [diff] [blame] | 397 | return evm_protect_xattr(dentry, xattr_name, xattr_value, |
| 398 | xattr_value_len); |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /** |
| 402 | * evm_inode_removexattr - protect the EVM extended attribute |
| 403 | * @dentry: pointer to the affected dentry |
| 404 | * @xattr_name: pointer to the affected extended attribute name |
| 405 | * |
Mimi Zohar | 7102ebc | 2011-05-12 18:33:20 -0400 | [diff] [blame] | 406 | * Removing 'security.evm' requires CAP_SYS_ADMIN privileges and that |
| 407 | * the current value is valid. |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 408 | */ |
| 409 | int evm_inode_removexattr(struct dentry *dentry, const char *xattr_name) |
| 410 | { |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 411 | /* Policy permits modification of the protected xattrs even though |
| 412 | * there's no HMAC key loaded |
| 413 | */ |
| 414 | if (evm_initialized & EVM_ALLOW_METADATA_WRITES) |
| 415 | return 0; |
| 416 | |
Mimi Zohar | a924ce0 | 2011-08-11 01:22:30 -0400 | [diff] [blame] | 417 | return evm_protect_xattr(dentry, xattr_name, NULL, 0); |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 418 | } |
| 419 | |
Dmitry Kasatkin | 523b74b | 2015-10-22 21:26:42 +0300 | [diff] [blame] | 420 | static void evm_reset_status(struct inode *inode) |
| 421 | { |
| 422 | struct integrity_iint_cache *iint; |
| 423 | |
| 424 | iint = integrity_iint_find(inode); |
| 425 | if (iint) |
| 426 | iint->evm_status = INTEGRITY_UNKNOWN; |
| 427 | } |
| 428 | |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 429 | /** |
| 430 | * evm_inode_post_setxattr - update 'security.evm' to reflect the changes |
| 431 | * @dentry: pointer to the affected dentry |
| 432 | * @xattr_name: pointer to the affected extended attribute name |
| 433 | * @xattr_value: pointer to the new extended attribute value |
| 434 | * @xattr_value_len: pointer to the new extended attribute value length |
| 435 | * |
| 436 | * Update the HMAC stored in 'security.evm' to reflect the change. |
| 437 | * |
| 438 | * No need to take the i_mutex lock here, as this function is called from |
| 439 | * __vfs_setxattr_noperm(). The caller of which has taken the inode's |
| 440 | * i_mutex lock. |
| 441 | */ |
| 442 | void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name, |
| 443 | const void *xattr_value, size_t xattr_value_len) |
| 444 | { |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 445 | if (!evm_key_loaded() || (!evm_protected_xattr(xattr_name) |
| 446 | && !posix_xattr_acl(xattr_name))) |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 447 | return; |
| 448 | |
Dmitry Kasatkin | 523b74b | 2015-10-22 21:26:42 +0300 | [diff] [blame] | 449 | evm_reset_status(dentry->d_inode); |
| 450 | |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 451 | evm_update_evmxattr(dentry, xattr_name, xattr_value, xattr_value_len); |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /** |
| 455 | * evm_inode_post_removexattr - update 'security.evm' after removing the xattr |
| 456 | * @dentry: pointer to the affected dentry |
| 457 | * @xattr_name: pointer to the affected extended attribute name |
| 458 | * |
| 459 | * Update the HMAC stored in 'security.evm' to reflect removal of the xattr. |
Dmitry Kasatkin | 7c51bb00 | 2014-11-20 16:31:01 +0200 | [diff] [blame] | 460 | * |
| 461 | * No need to take the i_mutex lock here, as this function is called from |
| 462 | * vfs_removexattr() which takes the i_mutex. |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 463 | */ |
| 464 | void evm_inode_post_removexattr(struct dentry *dentry, const char *xattr_name) |
| 465 | { |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 466 | if (!evm_key_loaded() || !evm_protected_xattr(xattr_name)) |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 467 | return; |
| 468 | |
Dmitry Kasatkin | 523b74b | 2015-10-22 21:26:42 +0300 | [diff] [blame] | 469 | evm_reset_status(dentry->d_inode); |
| 470 | |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 471 | evm_update_evmxattr(dentry, xattr_name, NULL, 0); |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
Mimi Zohar | 817b54a | 2011-05-13 12:53:38 -0400 | [diff] [blame] | 475 | * evm_inode_setattr - prevent updating an invalid EVM extended attribute |
| 476 | * @dentry: pointer to the affected dentry |
Matthew Garrett | 50b9774 | 2017-11-07 07:17:42 -0800 | [diff] [blame] | 477 | * |
| 478 | * Permit update of file attributes when files have a valid EVM signature, |
| 479 | * except in the case of them having an immutable portable signature. |
Mimi Zohar | 817b54a | 2011-05-13 12:53:38 -0400 | [diff] [blame] | 480 | */ |
| 481 | int evm_inode_setattr(struct dentry *dentry, struct iattr *attr) |
| 482 | { |
| 483 | unsigned int ia_valid = attr->ia_valid; |
| 484 | enum integrity_status evm_status; |
| 485 | |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 486 | /* Policy permits modification of the protected attrs even though |
| 487 | * there's no HMAC key loaded |
| 488 | */ |
| 489 | if (evm_initialized & EVM_ALLOW_METADATA_WRITES) |
| 490 | return 0; |
| 491 | |
Mimi Zohar | a924ce0 | 2011-08-11 01:22:30 -0400 | [diff] [blame] | 492 | if (!(ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID))) |
Mimi Zohar | 817b54a | 2011-05-13 12:53:38 -0400 | [diff] [blame] | 493 | return 0; |
| 494 | evm_status = evm_verify_current_integrity(dentry); |
Mimi Zohar | 566be59 | 2011-08-22 09:14:18 -0400 | [diff] [blame] | 495 | if ((evm_status == INTEGRITY_PASS) || |
| 496 | (evm_status == INTEGRITY_NOXATTRS)) |
| 497 | return 0; |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 498 | integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry), |
Mimi Zohar | 9b97b6c | 2013-02-21 09:31:22 -0500 | [diff] [blame] | 499 | dentry->d_name.name, "appraise_metadata", |
| 500 | integrity_status_msg[evm_status], -EPERM, 0); |
Mimi Zohar | 566be59 | 2011-08-22 09:14:18 -0400 | [diff] [blame] | 501 | return -EPERM; |
Mimi Zohar | 817b54a | 2011-05-13 12:53:38 -0400 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 505 | * evm_inode_post_setattr - update 'security.evm' after modifying metadata |
| 506 | * @dentry: pointer to the affected dentry |
| 507 | * @ia_valid: for the UID and GID status |
| 508 | * |
| 509 | * For now, update the HMAC stored in 'security.evm' to reflect UID/GID |
| 510 | * changes. |
| 511 | * |
| 512 | * This function is called from notify_change(), which expects the caller |
| 513 | * to lock the inode's i_mutex. |
| 514 | */ |
| 515 | void evm_inode_post_setattr(struct dentry *dentry, int ia_valid) |
| 516 | { |
Matthew Garrett | ae1ba16 | 2017-11-07 07:18:35 -0800 | [diff] [blame] | 517 | if (!evm_key_loaded()) |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 518 | return; |
| 519 | |
| 520 | if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)) |
| 521 | evm_update_evmxattr(dentry, NULL, NULL, 0); |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 522 | } |
| 523 | |
Mimi Zohar | cb723180 | 2011-03-09 14:40:44 -0500 | [diff] [blame] | 524 | /* |
Roberto Sassu | 7b84c7d | 2021-05-14 17:27:42 +0200 | [diff] [blame] | 525 | * evm_inode_init_security - initializes security.evm HMAC value |
Mimi Zohar | cb723180 | 2011-03-09 14:40:44 -0500 | [diff] [blame] | 526 | */ |
| 527 | int evm_inode_init_security(struct inode *inode, |
| 528 | const struct xattr *lsm_xattr, |
| 529 | struct xattr *evm_xattr) |
| 530 | { |
Thiago Jung Bauermann | 650b29d | 2019-06-11 03:28:08 -0300 | [diff] [blame] | 531 | struct evm_xattr *xattr_data; |
Mimi Zohar | cb723180 | 2011-03-09 14:40:44 -0500 | [diff] [blame] | 532 | int rc; |
| 533 | |
Roberto Sassu | 7b84c7d | 2021-05-14 17:27:42 +0200 | [diff] [blame] | 534 | if (!(evm_initialized & EVM_INIT_HMAC) || |
| 535 | !evm_protected_xattr(lsm_xattr->name)) |
Mimi Zohar | 5a4730b | 2011-08-11 00:22:52 -0400 | [diff] [blame] | 536 | return 0; |
Mimi Zohar | cb723180 | 2011-03-09 14:40:44 -0500 | [diff] [blame] | 537 | |
| 538 | xattr_data = kzalloc(sizeof(*xattr_data), GFP_NOFS); |
| 539 | if (!xattr_data) |
| 540 | return -ENOMEM; |
| 541 | |
Thiago Jung Bauermann | 650b29d | 2019-06-11 03:28:08 -0300 | [diff] [blame] | 542 | xattr_data->data.type = EVM_XATTR_HMAC; |
Mimi Zohar | cb723180 | 2011-03-09 14:40:44 -0500 | [diff] [blame] | 543 | rc = evm_init_hmac(inode, lsm_xattr, xattr_data->digest); |
| 544 | if (rc < 0) |
| 545 | goto out; |
| 546 | |
| 547 | evm_xattr->value = xattr_data; |
| 548 | evm_xattr->value_len = sizeof(*xattr_data); |
Tetsuo Handa | 9548906 | 2013-07-25 05:44:02 +0900 | [diff] [blame] | 549 | evm_xattr->name = XATTR_EVM_SUFFIX; |
Mimi Zohar | cb723180 | 2011-03-09 14:40:44 -0500 | [diff] [blame] | 550 | return 0; |
| 551 | out: |
| 552 | kfree(xattr_data); |
| 553 | return rc; |
| 554 | } |
| 555 | EXPORT_SYMBOL_GPL(evm_inode_init_security); |
| 556 | |
Dmitry Kasatkin | 2ce523e | 2015-10-22 21:26:21 +0300 | [diff] [blame] | 557 | #ifdef CONFIG_EVM_LOAD_X509 |
| 558 | void __init evm_load_x509(void) |
| 559 | { |
Dmitry Kasatkin | 26ddabf | 2015-10-22 21:26:26 +0300 | [diff] [blame] | 560 | int rc; |
| 561 | |
| 562 | rc = integrity_load_x509(INTEGRITY_KEYRING_EVM, CONFIG_EVM_X509_PATH); |
| 563 | if (!rc) |
| 564 | evm_initialized |= EVM_INIT_X509; |
Dmitry Kasatkin | 2ce523e | 2015-10-22 21:26:21 +0300 | [diff] [blame] | 565 | } |
| 566 | #endif |
| 567 | |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 568 | static int __init init_evm(void) |
| 569 | { |
| 570 | int error; |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 571 | struct list_head *pos, *q; |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 572 | |
Dmitry Kasatkin | d3b3367 | 2014-03-28 14:31:04 +0200 | [diff] [blame] | 573 | evm_init_config(); |
| 574 | |
Dmitry Kasatkin | f4dc377 | 2015-10-22 21:26:10 +0300 | [diff] [blame] | 575 | error = integrity_init_keyring(INTEGRITY_KEYRING_EVM); |
| 576 | if (error) |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 577 | goto error; |
Dmitry Kasatkin | f4dc377 | 2015-10-22 21:26:10 +0300 | [diff] [blame] | 578 | |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 579 | error = evm_init_secfs(); |
| 580 | if (error < 0) { |
Joe Perches | 20ee451 | 2014-02-24 13:59:56 -0800 | [diff] [blame] | 581 | pr_info("Error registering secfs\n"); |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 582 | goto error; |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 583 | } |
Dmitry Kasatkin | 15647eb | 2011-09-01 14:41:40 +0300 | [diff] [blame] | 584 | |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 585 | error: |
| 586 | if (error != 0) { |
| 587 | if (!list_empty(&evm_config_xattrnames)) { |
YueHaibing | c8b3752 | 2018-12-15 10:06:10 +0000 | [diff] [blame] | 588 | list_for_each_safe(pos, q, &evm_config_xattrnames) |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 589 | list_del(pos); |
Matthew Garrett | 21af766 | 2018-05-11 16:12:35 -0700 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
| 593 | return error; |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 594 | } |
| 595 | |
Mimi Zohar | 66dbc325 | 2011-03-15 16:12:09 -0400 | [diff] [blame] | 596 | late_initcall(init_evm); |