Skip to contentSkip to conversation

integrity: Add an integrity directory in securityfs

PATCH In review Matthew Garrett 2 participants 11 messages May 11, 2018 – May 14, 2018

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/3 integrity: Add an integrity directory in securityfs

We want to add additional evm control nodes, and it'd be preferable not to clutter up the securityfs root directory any further. Create a new integrity directory, move the ima directory into it, create an evm directory for the evm attribute and add compatibility symlinks.

---
 security/integrity/evm/evm_secfs.c | 27 ++++++++++++++++++++++++---
 security/integrity/iint.c          | 18 ++++++++++++++++++
 security/integrity/ima/ima_fs.c    |  9 ++++++++-
 security/integrity/integrity.h     |  2 ++
 4 files changed, 52 insertions(+), 4 deletions(-)
security/integrity/evm/evm_secfs.c +24 -3
index feba03bbedae..e44380f0cb45 100644
@@ -19,7 +19,9 @@
 #include <linux/module.h>
 #include "evm.h"
 
+static struct dentry *evm_dir;
 static struct dentry *evm_init_tpm;
+static struct dentry *evm_symlink;
 
 /**
  * evm_read_key - read() for <securityfs>/evm
@@ -111,9 +113,28 @@ int __init evm_init_secfs(void)
 {
 	int error = 0;
 
-	evm_init_tpm = securityfs_create_file("evm", S_IRUSR | S_IRGRP,
-					      NULL, NULL, &evm_key_ops);
-	if (!evm_init_tpm || IS_ERR(evm_init_tpm))
+	evm_dir = securityfs_create_dir("evm", integrity_dir);
+	if (!evm_dir || IS_ERR(evm_dir))
+		return -EFAULT;
+
+	evm_init_tpm = securityfs_create_file("evm", 0660,
+					      evm_dir, NULL, &evm_key_ops);
+	if (!evm_init_tpm || IS_ERR(evm_init_tpm)) {
+		error = -EFAULT;
+		goto out;
+	}
+
+	evm_symlink = securityfs_create_symlink("evm", NULL,
+						"integrity/evm/evm", NULL);
+	if (!evm_symlink || IS_ERR(evm_symlink)) {
 		error = -EFAULT;
+		goto out;
+	}
+
+	return 0;
+out:
+	securityfs_remove(evm_symlink);
+	securityfs_remove(evm_init_tpm);
+	securityfs_remove(evm_dir);
 	return error;
 }
security/integrity/iint.c +18 -0
index f266e4b3b7d4..149faa81f6f0 100644
@@ -21,12 +21,15 @@
 #include <linux/rbtree.h>
 #include <linux/file.h>
 #include <linux/uaccess.h>
+#include <linux/security.h>
 #include "integrity.h"
 
 static struct rb_root integrity_iint_tree = RB_ROOT;
 static DEFINE_RWLOCK(integrity_iint_lock);
 static struct kmem_cache *iint_cache __read_mostly;
 
+struct dentry *integrity_dir;
+
 /*
  * __integrity_iint_find - return the iint associated with an inode
  */
@@ -211,3 +214,18 @@ void __init integrity_load_keys(void)
 	ima_load_x509();
 	evm_load_x509();
 }
+
+static int __init integrity_fs_init(void)
+{
+	integrity_dir = securityfs_create_dir("integrity", NULL);
+	if (IS_ERR(integrity_dir)) {
+		pr_err("Unable to create integrity sysfs dir: %ld\n",
+		       PTR_ERR(integrity_dir));
+		integrity_dir = NULL;
+		return PTR_ERR(integrity_dir);
+	}
+
+	return 0;
+}
+
+late_initcall(integrity_fs_init)
security/integrity/ima/ima_fs.c +8 -1
index fa540c0469da..5153d7faea13 100644
@@ -356,6 +356,7 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf,
 }
 
 static struct dentry *ima_dir;
+static struct dentry *ima_symlink;
 static struct dentry *binary_runtime_measurements;
 static struct dentry *ascii_runtime_measurements;
 static struct dentry *runtime_measurements_count;
