EVM: Allow runtime modification of the set of verified xattrs
Subsystems (4)
PATCH v2 1/1 EVM: Allow runtime modification of the set of verified xattrs
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.
---
Mimi, annotating the list_head __ro_after_init doesn't work - adding entries after init will attempt to modify its ->prev pointer.
Documentation/ABI/testing/evm | 13 ++++ security/integrity/evm/evm.h | 7 +- security/integrity/evm/evm_crypto.c | 10 +-- security/integrity/evm/evm_main.c | 73 +++++++++++++++----- security/integrity/evm/evm_secfs.c | 102 ++++++++++++++++++++++++++-- 5 files changed, 176 insertions(+), 29 deletions(-)
Documentation/ABI/testing/evm +13 -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 +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. Adding additional extended attributes + will result in any existing signatures generated without the + additional attributes becoming invalid, and any signatures + generated after additional attributes are added will only be + valid if the same additional attributes are configured on + system boot.
security/integrity/evm/evm.h +6 -1
@@ -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
@@ -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 +56 -17
150 lines not on this page · raw message
security/integrity/evm/evm_secfs.c +96 -6
115 lines not on this page · raw message
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
Quoted 33 lines · Matthew Garrett
security/integrity/evm/evm_main.c +8
-2@@ -35,7 +35,7 @@ static const char * const integrity_status_msg[] = { };int evm_hmac_attrs; -char *evm_config_xattrnames[] = { +char *evm_config_default_xattrnames[] = {#ifdef CONFIG_SECURITY_SELINUX XATTR_NAME_SELINUX,#endif @@ -57,6 +57,8 @@ char *evm_config_xattrnames[] = { NULL }; +LIST_HEAD (evm_config_xattrnames); +static int evm_fixmode;static int __init evm_set_fixmode (char *str) {@@ -66,12 +68,30 @@ static int __init evm_set_fixmode(char *str) }__setup ("evm=" , evm_set_fixmode); -static void __init evm_init_config (void ) +static int __init evm_init_config (void ) { +struct xattr_list *tmp; +char **xattrname; + + for (xattrname = evm_config_default_xattrnames; *xattrname != NULL;
security/integrity/evm/evm_main.c static int __init evm_set_fixmode(char *str) · line 86
Quoted 10 lines
security/integrity/evm/evm_main.c +10
-0+ xattrname++) { + tmp =kmalloc (sizeof (struct xattr_list ),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + tmp->name =kstrdup (*xattrname,GFP_KERNEL ); +if (!tmp->name) { +kfree (tmp); +return -ENOMEM ; + } +list_add_tail (&tmp->list, &evm_config_xattrnames);
If evm_config_xattrnames[] is defined as struct xattr_list, there's no need for allocating memory for the xattr_list and name. Something like in ima_init_policy() would work.
Could we break this patch up to simplify review? The first patch would create and use the xattrname list. The subsequent patch(es) would add the new functionality.
thanks,
Mimi
Quoted 12 lines
security/integrity/evm/evm_main.c +4
-0+ } +#ifdef CONFIG_EVM_ATTR_FSUUID evm_hmac_attrs |=EVM_ATTR_FSUUID ;#endif pr_info ("HMAC attrs: 0x%x\n" , evm_hmac_attrs); + +return 0 ; }static bool evm_key_loaded (void )
Quoted 2 lines · Mimi Zohar
Quoted 1 line · Matthew Garrett
+ for (xattrname =
evm_config_default_xattrnames; *xattrname !=
NULL;
Quoted 11 lines
security/integrity/evm/evm_main.c static int __init evm_set_fixmode(char *str) · line 86
Quoted 10 lines
security/integrity/evm/evm_main.c +10
-0+ xattrname++) { + tmp =kmalloc (sizeof (struct xattr_list ),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + tmp->name =kstrdup (*xattrname,GFP_KERNEL ); +if (!tmp->name) { +kfree (tmp); +return -ENOMEM ; + } +list_add_tail (&tmp->list, &evm_config_xattrnames);
Quoted 3 lines
If evm_config_xattrnames[] is defined as struct
xattr_list, there's no need for allocating memory for thexattr_listand name. Something like inima_init_policy()would work.
Hm. Do you mean evm_config_default_xattrnames?
Quoted 3 lines
Could we break this patch up to simplify review? The first patch would create and use the xattrname list. The subsequent patch(es) would add the new functionality.
Sure, I'll do that.
Quoted 16 lines · Matthew Garrett
Quoted 2 lines · Mimi Zohar
Quoted 1 line · Matthew Garrett
+ for (xattrname =
evm_config_default_xattrnames; *xattrname !=NULL;
Quoted 10 lines
Quoted 10 lines
security/integrity/evm/evm_main.c +10
-0+ xattrname++) { + tmp =kmalloc (sizeof (struct xattr_list ),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + tmp->name =kstrdup (*xattrname,GFP_KERNEL ); +if (!tmp->name) { +kfree (tmp); +return -ENOMEM ; + } +list_add_tail (&tmp->list, &evm_config_xattrnames);
Quoted 5 lines
Quoted 3 lines
If evm_config_xattrnames[] is defined as struct
xattr_list, there's no need for allocating memory for thexattr_listand name. Something like inima_init_policy()would work.Hm. Do you mean
evm_config_default_xattrnames?
Yes, or:
for (i = 0; i < secure_boot_entries; i++)
list_add_tail(&secure_boot_rules[i].list,
&ima_default_rules);Quoted 6 lines
Quoted 4 lines
Could we break this patch up to simplify review? The first patch would create and use the xattrname list. The subsequent patch(es) would add the new functionality.
Sure, I'll do that.
thanks!
Mimi