Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bcbc9b0c authored by Mimi Zohar's avatar Mimi Zohar
Browse files

ima: extend the measurement list to include the file signature



This patch defines a new template called 'ima-sig', which includes
the file signature in the template data, in addition to the file's
digest and pathname.

A template is composed of a set of fields.  Associated with each
field is an initialization and display function.  This patch defines
a new template field called 'sig', the initialization function
ima_eventsig_init(), and the display function ima_show_template_sig().

This patch modifies the .field_init() function definition to include
the 'security.ima' extended attribute and length.

Changelog:
- remove unused code (Dmitry Kasatkin)
- avoid calling ima_write_template_field_data() unnecesarily (Roberto Sassu)
- rename DATA_FMT_SIG to DATA_FMT_HEX
- cleanup ima_eventsig_init() based on Roberto's comments

Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
Signed-off-by: default avatarDmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: default avatarRoberto Sassu <roberto.sassu@polito.it>
parent 42a20ba5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ choice
		bool "ima"
	config IMA_NG_TEMPLATE
		bool "ima-ng (default)"
	config IMA_SIG_TEMPLATE
		bool "ima-sig"
endchoice

config IMA_DEFAULT_TEMPLATE
@@ -70,6 +72,7 @@ config IMA_DEFAULT_TEMPLATE
	depends on IMA
	default "ima" if IMA_TEMPLATE
	default "ima-ng" if IMA_NG_TEMPLATE
	default "ima-sig" if IMA_SIG_TEMPLATE

choice
	prompt "Default integrity hash algorithm"
+7 −3
Original line number Diff line number Diff line
@@ -59,7 +59,8 @@ struct ima_template_field {
	const char field_id[IMA_TEMPLATE_FIELD_ID_MAX_LEN];
	int (*field_init) (struct integrity_iint_cache *iint, struct file *file,
			   const unsigned char *filename,
			   struct ima_field_data *field_data);
			   struct evm_ima_xattr_data *xattr_value,
			   int xattr_len, struct ima_field_data *field_data);
	void (*field_show) (struct seq_file *m, enum ima_show_type show,
			    struct ima_field_data *field_data);
};
@@ -134,12 +135,15 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
			    struct evm_ima_xattr_data **xattr_value,
			    int *xattr_len);
void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file,
			   const unsigned char *filename);
			   const unsigned char *filename,
			   struct evm_ima_xattr_data *xattr_value,
			   int xattr_len);
void ima_audit_measurement(struct integrity_iint_cache *iint,
			   const unsigned char *filename);
int ima_alloc_init_template(struct integrity_iint_cache *iint,
			    struct file *file, const unsigned char *filename,
			    struct ima_template_entry **entry);
			    struct evm_ima_xattr_data *xattr_value,
			    int xattr_len, struct ima_template_entry **entry);
int ima_store_template(struct ima_template_entry *entry, int violation,
		       struct inode *inode, const unsigned char *filename);
const char *ima_d_path(struct path *path, char **pathbuf);
+10 −4
Original line number Diff line number Diff line
@@ -26,7 +26,8 @@
 */
int ima_alloc_init_template(struct integrity_iint_cache *iint,
			    struct file *file, const unsigned char *filename,
			    struct ima_template_entry **entry)
			    struct evm_ima_xattr_data *xattr_value,
			    int xattr_len, struct ima_template_entry **entry)
{
	struct ima_template_desc *template_desc = ima_template_desc_current();
	int i, result = 0;
@@ -41,6 +42,7 @@ int ima_alloc_init_template(struct integrity_iint_cache *iint,
		u32 len;

		result = field->field_init(iint, file, filename,
					   xattr_value, xattr_len,
					   &((*entry)->template_data[i]));
		if (result != 0)
			goto out;
@@ -123,7 +125,8 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
	/* can overflow, only indicator */
	atomic_long_inc(&ima_htable.violations);

	result = ima_alloc_init_template(NULL, file, filename, &entry);
	result = ima_alloc_init_template(NULL, file, filename,
					 NULL, 0, &entry);
	if (result < 0) {
		result = -ENOMEM;
		goto err_out;
@@ -239,7 +242,9 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
 * Must be called with iint->mutex held.
 */
void ima_store_measurement(struct integrity_iint_cache *iint,
			   struct file *file, const unsigned char *filename)
			   struct file *file, const unsigned char *filename,
			   struct evm_ima_xattr_data *xattr_value,
			   int xattr_len)
{
	const char *op = "add_template_measure";
	const char *audit_cause = "ENOMEM";
@@ -251,7 +256,8 @@ void ima_store_measurement(struct integrity_iint_cache *iint,
	if (iint->flags & IMA_MEASURED)
		return;

	result = ima_alloc_init_template(iint, file, filename, &entry);
	result = ima_alloc_init_template(iint, file, filename,
					 xattr_value, xattr_len, &entry);
	if (result < 0) {
		integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode, filename,
				    op, audit_cause, result, 0);
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ static void __init ima_add_boot_aggregate(void)
	}

	result = ima_alloc_init_template(iint, NULL, boot_aggregate_name,
					 &entry);
					 NULL, 0, &entry);
	if (result < 0)
		return;

+2 −1
Original line number Diff line number Diff line
@@ -225,7 +225,8 @@ static int process_measurement(struct file *file, const char *filename,
		pathname = (const char *)file->f_dentry->d_name.name;

	if (action & IMA_MEASURE)
		ima_store_measurement(iint, file, pathname);
		ima_store_measurement(iint, file, pathname,
				      xattr_value, xattr_len);
	if (action & IMA_APPRAISE_SUBMASK)
		rc = ima_appraise_measurement(_func, iint, file, pathname,
					      xattr_value, xattr_len);
Loading