Skip to content

Commit 00d535a

Browse files
committed
Merge branch 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull integrity updates from James Morris: "From Mimi: - add run time support for specifying additional security xattrs included in the security.evm HMAC/signature - some code clean up and bug fixes" * 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: EVM: unlock on error path in evm_read_xattrs() EVM: prevent array underflow in evm_write_xattrs() EVM: Fix null dereference on xattr when xattr fails to allocate EVM: fix memory leak of temporary buffer 'temp' IMA: use list_splice_tail_init_rcu() instead of its open coded variant ima: use match_string() helper ima: fix updating the ima_appraise flag ima: based on policy verify firmware signatures (pre-allocated buffer) ima: define a new policy condition based on the filesystem name EVM: Allow runtime modification of the set of verified xattrs EVM: turn evm_config_xattrnames into a list integrity: Add an integrity directory in securityfs ima: Remove unused variable ima_initialized ima: Unify logging ima: Reflect correct permissions for policy
2 parents 289cf15 + b5c90a7 commit 00d535a

File tree

16 files changed

+377
-84
lines changed

16 files changed

+377
-84
lines changed

Documentation/ABI/testing/evm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,16 @@ Description:
5757
dracut (via 97masterkey and 98integrity) and systemd (via
5858
core/ima-setup) have support for loading keys at boot
5959
time.
60+
61+
What: security/integrity/evm/evm_xattrs
62+
Date: April 2018
63+
Contact: Matthew Garrett <[email protected]>
64+
Description:
65+
Shows the set of extended attributes used to calculate or
66+
validate the EVM signature, and allows additional attributes
67+
to be added at runtime. Any signatures generated after
68+
additional attributes are added (and on files posessing those
69+
additional attributes) will only be valid if the same
70+
additional attributes are configured on system boot. Writing
71+
a single period (.) will lock the xattr list from any further
72+
modification.

Documentation/ABI/testing/ima_policy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Description:
2121
audit | hash | dont_hash
2222
condition:= base | lsm [option]
2323
base: [[func=] [mask=] [fsmagic=] [fsuuid=] [uid=]
24-
[euid=] [fowner=]]
24+
[euid=] [fowner=] [fsname=]]
2525
lsm: [[subj_user=] [subj_role=] [subj_type=]
2626
[obj_user=] [obj_role=] [obj_type=]]
2727
option: [[appraise_type=]] [permit_directio]

include/uapi/linux/audit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
#define AUDIT_INTEGRITY_HASH 1803 /* Integrity HASH type */
148148
#define AUDIT_INTEGRITY_PCR 1804 /* PCR invalidation msgs */
149149
#define AUDIT_INTEGRITY_RULE 1805 /* policy rule */
150+
#define AUDIT_INTEGRITY_EVM_XATTR 1806 /* New EVM-covered xattr */
150151

151152
#define AUDIT_KERNEL 2000 /* Asynchronous audit record. NOT A REQUEST. */
152153

security/integrity/evm/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ config EVM_EXTRA_SMACK_XATTRS
4242
additional info to the calculation, requires existing EVM
4343
labeled file systems to be relabeled.
4444

45+
config EVM_ADD_XATTRS
46+
bool "Add additional EVM extended attributes at runtime"
47+
depends on EVM
48+
default n
49+
help
50+
Allow userland to provide additional xattrs for HMAC calculation.
51+
52+
When this option is enabled, root can add additional xattrs to the
53+
list used by EVM by writing them into
54+
/sys/kernel/security/integrity/evm/evm_xattrs.
55+
4556
config EVM_LOAD_X509
4657
bool "Load an X509 certificate onto the '.evm' trusted keyring"
4758
depends on EVM && INTEGRITY_TRUSTED_KEYRING

security/integrity/evm/evm.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
#define EVM_INIT_MASK (EVM_INIT_HMAC | EVM_INIT_X509 | EVM_SETUP_COMPLETE | \
3131
EVM_ALLOW_METADATA_WRITES)
3232

33+
struct xattr_list {
34+
struct list_head list;
35+
char *name;
36+
};
37+
3338
extern int evm_initialized;
3439

