@@ -78,6 +78,8 @@ choice
bool "ima-sig"
config IMA_DEP_CGN_TEMPLATE
bool "ima-dep-cgn"
+ config IMA_CGPATH_TEMPLATE
+ bool "ima-cgpath"
endchoice
config IMA_DEFAULT_TEMPLATE
@@ -86,6 +88,7 @@ config IMA_DEFAULT_TEMPLATE
default "ima-ng" if IMA_NG_TEMPLATE
default "ima-sig" if IMA_SIG_TEMPLATE
default "ima-dep-cgn" if IMA_DEP_CGN_TEMPLATE
+ default "ima-cgpath" if IMA_CGPATH_TEMPLATE
choice
prompt "Default integrity hash algorithm"
@@ -27,6 +27,7 @@ static struct ima_template_desc builtin_templates[] = {
{.name = "evm-sig",
.fmt = "d-ng|n-ng|evmsig|xattrnames|xattrlengths|xattrvalues|iuid|igid|imode"},
{.name = "ima-dep-cgn", .fmt = "dep|cgn|d-ng|n-ng"},
+ {.name = "ima-cgpath", .fmt = "dep|cg-path|d-ng|n-ng"},
{.name = "", .fmt = ""}, /* placeholder for a custom format */
};
@@ -74,6 +75,8 @@ static const struct ima_template_field supported_fields[] = {
.field_show = ima_show_template_string},
{.field_id = "dep", .field_init = ima_eventdep_init,
.field_show = ima_show_template_string},
+ {.field_id = "cg-path", .field_init = ima_eventcg_path_init,
+ .field_show = ima_show_template_string},
};
/*
@@ -838,3 +838,34 @@ int ima_eventdep_init(struct ima_event_data *event_data,
return rc;
}
+
+/*
+ * ima_eventcg_path_init - include the current task's subsys_id=1 cgroup path as part of the
+ * template data
+ */
+int ima_eventcg_path_init(struct ima_event_data *event_data,
+ struct ima_field_data *field_data)
+{
+ char *cgroup_path_str = NULL;
+ struct cgroup *cgroup = NULL;
+ int rc = 0;
+
+ cgroup_path_str = kmalloc(PATH_MAX, GFP_KERNEL);
+
+ if (!cgroup_path_str)
+ return -ENOMEM;
+
+ cgroup = task_cgroup(current, 1);
+ if (!cgroup)
+ goto out;
+
+ rc = cgroup_path(cgroup, cgroup_path_str, PATH_MAX);
+ if (!rc)
+ goto out;
+
+ rc = ima_write_template_field_data(cgroup_path_str, strlen(cgroup_path_str), DATA_FMT_STRING, field_data);
+ kfree(cgroup_path_str);
+ return rc;
+out:
+ return ima_write_template_field_data("-", 1, DATA_FMT_STRING, field_data);
+}
@@ -70,4 +70,6 @@ int ima_eventcgn_init(struct ima_event_data *event_data,
struct ima_field_data *field_data);
int ima_eventdep_init(struct ima_event_data *event_data,
struct ima_field_data *field_data);
+int ima_eventcg_path_init(struct ima_event_data *event_data,
+ struct ima_field_data *field_data);
#endif /* __LINUX_IMA_TEMPLATE_LIB_H */