Skip to content

Commit f8216f6

Browse files
robertosassumimizohar
authored andcommitted
ima: Define new template field imode
This patch defines the new template field imode, which includes the inode mode. It can be used by a remote verifier to verify the EVM portable signature, if it was included with the template fields sig or evmsig. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 7dcfeac commit f8216f6

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

Documentation/security/IMA-templates.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ descriptors by adding their identifier to the format string
7777
- 'evmsig': the EVM portable signature;
7878
- 'iuid': the inode UID;
7979
- 'igid': the inode GID;
80+
- 'imode': the inode mode;
8081

8182

8283
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
@@ -51,6 +51,8 @@ static const struct ima_template_field supported_fields[] = {
5151
.field_show = ima_show_template_uint},
5252
{.field_id = "igid", .field_init = ima_eventinodegid_init,
5353
.field_show = ima_show_template_uint},
54+
{.field_id = "imode", .field_init = ima_eventinodemode_init,
55+
.field_show = ima_show_template_uint},
5456
};
5557

5658
/*

security/integrity/ima/ima_template_lib.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,3 +596,25 @@ int ima_eventinodegid_init(struct ima_event_data *event_data,
596596
{
597597
return ima_eventinodedac_init_common(event_data, field_data, false);
598598
}
599+
600+
/*
601+
* ima_eventinodemode_init - include the inode mode as part of the template
602+
* data
603+
*/
604+
int ima_eventinodemode_init(struct ima_event_data *event_data,
605+
struct ima_field_data *field_data)
606+
{
607+
struct inode *inode;
608+
umode_t mode;
609+
610+
if (!event_data->file)
611+
return 0;
612+
613+
inode = file_inode(event_data->file);
614+
mode = inode->i_mode;
615+
if (ima_canonical_fmt)
616+
mode = cpu_to_le16(mode);
617+
618+
return ima_write_template_field_data((char *)&mode, sizeof(mode),
619+
DATA_FMT_UINT, field_data);
620+
}

security/integrity/ima/ima_template_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ int ima_eventinodeuid_init(struct ima_event_data *event_data,
5454
struct ima_field_data *field_data);
5555
int ima_eventinodegid_init(struct ima_event_data *event_data,
5656
struct ima_field_data *field_data);
57+
int ima_eventinodemode_init(struct ima_event_data *event_data,
58+
struct ima_field_data *field_data);
5759
#endif /* __LINUX_IMA_TEMPLATE_LIB_H */

0 commit comments

Comments
 (0)