Skip to content

Commit 026d7fc

Browse files
robertosassumimizohar
authored andcommitted
ima: Introduce template field evmsig and write to field sig as fallback
With the patch to accept EVM portable signatures when the appraise_type=imasig requirement is specified in the policy, appraisal can be successfully done even if the file does not have an IMA signature. However, remote attestation would not see that a different signature type was used, as only IMA signatures can be included in the measurement list. This patch solves the issue by introducing the new template field 'evmsig' to show EVM portable signatures and by including its value in the existing field 'sig' if the IMA signature is not found. Suggested-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 7aa5783 commit 026d7fc

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

Documentation/security/IMA-templates.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ descriptors by adding their identifier to the format string
7070
prefix is shown only if the hash algorithm is not SHA1 or MD5);
7171
- 'd-modsig': the digest of the event without the appended modsig;
7272
- 'n-ng': the name of the event, without size limitations;
73-
- 'sig': the file signature;
73+
- 'sig': the file signature, or the EVM portable signature if the file
74+
signature is not found;
7475
- 'modsig' the appended file signature;
7576
- 'buf': the buffer data that was used to generate the hash without size limitations;
77+
- 'evmsig': the EVM portable signature;
7678

7779

7880
Below, there is the list of defined template descriptors:

security/integrity/ima/ima_template.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static const struct ima_template_field supported_fields[] = {
4545
.field_show = ima_show_template_digest_ng},
4646
{.field_id = "modsig", .field_init = ima_eventmodsig_init,
4747
.field_show = ima_show_template_sig},
48+
{.field_id = "evmsig", .field_init = ima_eventevmsig_init,
49+
.field_show = ima_show_template_sig},
4850
};
4951

5052
/*

security/integrity/ima/ima_template_lib.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include "ima_template_lib.h"
13+
#include <linux/xattr.h>
1314

1415
static bool ima_template_hash_algo_allowed(u8 algo)
1516
{
@@ -438,7 +439,7 @@ int ima_eventsig_init(struct ima_event_data *event_data,
438439
struct evm_ima_xattr_data *xattr_value = event_data->xattr_value;
439440

440441
if ((!xattr_value) || (xattr_value->type != EVM_IMA_XATTR_DIGSIG))
441-
return 0;
442+
return ima_eventevmsig_init(event_data, field_data);
442443

443444
return ima_write_template_field_data(xattr_value, event_data->xattr_len,
444445
DATA_FMT_HEX, field_data);
@@ -484,3 +485,33 @@ int ima_eventmodsig_init(struct ima_event_data *event_data,
484485
return ima_write_template_field_data(data, data_len, DATA_FMT_HEX,
485486
field_data);
486487
}
488+
489+
/*
490+
* ima_eventevmsig_init - include the EVM portable signature as part of the
491+
* template data
492+
*/
493+
int ima_eventevmsig_init(struct ima_event_data *event_data,
494+
struct ima_field_data *field_data)
495+
{
496+
struct evm_ima_xattr_data *xattr_data = NULL;
497+
int rc = 0;
498+
499+
if (!event_data->file)
500+
return 0;
501+
502+
rc = vfs_getxattr_alloc(&init_user_ns, file_dentry(event_data->file),
503+
XATTR_NAME_EVM, (char **)&xattr_data, 0,
504+
GFP_NOFS);
505+
if (rc <= 0)
506+
return 0;
507+
508+
if (xattr_data->type != EVM_XATTR_PORTABLE_DIGSIG) {
509+
kfree(xattr_data);
510+
return 0;
511+
}
512+
513+
rc = ima_write_template_field_data((char *)xattr_data, rc, DATA_FMT_HEX,
514+
field_data);
515+
kfree(xattr_data);
516+
return rc;
517+
}

security/integrity/ima/ima_template_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ int ima_eventbuf_init(struct ima_event_data *event_data,
4646
struct ima_field_data *field_data);
4747
int ima_eventmodsig_init(struct ima_event_data *event_data,
4848
struct ima_field_data *field_data);
49+
int ima_eventevmsig_init(struct ima_event_data *event_data,
50+
struct ima_field_data *field_data);
4951
#endif /* __LINUX_IMA_TEMPLATE_LIB_H */

0 commit comments

Comments
 (0)