@@ -448,10 +449,15 @@ static const struct file_operations ima_measure_policy_ops = {
 
 int __init ima_fs_init(void)
 {
-	ima_dir = securityfs_create_dir("ima", NULL);
+	ima_dir = securityfs_create_dir("ima", integrity_dir);
 	if (IS_ERR(ima_dir))
 		return -1;
 
+	ima_symlink = securityfs_create_symlink("ima", NULL, "integrity/ima",
+						NULL);
+	if (IS_ERR(ima_symlink))
+		goto out;
+
 	binary_runtime_measurements =
 	    securityfs_create_file("binary_runtime_measurements",
 				   S_IRUSR | S_IRGRP, ima_dir, NULL,
@@ -491,6 +497,7 @@ int __init ima_fs_init(void)
 	securityfs_remove(runtime_measurements_count);
 	securityfs_remove(ascii_runtime_measurements);
 	securityfs_remove(binary_runtime_measurements);
+	securityfs_remove(ima_symlink);
 	securityfs_remove(ima_dir);
 	securityfs_remove(ima_policy);
 	return -1;
security/integrity/integrity.h +2 -0
index 5e58e02ba8dc..0bb372eed62a 100644
@@ -143,6 +143,8 @@ int integrity_kernel_read(struct file *file, loff_t offset,
 #define INTEGRITY_KEYRING_MODULE	2
 #define INTEGRITY_KEYRING_MAX		3
 
+extern struct dentry *integrity_dir;
+
 #ifdef CONFIG_INTEGRITY_SIGNATURE
 
 int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#1 lore raw

PATCH v5 2/3 EVM: turn evm_config_xattrnames into a list

Use a list of xattrs rather than an array - this makes it easier to extend the list at runtime.

---
 security/integrity/evm/evm.h        |  7 ++-
 security/integrity/evm/evm_crypto.c | 10 ++--
 security/integrity/evm/evm_main.c   | 79 +++++++++++++++++------------
 3 files changed, 57 insertions(+), 39 deletions(-)
security/integrity/evm/evm.h +6 -1
index 45c4a89c02ff..1257c3c24723 100644
@@ -30,6 +30,11 @@
 #define EVM_INIT_MASK (EVM_INIT_HMAC | EVM_INIT_X509 | EVM_SETUP_COMPLETE | \
 		       EVM_ALLOW_METADATA_WRITES)
 
+struct xattr_list {
+	struct list_head list;
+	char *name;
+};
+
 extern int evm_initialized;
 
 #define EVM_ATTR_FSUUID		0x0001
@@ -40,7 +45,7 @@ extern struct crypto_shash *hmac_tfm;
 extern struct crypto_shash *hash_tfm;
 
 /* List of EVM protected security xattrs */
-extern char *evm_config_xattrnames[];
+extern struct list_head evm_config_xattrnames;
 
 int evm_init_key(void);
 int evm_update_evmxattr(struct dentry *dentry,
security/integrity/evm/evm_crypto.c +5 -5
index a46fba322340..caeea20670cc 100644
@@ -192,8 +192,8 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 				char type, char *digest)
 {
 	struct inode *inode = d_backing_inode(dentry);
+	struct xattr_list *xattr;
 	struct shash_desc *desc;
-	char **xattrname;
 	size_t xattr_size = 0;
 	char *xattr_value = NULL;
 	int error;
@@ -208,14 +208,14 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 		return PTR_ERR(desc);
 
 	error = -ENODATA;
-	for (xattrname = evm_config_xattrnames; *xattrname != NULL; xattrname++) {
+	list_for_each_entry(xattr, &evm_config_xattrnames, list) {
 		bool is_ima = false;
 
-		if (strcmp(*xattrname, XATTR_NAME_IMA) == 0)
+		if (strcmp(xattr->name, XATTR_NAME_IMA) == 0)
 			is_ima = true;
 
 		if ((req_xattr_name && req_xattr_value)
-		    && !strcmp(*xattrname, req_xattr_name)) {
+		    && !strcmp(xattr->name, req_xattr_name)) {
 			error = 0;
 			crypto_shash_update(desc, (const u8 *)req_xattr_value,
 					     req_xattr_value_len);
@@ -223,7 +223,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 				ima_present = true;
 			continue;
 		}
-		size = vfs_getxattr_alloc(dentry, *xattrname,
+		size = vfs_getxattr_alloc(dentry, xattr->name,
 					  &xattr_value, xattr_size, GFP_NOFS);
 		if (size == -ENOMEM) {
 			error = -ENOMEM;
security/integrity/evm/evm_main.c +46 -33

154 lines not on this page · raw message

Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#2 lore raw

PATCH v5 3/3 EVM: Allow runtime modification of the set of verified xattrs

In reply to Matthew Garrett

Sites may wish to provide additional metadata alongside files in order to make more fine-grained security decisions[1]. The security of this is enhanced if this metadata is protected, something that EVM makes possible. However, the kernel cannot know about the set of extended attributes that local admins may wish to protect, and hardcoding this policy in the kernel makes it difficult to change over time and less convenient for distributions to enable.

This patch adds a new /sys/kernel/security/evm_xattrs node, which can be read to obtain the current set of EVM-protected extended attributes or written to in order to add new entries. Extending this list will not change the validity of any existing signatures provided that the file in question does not have any of the additional extended attributes - missing xattrs are skipped when calculating the EVM hash.

[1] For instance, a package manager could install information about the package uploader in an additional extended attribute. Local LSM policy could then be associated with that extended attribute in order to restrict the privileges available to packages from less trusted uploaders.

---

I think this covers the review comments.

 Documentation/ABI/testing/evm       |  13 +++
 include/uapi/linux/audit.h          |   1 +
 security/integrity/evm/Kconfig      |  11 ++
 security/integrity/evm/evm_crypto.c |   2 +-
 security/integrity/evm/evm_main.c   |   6 +-
 security/integrity/evm/evm_secfs.c  | 173 ++++++++++++++++++++++++++++
 6 files changed, 202 insertions(+), 4 deletions(-)
Documentation/ABI/testing/evm +13 -0
index d12cb2eae9ee..fa31df7fd30b 100644
@@ -57,3 +57,16 @@ Description:
 		dracut (via 97masterkey and 98integrity) and systemd (via
 		core/ima-setup) have support for loading keys at boot
 		time.
+
+What:		security/evm_xattrs
+Date:		April 2018
+Contact:	Matthew Garrett <[email protected]>
+Description:
+		Shows the set of extended attributes used to calculate or
+		validate the EVM signature, and allows additional attributes
+		to be added at runtime. Any signatures generated after
+		additional attributes are added (and on files posessing those
+		additional attributes) will only be valid if the same
+		additional attributes are configured on system boot. Writing
+		a single period (.) will lock the xattr list from any further
+		modification.
include/uapi/linux/audit.h +1 -0
index 4e61a9e05132..65d9293f1fb8 100644
@@ -147,6 +147,7 @@
 #define AUDIT_INTEGRITY_HASH	    1803 /* Integrity HASH type */
 #define AUDIT_INTEGRITY_PCR	    1804 /* PCR invalidation msgs */
 #define AUDIT_INTEGRITY_RULE	    1805 /* policy rule */
+#define AUDIT_INTEGRITY_EVM_XATTR   1806 /* New EVM-covered xattr */
 
 #define AUDIT_KERNEL		2000	/* Asynchronous audit record. NOT A REQUEST. */
 
security/integrity/evm/Kconfig +11 -0
index e825e0ae78e7..54adb3f9ad1d 100644
@@ -42,6 +42,17 @@ config EVM_EXTRA_SMACK_XATTRS
 	  additional info to the calculation, requires existing EVM
 	  labeled file systems to be relabeled.
 
+config EVM_ADD_XATTRS
+	bool "Add additional EVM extended attributes at runtime"
+	depends on EVM
+	default n
+	help
+	  Allow userland to provide additional xattrs for HMAC calculation.
+
+	  When this option is enabled, root can add additional xattrs to the
+	  list used by EVM by writing them into
+	  /sys/kernel/security/evm_xattrs.
+
 config EVM_LOAD_X509
 	bool "Load an X509 certificate onto the '.evm' trusted keyring"
 	depends on EVM && INTEGRITY_TRUSTED_KEYRING
security/integrity/evm/evm_crypto.c +1 -1
index caeea20670cc..494da5fcc092 100644
@@ -208,7 +208,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 		return PTR_ERR(desc);
 
 	error = -ENODATA;
-	list_for_each_entry(xattr, &evm_config_xattrnames, list) {
+	list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) {
 		bool is_ima = false;
 
 		if (strcmp(xattr->name, XATTR_NAME_IMA) == 0)
security/integrity/evm/evm_main.c +3 -3
index 09582d4fc4a8..f9eff5041e4c 100644
@@ -35,7 +35,7 @@ static const char * const integrity_status_msg[] = {
 };
 int evm_hmac_attrs;
 
-static struct xattr_list evm_config_default_xattrnames[] __ro_after_init = {
+static struct xattr_list evm_config_default_xattrnames[] = {
 #ifdef CONFIG_SECURITY_SELINUX
 	{.name = XATTR_NAME_SELINUX},
 #endif
@@ -101,7 +101,7 @@ static int evm_find_protected_xattrs(struct dentry *dentry)
 	if (!(inode->i_opflags & IOP_XATTR))
 		return -EOPNOTSUPP;
 
-	list_for_each_entry(xattr, &evm_config_xattrnames, list) {
+	list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) {
 		error = __vfs_getxattr(dentry, inode, xattr->name, NULL, 0);
 		if (error < 0) {
 			if (error == -ENODATA)
@@ -228,7 +228,7 @@ static int evm_protected_xattr(const char *req_xattr_name)
 	struct xattr_list *xattr;
 
 	namelen = strlen(req_xattr_name);
-	list_for_each_entry(xattr, &evm_config_xattrnames, list) {
+	list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) {
 		if ((strlen(xattr->name) == namelen)
 		    && (strncmp(req_xattr_name, xattr->name, namelen) == 0)) {
 			found = 1;
security/integrity/evm/evm_secfs.c +173 -0

199 lines not on this page · raw message

Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#3 lore raw

Re: [PATCH V5 3/3] EVM: Allow runtime modification of the set of verified xattrs

Quoted 8 lines · Matthew Garrett

Sites may wish to provide additional metadata alongside files in order to make more fine-grained security decisions[1]. The security of this is enhanced if this metadata is protected, something that EVM makes possible. However, the kernel cannot know about the set of extended attributes that local admins may wish to protect, and hardcoding this policy in the kernel makes it difficult to change over time and less convenient for distributions to enable.

Quoted 6 lines

This patch adds a new /sys/kernel/security/evm_xattrs node, which can be read to obtain the current set of EVM-protected extended attributes or written to in order to add new entries. Extending this list will not change the validity of any existing signatures provided that the file in question does not have any of the additional extended attributes - missing xattrs are skipped when calculating the EVM hash.

The new pathname introduced in the new patch needs to be propagated
to the patch description, Documentation and Kconfig in this patch.

Quoted 11 lines

[1] For instance, a package manager could install information about the package uploader in an additional extended attribute. Local LSM policy could then be associated with that extended attribute in order to restrict the privileges available to packages from less trusted uploaders.

---

I think this covers the review comments.

Yes, it looks good. The pathname changes introduced in the new patch, need to be propagated to the patch description, above, Documentation, and Kconfig. The only other change is that with the introduction of requiring the xattr names to be prefixed with "security", locking the xattr names list fails. After making these tw changes, there's no need to re-post the entire patch set. Please re-post just this one.

Quoted 13 lines
 Documentation/ABI/testing/evm       |  13 +++
 include/uapi/linux/audit.h          |   1 +
 security/integrity/evm/Kconfig      |  11 ++
 security/integrity/evm/evm_crypto.c |   2 +-
 security/integrity/evm/evm_main.c   |   6 +-
 security/integrity/evm/evm_secfs.c  | 173 ++++++++++++++++++++++++++++
 6 files changed, 202 insertions(+), 4 deletions(-)
Documentation/ABI/testing/evm +0 -0
index d12cb2eae9ee..fa31df7fd30b 100644

Documentation/ABI/testing/evm Description: · line 61

Quoted 5 lines
Documentation/ABI/testing/evm +2 -0
@@ -57,3 +57,16 @@ Description:
 		dracut (via 97masterkey and 98integrity) and systemd (via
 		core/ima-setup) have support for loading keys at boot
 		time.
+
+What:		security/evm_xattrs

Update

Documentation/ABI/testing/evm Description: · line 72

Quoted 11 lines
Documentation/ABI/testing/evm +11 -0
+Date:		April 2018
+Contact:	Matthew Garrett <[email protected]>
+Description:
+		Shows the set of extended attributes used to calculate or
+		validate the EVM signature, and allows additional attributes
+		to be added at runtime. Any signatures generated after
+		additional attributes are added (and on files posessing those
+		additional attributes) will only be valid if the same
+		additional attributes are configured on system boot. Writing
+		a single period (.) will lock the xattr list from any further
+		modification.

Writing '.', doesn't match the code.

Documentation/ABI/testing/evm

Quoted 10 lines
Documentation/ABI/testing/evm +10 -0
+config EVM_ADD_XATTRS
+	bool "Add additional EVM extended attributes at runtime"
+	depends on EVM
+	default n
+	help
+	  Allow userland to provide additional xattrs for HMAC calculation.
+
+	  When this option is enabled, root can add additional xattrs to the
+	  list used by EVM by writing them into
+	  /sys/kernel/security/evm_xattrs.

Update

Quoted 13 lines
Documentation/ABI/testing/evm +13 -0
+
+	if (strcmp(xattr->name, ".") == 0) {
+		evm_xattrs_locked = 1;
+		inode = evm_xattrs->d_inode;
+		inode_lock(inode);
+		newattrs.ia_mode = S_IFREG | 0440;
+		newattrs.ia_valid = ATTR_MODE;
+		err = notify_change(evm_xattrs, &newattrs, NULL);
+		inode_unlock(inode);
+		audit_log_format(ab, "locked");
+		if (!err)
+			err = count;
+		goto out;

Documentation/ABI/testing/evm

Quoted 10 lines
Documentation/ABI/testing/evm +10 -0
+	}
+
+	audit_log_format(ab, "xattr=");
+	audit_log_untrustedstring(ab, xattr->name);
+
+	if (strncmp(xattr->name, XATTR_SECURITY_PREFIX,
+		    XATTR_SECURITY_PREFIX_LEN) != 0) {
+		err = -EINVAL;
+		goto out;
+	}

This test now prevents locking the xattr names list. Making this an else clause will fix it.

thanks,

Mimi

#4 lore raw

Re: [PATCH V5 3/3] EVM: Allow runtime modification of the set of verified xattrs

Quoted 19 lines · Mimi Zohar

On Fri, 2018-05-11 at 16:12 -0700, Matthew Garrett wrote:
+

Quoted 17 lines
security/integrity/evm/evm_secfs.c +17 -0
+     if (strcmp(xattr->name, ".") == 0) {
+             evm_xattrs_locked = 1;
+             inode = evm_xattrs->d_inode;
+             inode_lock(inode);
+             newattrs.ia_mode = S_IFREG | 0440;
+             newattrs.ia_valid = ATTR_MODE;
+             err = notify_change(evm_xattrs, &newattrs, NULL);
+             inode_unlock(inode);
+             audit_log_format(ab, "locked");
+             if (!err)
+                     err = count;
+             goto out;
+     }
+
+     audit_log_format(ab, "xattr=");
+     audit_log_untrustedstring(ab, xattr->name);
+
Quoted 8 lines

security/integrity/evm/evm_secfs.c static const struct file_operations evm_key_ops = { · line 234

Quoted 5 lines
security/integrity/evm/evm_secfs.c +5 -0
+     if (strncmp(xattr->name, XATTR_SECURITY_PREFIX,
+                 XATTR_SECURITY_PREFIX_LEN) != 0) {
+             err = -EINVAL;
+             goto out;
+     }

This test now prevents locking the xattr names list. Making this an else clause will fix it.

Are you sure? The check for "." happens before this, and jumps over the rest of the function.

#5 lore raw

Re: [PATCH V5 3/3] EVM: Allow runtime modification of the set of verified xattrs

Quoted 30 lines · Matthew Garrett
Quoted 19 lines · Mimi Zohar

On Fri, 2018-05-11 at 16:12 -0700, Matthew Garrett wrote:
+

Quoted 17 lines
security/integrity/evm/evm_secfs.c +17 -0
+     if (strcmp(xattr->name, ".") == 0) {
+             evm_xattrs_locked = 1;
+             inode = evm_xattrs->d_inode;
+             inode_lock(inode);
+             newattrs.ia_mode = S_IFREG | 0440;
+             newattrs.ia_valid = ATTR_MODE;
+             err = notify_change(evm_xattrs, &newattrs, NULL);
+             inode_unlock(inode);
+             audit_log_format(ab, "locked");
+             if (!err)
+                     err = count;
+             goto out;
+     }
+
+     audit_log_format(ab, "xattr=");
+     audit_log_untrustedstring(ab, xattr->name);
+
Quoted 8 lines

security/integrity/evm/evm_secfs.c static const struct file_operations evm_key_ops = { · line 234

Quoted 5 lines
security/integrity/evm/evm_secfs.c +5 -0
+     if (strncmp(xattr->name, XATTR_SECURITY_PREFIX,
+                 XATTR_SECURITY_PREFIX_LEN) != 0) {
+             err = -EINVAL;
+             goto out;
+     }

This test now prevents locking the xattr names list. Making this an else clause will fix it.

Quoted 2 lines

Are you sure? The check for "." happens before this, and jumps over the rest of the function.

Oh! It did work, but the messages are confusing.

# cat /sys/kernel/security/integrity/evm/evm_xattrs 
security.selinux
security.ima
security.capability
security.foo
# echo foo > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted
# echo security.foo > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted
# cat /sys/kernel/security/integrity/evm/evm_xattrs 
security.selinux
security.ima
security.capability
security.foo
# echo . > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted
# echo security.boo > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted
# ls -lat //sys/kernel/security/integrity/evm/evm_xattrs
-rw-rw----. 1 root root 0 May 14 13:10
//sys/kernel/security/integrity/evm/evm_xattrs

"security.boo" wasn't added. So writing '.' worked, but the chmod did not work. Maybe the error messages are coming from there.

Mimi

#6 lore raw

Re: [PATCH V5 3/3] EVM: Allow runtime modification of the set of verified xattrs

Quoted 44 lines · Mimi Zohar
Quoted 30 lines · Matthew Garrett
Quoted 19 lines · Mimi Zohar

On Fri, 2018-05-11 at 16:12 -0700, Matthew Garrett wrote:
+

Quoted 17 lines
security/integrity/evm/evm_secfs.c +17 -0
+     if (strcmp(xattr->name, ".") == 0) {
+             evm_xattrs_locked = 1;
+             inode = evm_xattrs->d_inode;
+             inode_lock(inode);
+             newattrs.ia_mode = S_IFREG | 0440;
+             newattrs.ia_valid = ATTR_MODE;
+             err = notify_change(evm_xattrs, &newattrs, NULL);
+             inode_unlock(inode);
+             audit_log_format(ab, "locked");
+             if (!err)
+                     err = count;
+             goto out;
+     }
+
+     audit_log_format(ab, "xattr=");
+     audit_log_untrustedstring(ab, xattr->name);
+
Quoted 8 lines

security/integrity/evm/evm_secfs.c static const struct file_operations evm_key_ops = { · line 234

Quoted 5 lines
security/integrity/evm/evm_secfs.c +5 -0
+     if (strncmp(xattr->name, XATTR_SECURITY_PREFIX,
+                 XATTR_SECURITY_PREFIX_LEN) != 0) {
+             err = -EINVAL;
+             goto out;
+     }

This test now prevents locking the xattr names list. Making this an else clause will fix it.

Quoted 2 lines

Are you sure? The check for "." happens before this, and jumps over the rest of the function.

Oh! It did work, but the messages are confusing.

# cat /sys/kernel/security/integrity/evm/evm_xattrs 
security.selinux
security.ima
security.capability
security.foo
# echo foo > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted
Quoted 2 lines
# echo security.foo > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted

This makes sense, as it was already added.

Quoted 9 lines
# cat /sys/kernel/security/integrity/evm/evm_xattrs 
security.selinux
security.ima
security.capability
security.foo
# echo . > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted

I'm still seeing this message.

Mimi

#7 lore raw

Re: [PATCH V5 3/3] EVM: Allow runtime modification of the set of verified xattrs

Quoted 4 lines · Mimi Zohar
Quoted 2 lines
# echo . > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted

I'm still seeing this message.

Looking into it.

#8 lore raw

Re: [PATCH V5 3/3] EVM: Allow runtime modification of the set of verified xattrs

Quoted 8 lines · Matthew Garrett
Quoted 4 lines · Mimi Zohar
Quoted 2 lines
# echo . > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted

I'm still seeing this message.

Looking into it.

I can't reproduce this - the only way you should be getting EPERM is if the list is already locked or if you don't have CAP_SYS_ADMIN.

#9 lore raw

Re: [PATCH V5 3/3] EVM: Allow runtime modification of the set of verified xattrs

Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Matthew Garrett
Quoted 2 lines · Mimi Zohar
Quoted 2 lines
# echo . > /sys/kernel/security/integrity/evm/evm_xattrs
bash: echo: write error: Operation not permitted
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I'm still seeing this message.

Looking into it.

I can't reproduce this - the only way you should be getting EPERM is if the list is already locked or if you don't have CAP_SYS_ADMIN.

The call to notify_change() calls security_inode_setattr(), which is failing, because there is no security.evm xattr. It's failing with -EPERM.

Mimi

#10 lore raw

Re: [PATCH V5 3/3] EVM: Allow runtime modification of the set of verified xattrs

Quoted 3 lines · Mimi Zohar

The call to notify_change() calls security_inode_setattr(), which is failing, because there is no security.evm xattr. It's failing with -EPERM.

Ah! Ok yes that would explain it. Let me figure out how to do this reasonably...