Skip to content

Commit 21af766

Browse files
mjg59Mimi Zohar
authored andcommitted
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. Signed-off-by: Matthew Garrett <[email protected]> Reviewed-by: James Morris <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 0c343af commit 21af766

File tree

3 files changed

+57
-39
lines changed

3 files changed

+57
-39
lines changed

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;
@@ -208,22 +208,22 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
208208
return PTR_ERR(desc);
209209

210210
error = -ENODATA;
211-
for (xattrname = evm_config_xattrnames; *xattrname != NULL; xattrname++) {
211+
list_for_each_entry(xattr, &evm_config_xattrnames, list) {
212212
bool is_ima = false;
213213

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

217217
if ((req_xattr_name && req_xattr_value)
218-
&& !strcmp(*xattrname, req_xattr_name)) {
218+
&& !strcmp(xattr->name, req_xattr_name)) {
219219
error = 0;
220220
crypto_shash_update(desc, (const u8 *)req_xattr_value,
221221
req_xattr_value_len);
222222
if (is_ima)
223223
ima_present = true;
224224
continue;
225225
}
226-
size = vfs_getxattr_alloc(dentry, *xattrname,
226+
size = vfs_getxattr_alloc(dentry, xattr->name,
227227
&xattr_value, xattr_size, GFP_NOFS);
228228
if (size == -ENOMEM) {
229229
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[] __ro_after_init = {
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(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(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)