0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #define pr_fmt(fmt) "EVM: "fmt
0015
0016 #include <linux/init.h>
0017 #include <linux/crypto.h>
0018 #include <linux/audit.h>
0019 #include <linux/xattr.h>
0020 #include <linux/integrity.h>
0021 #include <linux/evm.h>
0022 #include <linux/magic.h>
0023 #include <linux/posix_acl_xattr.h>
0024
0025 #include <crypto/hash.h>
0026 #include <crypto/hash_info.h>
0027 #include <crypto/algapi.h>
0028 #include "evm.h"
0029
0030 int evm_initialized;
0031
0032 static const char * const integrity_status_msg[] = {
0033 "pass", "pass_immutable", "fail", "fail_immutable", "no_label",
0034 "no_xattrs", "unknown"
0035 };
0036 int evm_hmac_attrs;
0037
0038 static struct xattr_list evm_config_default_xattrnames[] = {
0039 {
0040 .name = XATTR_NAME_SELINUX,
0041 .enabled = IS_ENABLED(CONFIG_SECURITY_SELINUX)
0042 },
0043 {
0044 .name = XATTR_NAME_SMACK,
0045 .enabled = IS_ENABLED(CONFIG_SECURITY_SMACK)
0046 },
0047 {
0048 .name = XATTR_NAME_SMACKEXEC,
0049 .enabled = IS_ENABLED(CONFIG_EVM_EXTRA_SMACK_XATTRS)
0050 },
0051 {
0052 .name = XATTR_NAME_SMACKTRANSMUTE,
0053 .enabled = IS_ENABLED(CONFIG_EVM_EXTRA_SMACK_XATTRS)
0054 },
0055 {
0056 .name = XATTR_NAME_SMACKMMAP,
0057 .enabled = IS_ENABLED(CONFIG_EVM_EXTRA_SMACK_XATTRS)
0058 },
0059 {
0060 .name = XATTR_NAME_APPARMOR,
0061 .enabled = IS_ENABLED(CONFIG_SECURITY_APPARMOR)
0062 },
0063 {
0064 .name = XATTR_NAME_IMA,
0065 .enabled = IS_ENABLED(CONFIG_IMA_APPRAISE)
0066 },
0067 {
0068 .name = XATTR_NAME_CAPS,
0069 .enabled = true
0070 },
0071 };
0072
0073 LIST_HEAD(evm_config_xattrnames);
0074
0075 static int evm_fixmode __ro_after_init;
0076 static int __init evm_set_fixmode(char *str)
0077 {
0078 if (strncmp(str, "fix", 3) == 0)
0079 evm_fixmode = 1;
0080 else
0081 pr_err("invalid \"%s\" mode", str);
0082
0083 return 1;
0084 }
0085 __setup("evm=", evm_set_fixmode);
0086
0087 static void __init evm_init_config(void)
0088 {
0089 int i, xattrs;
0090
0091 xattrs = ARRAY_SIZE(evm_config_default_xattrnames);
0092
0093 pr_info("Initialising EVM extended attributes:\n");
0094 for (i = 0; i < xattrs; i++) {
0095 pr_info("%s%s\n", evm_config_default_xattrnames[i].name,
0096 !evm_config_default_xattrnames[i].enabled ?
0097 " (disabled)" : "");
0098 list_add_tail(&evm_config_default_xattrnames[i].list,
0099 &evm_config_xattrnames);
0100 }
0101
0102 #ifdef CONFIG_EVM_ATTR_FSUUID
0103 evm_hmac_attrs |= EVM_ATTR_FSUUID;
0104 #endif
0105 pr_info("HMAC attrs: 0x%x\n", evm_hmac_attrs);
0106 }
0107
0108 static bool evm_key_loaded(void)
0109 {
0110 return (bool)(evm_initialized & EVM_KEY_MASK);
0111 }
0112
0113
0114
0115
0116
0117
0118
0119
0120 static bool evm_hmac_disabled(void)
0121 {
0122 if (evm_initialized & EVM_INIT_HMAC)
0123 return false;
0124
0125 if (!(evm_initialized & EVM_SETUP_COMPLETE))
0126 return false;
0127
0128 return true;
0129 }
0130
0131 static int evm_find_protected_xattrs(struct dentry *dentry)
0132 {
0133 struct inode *inode = d_backing_inode(dentry);
0134 struct xattr_list *xattr;
0135 int error;
0136 int count = 0;
0137
0138 if (!(inode->i_opflags & IOP_XATTR))
0139 return -EOPNOTSUPP;
0140
0141 list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) {
0142 error = __vfs_getxattr(dentry, inode, xattr->name, NULL, 0);
0143 if (error < 0) {
0144 if (error == -ENODATA)
0145 continue;
0146 return error;
0147 }
0148 count++;
0149 }
0150
0151 return count;
0152 }
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167 static enum integrity_status evm_verify_hmac(struct dentry *dentry,
0168 const char *xattr_name,
0169 char *xattr_value,
0170 size_t xattr_value_len,
0171 struct integrity_iint_cache *iint)
0172 {
0173 struct evm_ima_xattr_data *xattr_data = NULL;
0174 struct signature_v2_hdr *hdr;
0175 enum integrity_status evm_status = INTEGRITY_PASS;
0176 struct evm_digest digest;
0177 struct inode *inode;
0178 int rc, xattr_len, evm_immutable = 0;
0179
0180 if (iint && (iint->evm_status == INTEGRITY_PASS ||
0181 iint->evm_status == INTEGRITY_PASS_IMMUTABLE))
0182 return iint->evm_status;
0183
0184
0185
0186
0187 rc = vfs_getxattr_alloc(&init_user_ns, dentry, XATTR_NAME_EVM,
0188 (char **)&xattr_data, 0, GFP_NOFS);
0189 if (rc <= 0) {
0190 evm_status = INTEGRITY_FAIL;
0191 if (rc == -ENODATA) {
0192 rc = evm_find_protected_xattrs(dentry);
0193 if (rc > 0)
0194 evm_status = INTEGRITY_NOLABEL;
0195 else if (rc == 0)
0196 evm_status = INTEGRITY_NOXATTRS;
0197 } else if (rc == -EOPNOTSUPP) {
0198 evm_status = INTEGRITY_UNKNOWN;
0199 }
0200 goto out;
0201 }
0202
0203 xattr_len = rc;
0204
0205
0206 switch (xattr_data->type) {
0207 case EVM_XATTR_HMAC:
0208 if (xattr_len != sizeof(struct evm_xattr)) {
0209 evm_status = INTEGRITY_FAIL;
0210 goto out;
0211 }
0212
0213 digest.hdr.algo = HASH_ALGO_SHA1;
0214 rc = evm_calc_hmac(dentry, xattr_name, xattr_value,
0215 xattr_value_len, &digest);
0216 if (rc)
0217 break;
0218 rc = crypto_memneq(xattr_data->data, digest.digest,
0219 SHA1_DIGEST_SIZE);
0220 if (rc)
0221 rc = -EINVAL;
0222 break;
0223 case EVM_XATTR_PORTABLE_DIGSIG:
0224 evm_immutable = 1;
0225 fallthrough;
0226 case EVM_IMA_XATTR_DIGSIG:
0227
0228 if (xattr_len <= sizeof(struct signature_v2_hdr)) {
0229 evm_status = INTEGRITY_FAIL;
0230 goto out;
0231 }
0232
0233 hdr = (struct signature_v2_hdr *)xattr_data;
0234 digest.hdr.algo = hdr->hash_algo;
0235 rc = evm_calc_hash(dentry, xattr_name, xattr_value,
0236 xattr_value_len, xattr_data->type, &digest);
0237 if (rc)
0238 break;
0239 rc = integrity_digsig_verify(INTEGRITY_KEYRING_EVM,
0240 (const char *)xattr_data, xattr_len,
0241 digest.digest, digest.hdr.length);
0242 if (!rc) {
0243 inode = d_backing_inode(dentry);
0244
0245 if (xattr_data->type == EVM_XATTR_PORTABLE_DIGSIG) {
0246 if (iint)
0247 iint->flags |= EVM_IMMUTABLE_DIGSIG;
0248 evm_status = INTEGRITY_PASS_IMMUTABLE;
0249 } else if (!IS_RDONLY(inode) &&
0250 !(inode->i_sb->s_readonly_remount) &&
0251 !IS_IMMUTABLE(inode)) {
0252 evm_update_evmxattr(dentry, xattr_name,
0253 xattr_value,
0254 xattr_value_len);
0255 }
0256 }
0257 break;
0258 default:
0259 rc = -EINVAL;
0260 break;
0261 }
0262
0263 if (rc) {
0264 if (rc == -ENODATA)
0265 evm_status = INTEGRITY_NOXATTRS;
0266 else if (evm_immutable)
0267 evm_status = INTEGRITY_FAIL_IMMUTABLE;
0268 else
0269 evm_status = INTEGRITY_FAIL;
0270 }
0271 pr_debug("digest: (%d) [%*phN]\n", digest.hdr.length, digest.hdr.length,
0272 digest.digest);
0273 out:
0274 if (iint)
0275 iint->evm_status = evm_status;
0276 kfree(xattr_data);
0277 return evm_status;
0278 }
0279
0280 static int evm_protected_xattr_common(const char *req_xattr_name,
0281 bool all_xattrs)
0282 {
0283 int namelen;
0284 int found = 0;
0285 struct xattr_list *xattr;
0286
0287 namelen = strlen(req_xattr_name);
0288 list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) {
0289 if (!all_xattrs && !xattr->enabled)
0290 continue;
0291
0292 if ((strlen(xattr->name) == namelen)
0293 && (strncmp(req_xattr_name, xattr->name, namelen) == 0)) {
0294 found = 1;
0295 break;
0296 }
0297 if (strncmp(req_xattr_name,
0298 xattr->name + XATTR_SECURITY_PREFIX_LEN,
0299 strlen(req_xattr_name)) == 0) {
0300 found = 1;
0301 break;
0302 }
0303 }
0304
0305 return found;
0306 }
0307
0308 static int evm_protected_xattr(const char *req_xattr_name)
0309 {
0310 return evm_protected_xattr_common(req_xattr_name, false);
0311 }
0312
0313 int evm_protected_xattr_if_enabled(const char *req_xattr_name)
0314 {
0315 return evm_protected_xattr_common(req_xattr_name, true);
0316 }
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333 int evm_read_protected_xattrs(struct dentry *dentry, u8 *buffer,
0334 int buffer_size, char type, bool canonical_fmt)
0335 {
0336 struct xattr_list *xattr;
0337 int rc, size, total_size = 0;
0338
0339 list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) {
0340 rc = __vfs_getxattr(dentry, d_backing_inode(dentry),
0341 xattr->name, NULL, 0);
0342 if (rc < 0 && rc == -ENODATA)
0343 continue;
0344 else if (rc < 0)
0345 return rc;
0346
0347 switch (type) {
0348 case 'n':
0349 size = strlen(xattr->name) + 1;
0350 if (buffer) {
0351 if (total_size)
0352 *(buffer + total_size - 1) = '|';
0353
0354 memcpy(buffer + total_size, xattr->name, size);
0355 }
0356 break;
0357 case 'l':
0358 size = sizeof(u32);
0359 if (buffer) {
0360 if (canonical_fmt)
0361 rc = (__force int)cpu_to_le32(rc);
0362
0363 *(u32 *)(buffer + total_size) = rc;
0364 }
0365 break;
0366 case 'v':
0367 size = rc;
0368 if (buffer) {
0369 rc = __vfs_getxattr(dentry,
0370 d_backing_inode(dentry), xattr->name,
0371 buffer + total_size,
0372 buffer_size - total_size);
0373 if (rc < 0)
0374 return rc;
0375 }
0376 break;
0377 default:
0378 return -EINVAL;
0379 }
0380
0381 total_size += size;
0382 }
0383
0384 return total_size;
0385 }
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403 enum integrity_status evm_verifyxattr(struct dentry *dentry,
0404 const char *xattr_name,
0405 void *xattr_value, size_t xattr_value_len,
0406 struct integrity_iint_cache *iint)
0407 {
0408 if (!evm_key_loaded() || !evm_protected_xattr(xattr_name))
0409 return INTEGRITY_UNKNOWN;
0410
0411 if (!iint) {
0412 iint = integrity_iint_find(d_backing_inode(dentry));
0413 if (!iint)
0414 return INTEGRITY_UNKNOWN;
0415 }
0416 return evm_verify_hmac(dentry, xattr_name, xattr_value,
0417 xattr_value_len, iint);
0418 }
0419 EXPORT_SYMBOL_GPL(evm_verifyxattr);
0420
0421
0422
0423
0424
0425
0426
0427
0428 static enum integrity_status evm_verify_current_integrity(struct dentry *dentry)
0429 {
0430 struct inode *inode = d_backing_inode(dentry);
0431
0432 if (!evm_key_loaded() || !S_ISREG(inode->i_mode) || evm_fixmode)
0433 return INTEGRITY_PASS;
0434 return evm_verify_hmac(dentry, NULL, NULL, 0, NULL);
0435 }
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449 static int evm_xattr_acl_change(struct user_namespace *mnt_userns,
0450 struct dentry *dentry, const char *xattr_name,
0451 const void *xattr_value, size_t xattr_value_len)
0452 {
0453 #ifdef CONFIG_FS_POSIX_ACL
0454 umode_t mode;
0455 struct posix_acl *acl = NULL, *acl_res;
0456 struct inode *inode = d_backing_inode(dentry);
0457 int rc;
0458
0459
0460
0461
0462
0463 acl = posix_acl_from_xattr(&init_user_ns, xattr_value, xattr_value_len);
0464 if (IS_ERR_OR_NULL(acl))
0465 return 1;
0466
0467 acl_res = acl;
0468
0469
0470
0471
0472
0473 rc = posix_acl_update_mode(mnt_userns, inode, &mode, &acl_res);
0474
0475 posix_acl_release(acl);
0476
0477 if (rc)
0478 return 1;
0479
0480 if (inode->i_mode != mode)
0481 return 1;
0482 #endif
0483 return 0;
0484 }
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498 static int evm_xattr_change(struct user_namespace *mnt_userns,
0499 struct dentry *dentry, const char *xattr_name,
0500 const void *xattr_value, size_t xattr_value_len)
0501 {
0502 char *xattr_data = NULL;
0503 int rc = 0;
0504
0505 if (posix_xattr_acl(xattr_name))
0506 return evm_xattr_acl_change(mnt_userns, dentry, xattr_name,
0507 xattr_value, xattr_value_len);
0508
0509 rc = vfs_getxattr_alloc(&init_user_ns, dentry, xattr_name, &xattr_data,
0510 0, GFP_NOFS);
0511 if (rc < 0)
0512 return 1;
0513
0514 if (rc == xattr_value_len)
0515 rc = !!memcmp(xattr_value, xattr_data, rc);
0516 else
0517 rc = 1;
0518
0519 kfree(xattr_data);
0520 return rc;
0521 }
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535 static int evm_protect_xattr(struct user_namespace *mnt_userns,
0536 struct dentry *dentry, const char *xattr_name,
0537 const void *xattr_value, size_t xattr_value_len)
0538 {
0539 enum integrity_status evm_status;
0540
0541 if (strcmp(xattr_name, XATTR_NAME_EVM) == 0) {
0542 if (!capable(CAP_SYS_ADMIN))
0543 return -EPERM;
0544 } else if (!evm_protected_xattr(xattr_name)) {
0545 if (!posix_xattr_acl(xattr_name))
0546 return 0;
0547 evm_status = evm_verify_current_integrity(dentry);
0548 if ((evm_status == INTEGRITY_PASS) ||
0549 (evm_status == INTEGRITY_NOXATTRS))
0550 return 0;
0551 goto out;
0552 }
0553
0554 evm_status = evm_verify_current_integrity(dentry);
0555 if (evm_status == INTEGRITY_NOXATTRS) {
0556 struct integrity_iint_cache *iint;
0557
0558
0559 if (evm_hmac_disabled())
0560 return 0;
0561
0562 iint = integrity_iint_find(d_backing_inode(dentry));
0563 if (iint && (iint->flags & IMA_NEW_FILE))
0564 return 0;
0565
0566
0567 if (dentry->d_sb->s_magic == TMPFS_MAGIC
0568 || dentry->d_sb->s_magic == SYSFS_MAGIC)
0569 return 0;
0570
0571 integrity_audit_msg(AUDIT_INTEGRITY_METADATA,
0572 dentry->d_inode, dentry->d_name.name,
0573 "update_metadata",
0574 integrity_status_msg[evm_status],
0575 -EPERM, 0);
0576 }
0577 out:
0578
0579 if (evm_hmac_disabled() && (evm_status == INTEGRITY_NOLABEL ||
0580 evm_status == INTEGRITY_UNKNOWN))
0581 return 0;
0582
0583
0584
0585
0586
0587 if (evm_status == INTEGRITY_FAIL_IMMUTABLE)
0588 return 0;
0589
0590 if (evm_status == INTEGRITY_PASS_IMMUTABLE &&
0591 !evm_xattr_change(mnt_userns, dentry, xattr_name, xattr_value,
0592 xattr_value_len))
0593 return 0;
0594
0595 if (evm_status != INTEGRITY_PASS &&
0596 evm_status != INTEGRITY_PASS_IMMUTABLE)
0597 integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry),
0598 dentry->d_name.name, "appraise_metadata",
0599 integrity_status_msg[evm_status],
0600 -EPERM, 0);
0601 return evm_status == INTEGRITY_PASS ? 0 : -EPERM;
0602 }
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618 int evm_inode_setxattr(struct user_namespace *mnt_userns, struct dentry *dentry,
0619 const char *xattr_name, const void *xattr_value,
0620 size_t xattr_value_len)
0621 {
0622 const struct evm_ima_xattr_data *xattr_data = xattr_value;
0623
0624
0625
0626
0627 if (evm_initialized & EVM_ALLOW_METADATA_WRITES)
0628 return 0;
0629
0630 if (strcmp(xattr_name, XATTR_NAME_EVM) == 0) {
0631 if (!xattr_value_len)
0632 return -EINVAL;
0633 if (xattr_data->type != EVM_IMA_XATTR_DIGSIG &&
0634 xattr_data->type != EVM_XATTR_PORTABLE_DIGSIG)
0635 return -EPERM;
0636 }
0637 return evm_protect_xattr(mnt_userns, dentry, xattr_name, xattr_value,
0638 xattr_value_len);
0639 }
0640
0641
0642
0643
0644
0645
0646
0647
0648
0649
0650 int evm_inode_removexattr(struct user_namespace *mnt_userns,
0651 struct dentry *dentry, const char *xattr_name)
0652 {
0653
0654
0655
0656 if (evm_initialized & EVM_ALLOW_METADATA_WRITES)
0657 return 0;
0658
0659 return evm_protect_xattr(mnt_userns, dentry, xattr_name, NULL, 0);
0660 }
0661
0662 static void evm_reset_status(struct inode *inode)
0663 {
0664 struct integrity_iint_cache *iint;
0665
0666 iint = integrity_iint_find(inode);
0667 if (iint)
0668 iint->evm_status = INTEGRITY_UNKNOWN;
0669 }
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679
0680 bool evm_revalidate_status(const char *xattr_name)
0681 {
0682 if (!evm_key_loaded())
0683 return false;
0684
0685
0686 if (!xattr_name)
0687 return true;
0688
0689 if (!evm_protected_xattr(xattr_name) && !posix_xattr_acl(xattr_name) &&
0690 strcmp(xattr_name, XATTR_NAME_EVM))
0691 return false;
0692
0693 return true;
0694 }
0695
0696
0697
0698
0699
0700
0701
0702
0703
0704
0705
0706
0707
0708
0709 void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
0710 const void *xattr_value, size_t xattr_value_len)
0711 {
0712 if (!evm_revalidate_status(xattr_name))
0713 return;
0714
0715 evm_reset_status(dentry->d_inode);
0716
0717 if (!strcmp(xattr_name, XATTR_NAME_EVM))
0718 return;
0719
0720 if (!(evm_initialized & EVM_INIT_HMAC))
0721 return;
0722
0723 evm_update_evmxattr(dentry, xattr_name, xattr_value, xattr_value_len);
0724 }
0725
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736 void evm_inode_post_removexattr(struct dentry *dentry, const char *xattr_name)
0737 {
0738 if (!evm_revalidate_status(xattr_name))
0739 return;
0740
0741 evm_reset_status(dentry->d_inode);
0742
0743 if (!strcmp(xattr_name, XATTR_NAME_EVM))
0744 return;
0745
0746 if (!(evm_initialized & EVM_INIT_HMAC))
0747 return;
0748
0749 evm_update_evmxattr(dentry, xattr_name, NULL, 0);
0750 }
0751
0752 static int evm_attr_change(struct user_namespace *mnt_userns,
0753 struct dentry *dentry, struct iattr *attr)
0754 {
0755 struct inode *inode = d_backing_inode(dentry);
0756 unsigned int ia_valid = attr->ia_valid;
0757
0758 if (!i_uid_needs_update(mnt_userns, attr, inode) &&
0759 !i_gid_needs_update(mnt_userns, attr, inode) &&
0760 (!(ia_valid & ATTR_MODE) || attr->ia_mode == inode->i_mode))
0761 return 0;
0762
0763 return 1;
0764 }
0765
0766
0767
0768
0769
0770
0771
0772
0773 int evm_inode_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
0774 struct iattr *attr)
0775 {
0776 unsigned int ia_valid = attr->ia_valid;
0777 enum integrity_status evm_status;
0778
0779
0780
0781
0782 if (evm_initialized & EVM_ALLOW_METADATA_WRITES)
0783 return 0;
0784
0785 if (!(ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)))
0786 return 0;
0787 evm_status = evm_verify_current_integrity(dentry);
0788
0789
0790
0791
0792 if ((evm_status == INTEGRITY_PASS) ||
0793 (evm_status == INTEGRITY_NOXATTRS) ||
0794 (evm_status == INTEGRITY_FAIL_IMMUTABLE) ||
0795 (evm_hmac_disabled() && (evm_status == INTEGRITY_NOLABEL ||
0796 evm_status == INTEGRITY_UNKNOWN)))
0797 return 0;
0798
0799 if (evm_status == INTEGRITY_PASS_IMMUTABLE &&
0800 !evm_attr_change(mnt_userns, dentry, attr))
0801 return 0;
0802
0803 integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry),
0804 dentry->d_name.name, "appraise_metadata",
0805 integrity_status_msg[evm_status], -EPERM, 0);
0806 return -EPERM;
0807 }
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820 void evm_inode_post_setattr(struct dentry *dentry, int ia_valid)
0821 {
0822 if (!evm_revalidate_status(NULL))
0823 return;
0824
0825 evm_reset_status(dentry->d_inode);
0826
0827 if (!(evm_initialized & EVM_INIT_HMAC))
0828 return;
0829
0830 if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID))
0831 evm_update_evmxattr(dentry, NULL, NULL, 0);
0832 }
0833
0834
0835
0836
0837 int evm_inode_init_security(struct inode *inode,
0838 const struct xattr *lsm_xattr,
0839 struct xattr *evm_xattr)
0840 {
0841 struct evm_xattr *xattr_data;
0842 int rc;
0843
0844 if (!(evm_initialized & EVM_INIT_HMAC) ||
0845 !evm_protected_xattr(lsm_xattr->name))
0846 return 0;
0847
0848 xattr_data = kzalloc(sizeof(*xattr_data), GFP_NOFS);
0849 if (!xattr_data)
0850 return -ENOMEM;
0851
0852 xattr_data->data.type = EVM_XATTR_HMAC;
0853 rc = evm_init_hmac(inode, lsm_xattr, xattr_data->digest);
0854 if (rc < 0)
0855 goto out;
0856
0857 evm_xattr->value = xattr_data;
0858 evm_xattr->value_len = sizeof(*xattr_data);
0859 evm_xattr->name = XATTR_EVM_SUFFIX;
0860 return 0;
0861 out:
0862 kfree(xattr_data);
0863 return rc;
0864 }
0865 EXPORT_SYMBOL_GPL(evm_inode_init_security);
0866
0867 #ifdef CONFIG_EVM_LOAD_X509
0868 void __init evm_load_x509(void)
0869 {
0870 int rc;
0871
0872 rc = integrity_load_x509(INTEGRITY_KEYRING_EVM, CONFIG_EVM_X509_PATH);
0873 if (!rc)
0874 evm_initialized |= EVM_INIT_X509;
0875 }
0876 #endif
0877
0878 static int __init init_evm(void)
0879 {
0880 int error;
0881 struct list_head *pos, *q;
0882
0883 evm_init_config();
0884
0885 error = integrity_init_keyring(INTEGRITY_KEYRING_EVM);
0886 if (error)
0887 goto error;
0888
0889 error = evm_init_secfs();
0890 if (error < 0) {
0891 pr_info("Error registering secfs\n");
0892 goto error;
0893 }
0894
0895 error:
0896 if (error != 0) {
0897 if (!list_empty(&evm_config_xattrnames)) {
0898 list_for_each_safe(pos, q, &evm_config_xattrnames)
0899 list_del(pos);
0900 }
0901 }
0902
0903 return error;
0904 }
0905
0906 late_initcall(init_evm);