Skip to content

Commit 7dcfeac

Browse files
robertosassumimizohar
authored andcommitted
ima: Define new template fields iuid and igid
This patch defines the new template fields iuid and igid, which include respectively the inode UID and GID. For idmapped mounts, still the original UID and GID are provided. These fields can be used 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> Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent cde1391 commit 7dcfeac

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

Documentation/security/IMA-templates.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ descriptors by adding their identifier to the format string
7575
- 'modsig' the appended file signature;
7676
- 'buf': the buffer data that was used to generate the hash without size limitations;
7777
- 'evmsig': the EVM portable signature;
78+
- 'iuid': the inode UID;
79+
- 'igid': the inode GID;
7880

7981

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

security/integrity/ima/ima_template.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ static const struct ima_template_field supported_fields[] = {
4747
.field_show = ima_show_template_sig},
4848
{.field_id = "evmsig", .field_init = ima_eventevmsig_init,
4949
.field_show = ima_show_template_sig},
50+
{.field_id = "iuid", .field_init = ima_eventinodeuid_init,
51+
.field_show = ima_show_template_uint},
52+
{.field_id = "igid", .field_init = ima_eventinodegid_init,
53+
.field_show = ima_show_template_uint},
5054
};
5155

5256
/*

security/integrity/ima/ima_template_lib.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,48 @@ int ima_eventevmsig_init(struct ima_event_data *event_data,
551551
kfree(xattr_data);
552552
return rc;
553553
}
554+
555+
static int ima_eventinodedac_init_common(struct ima_event_data *event_data,
556+
struct ima_field_data *field_data,
557+
bool get_uid)
558+
{
559+
unsigned int id;
560+
561+
if (!event_data->file)
562+
return 0;
563+
564+
if (get_uid)
565+
id = i_uid_read(file_inode(event_data->file));
566+
else
567+
id = i_gid_read(file_inode(event_data->file));
568+
569+
if (ima_canonical_fmt) {
570+
if (sizeof(id) == sizeof(u16))
571+
id = cpu_to_le16(id);
572+
else
573+
id = cpu_to_le32(id);
574+
}
575+
576+
return ima_write_template_field_data((void *)&id, sizeof(id),
577+
DATA_FMT_UINT, field_data);
578+
}
579+
580+
/*
581+
* ima_eventinodeuid_init - include the inode UID as part of the template
582+
* data
583+
*/
584+
int ima_eventinodeuid_init(struct ima_event_data *event_data,
585+
struct ima_field_data *field_data)
586+
{
587+
return ima_eventinodedac_init_common(event_data, field_data, true);
588+
}
589+
590+
/*
591+
* ima_eventinodegid_init - include the inode GID as part of the template
592+
* data
593+
*/
594+
int ima_eventinodegid_init(struct ima_event_data *event_data,
595+
struct ima_field_data *field_data)
596+
{
597+
return ima_eventinodedac_init_common(event_data, field_data, false);
598+
}

security/integrity/ima/ima_template_lib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ int ima_eventmodsig_init(struct ima_event_data *event_data,
5050
struct ima_field_data *field_data);
5151
int ima_eventevmsig_init(struct ima_event_data *event_data,
5252
struct ima_field_data *field_data);
53+
int ima_eventinodeuid_init(struct ima_event_data *event_data,
54+
struct ima_field_data *field_data);
55+
int ima_eventinodegid_init(struct ima_event_data *event_data,
56+
struct ima_field_data *field_data);
5357
#endif /* __LINUX_IMA_TEMPLATE_LIB_H */

0 commit comments

Comments
 (0)