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