3540
#define EVM_ATTR_FSUUID 0x0001
@@ -40,7 +45,7 @@ extern struct crypto_shash *hmac_tfm;
4045
extern struct crypto_shash *hash_tfm;
4146

4247
/* List of EVM protected security xattrs */
43-
extern char *evm_config_xattrnames[];
48+
extern struct list_head evm_config_xattrnames;
4449

4550
int evm_init_key(void);
4651
int evm_update_evmxattr(struct dentry *dentry,

security/integrity/evm/evm_crypto.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
192192
char type, char *digest)
193193
{
194194
struct inode *inode = d_backing_inode(dentry);
195+
struct xattr_list *xattr;
195196
struct shash_desc *desc;
196-
char **xattrname;
197197
size_t xattr_size = 0;
198198
char *xattr_value = NULL;
199199
int error;
@@ -209,22 +209,22 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
209209
return PTR_ERR(desc);
210210

211211
error = -ENODATA;
212-
for (xattrname = evm_config_xattrnames; *xattrname != NULL; xattrname++) {
212+
list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) {
213213
bool is_ima = false;
214214

215-
if (strcmp(*xattrname, XATTR_NAME_IMA) == 0)
215+
if (strcmp(xattr->name, XATTR_NAME_IMA) == 0)
216216
is_ima = true;
217217

218218
if ((req_xattr_name && req_xattr_value)
219-
&& !strcmp(*xattrname, req_xattr_name)) {
219+
&& !strcmp(xattr->name, req_xattr_name)) {
220220
error = 0;
221221
crypto_shash_update(desc, (const u8 *)req_xattr_value,
222222
req_xattr_value_len);
223223
if (is_ima)
224224
ima_present = true;
225225
continue;
226226
}
227-
size = vfs_getxattr_alloc(dentry, *xattrname,
227+
size = vfs_getxattr_alloc(dentry, xattr->name,
228228
&xattr_value, xattr_size, GFP_NOFS);
229229
if (size == -ENOMEM) {
230230
error = -ENOMEM;

security/integrity/evm/evm_main.c

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,29 @@ static const char * const integrity_status_msg[] = {
3535
};
3636
int evm_hmac_attrs;
3737

38-
char *evm_config_xattrnames[] = {
38+
static struct xattr_list evm_config_default_xattrnames[] = {
3939
#ifdef CONFIG_SECURITY_SELINUX
40-
XATTR_NAME_SELINUX,
40+
{.name = XATTR_NAME_SELINUX},
4141
#endif
4242
#ifdef CONFIG_SECURITY_SMACK
43-
XATTR_NAME_SMACK,
43+
{.name = XATTR_NAME_SMACK},
4444
#ifdef CONFIG_EVM_EXTRA_SMACK_XATTRS
45-
XATTR_NAME_SMACKEXEC,
46-
XATTR_NAME_SMACKTRANSMUTE,
47-
XATTR_NAME_SMACKMMAP,
45+
{.name = XATTR_NAME_SMACKEXEC},
46+
{.name = XATTR_NAME_SMACKTRANSMUTE},
47+
{.name = XATTR_NAME_SMACKMMAP},
4848
#endif
4949
#endif
5050
#ifdef CONFIG_SECURITY_APPARMOR
51-
XATTR_NAME_APPARMOR,
51+
{.name = XATTR_NAME_APPARMOR},
5252
#endif
5353
#ifdef CONFIG_IMA_APPRAISE
54-
XATTR_NAME_IMA,
54+
{.name = XATTR_NAME_IMA},
5555
#endif
56-
XATTR_NAME_CAPS,
57-
NULL
56+
{.name = XATTR_NAME_CAPS},
5857
};
5958

59+
LIST_HEAD(evm_config_xattrnames);
60+
6061
static int evm_fixmode;
6162
static int __init evm_set_fixmode(char *str)
6263
{
@@ -68,6 +69,17 @@ __setup("evm=", evm_set_fixmode);
6869

6970
static void __init evm_init_config(void)
7071
{
72+
int i, xattrs;
73+
74+
xattrs = ARRAY_SIZE(evm_config_default_xattrnames);
75+
76+
pr_info("Initialising EVM extended attributes:\n");
77+
for (i = 0; i < xattrs; i++) {
78+
pr_info("%s\n", evm_config_default_xattrnames[i].name);
79+
list_add_tail(&evm_config_default_xattrnames[i].list,
80+
&evm_config_xattrnames);
81+
}
82+
7183
#ifdef CONFIG_EVM_ATTR_FSUUID
7284
evm_hmac_attrs |= EVM_ATTR_FSUUID;
7385
#endif
@@ -82,15 +94,15 @@ static bool evm_key_loaded(void)
8294
static int evm_find_protected_xattrs(struct dentry *dentry)
8395
{
8496
struct inode *inode = d_backing_inode(dentry);
85-
char **xattr;
97+
struct xattr_list *xattr;
8698
int error;
8799
int count = 0;
88100

89101
if (!(inode->i_opflags & IOP_XATTR))
90102
return -EOPNOTSUPP;
91103

92-
for (xattr = evm_config_xattrnames; *xattr != NULL; xattr++) {
93-
error = __vfs_getxattr(dentry, inode, *xattr, NULL, 0);
104+
list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) {
105+
error = __vfs_getxattr(dentry, inode, xattr->name, NULL, 0);
94106
if (error < 0) {
95107
if (error == -ENODATA)
96108
continue;
@@ -211,24 +223,25 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,
211223

212224
static int evm_protected_xattr(const char *req_xattr_name)
213225
{
214-
char **xattrname;
215226
int namelen;
216227
int found = 0;
228+
struct xattr_list *xattr;
217229

218230
namelen = strlen(req_xattr_name);
219-
for (xattrname = evm_config_xattrnames; *xattrname != NULL; xattrname++) {
220-
if ((strlen(*xattrname) == namelen)
221-
&& (strncmp(req_xattr_name, *xattrname, namelen) == 0)) {
231+
list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) {
232+
if ((strlen(xattr->name) == namelen)
233+
&& (strncmp(req_xattr_name, xattr->name, namelen) == 0)) {
222234
found = 1;
223235
break;
224236
}
225237
if (strncmp(req_xattr_name,
226-
*xattrname + XATTR_SECURITY_PREFIX_LEN,
238+
xattr->name + XATTR_SECURITY_PREFIX_LEN,
227239
strlen(req_xattr_name)) == 0) {
228240
found = 1;
229241
break;
230242
}
231243
}
244+
232245
return found;
233246
}
234247

@@ -544,35 +557,35 @@ void __init evm_load_x509(void)
544557
static int __init init_evm(void)
545558
{
546559
int error;
560+
struct list_head *pos, *q;
561+
struct xattr_list *xattr;
547562

548563
evm_init_config();
549564

550565
error = integrity_init_keyring(INTEGRITY_KEYRING_EVM);
551566
if (error)
552-
return error;
567+
goto error;
553568

554569
error = evm_init_secfs();
555570
if (error < 0) {
556571
pr_info("Error registering secfs\n");
557-
return error;
572+
goto error;
558573
}
559574

560-
return 0;
561-
}
562-
563-
/*
564-
* evm_display_config - list the EVM protected security extended attributes
565-
*/
566-
static int __init evm_display_config(void)
567-
{
568-
char **xattrname;
575+
error:
576+
if (error != 0) {
577+
if (!list_empty(&evm_config_xattrnames)) {
578+
list_for_each_safe(pos, q, &evm_config_xattrnames) {
579+
xattr = list_entry(pos, struct xattr_list,
580+
list);
581+
list_del(pos);
582+
}
583+
}
584+
}
569585

570-
for (xattrname = evm_config_xattrnames; *xattrname != NULL; xattrname++)
571-
pr_info("%s\n", *xattrname);
572-
return 0;
586+
return error;
573587
}
574588

575-
pure_initcall(evm_display_config);
576589
late_initcall(init_evm);
577590

578591
MODULE_DESCRIPTION("Extended Verification Module");

0 commit comments

Comments
 (0)