Example #1
0
/*
 * evm_verify_hmac - calculate and compare the HMAC with the EVM xattr
 *
 * Compute the HMAC on the dentry's protected set of extended attributes
 * and compare it against the stored security.evm xattr.
 *
 * For performance:
 * - use the previoulsy retrieved xattr value and length to calculate the
 *   HMAC.)
 * - cache the verification result in the iint, when available.
 *
 * Returns integrity status
 */
static enum integrity_status evm_verify_hmac(struct dentry *dentry,
					     const char *xattr_name,
					     char *xattr_value,
					     size_t xattr_value_len,
					     struct integrity_iint_cache *iint)
{
	struct evm_ima_xattr_data xattr_data;
	enum integrity_status evm_status = INTEGRITY_PASS;
	int rc;

	if (iint && iint->evm_status == INTEGRITY_PASS)
		return iint->evm_status;

	/* if status is not PASS, try to check again - against -ENOMEM */

	rc = evm_calc_hmac(dentry, xattr_name, xattr_value,
			   xattr_value_len, xattr_data.digest);
	if (rc < 0) {
		evm_status = (rc == -ENODATA)
		    ? INTEGRITY_NOXATTRS : INTEGRITY_FAIL;
		goto out;
	}

	xattr_data.type = EVM_XATTR_HMAC;
	rc = vfs_xattr_cmp(dentry, XATTR_NAME_EVM, (u8 *)&xattr_data,
			   sizeof xattr_data, GFP_NOFS);
	if (rc < 0)
		evm_status = (rc == -ENODATA)
		    ? INTEGRITY_NOLABEL : INTEGRITY_FAIL;
out:
	if (iint)
		iint->evm_status = evm_status;
	return evm_status;
}
Example #2
0
/*
 * evm_verify_hmac - calculate and compare the HMAC with the EVM xattr
 *
 * Compute the HMAC on the dentry's protected set of extended attributes
 * and compare it against the stored security.evm xattr.
 *
 * For performance:
 * - use the previoulsy retrieved xattr value and length to calculate the
 *   HMAC.)
 * - cache the verification result in the iint, when available.
 *
 * Returns integrity status
 */
static enum integrity_status evm_verify_hmac(struct dentry *dentry,
					     const char *xattr_name,
					     char *xattr_value,
					     size_t xattr_value_len,
					     struct integrity_iint_cache *iint)
{
	struct evm_ima_xattr_data xattr_data;
	enum integrity_status evm_status;
	int rc;

	if (iint && iint->evm_status == INTEGRITY_PASS)
		return iint->evm_status;

	/* if status is not PASS, try to check again - against -ENOMEM */

	rc = evm_calc_hmac(dentry, xattr_name, xattr_value,
			   xattr_value_len, xattr_data.digest);
	if (rc < 0)
		goto err_out;

	xattr_data.type = EVM_XATTR_HMAC;
	rc = vfs_xattr_cmp(dentry, XATTR_NAME_EVM, (u8 *)&xattr_data,
			   sizeof xattr_data, GFP_NOFS);
	if (rc < 0)
		goto err_out;
	evm_status = INTEGRITY_PASS;
	goto out;

err_out:
	switch (rc) {
	case -ENODATA:		/* file not labelled */
		evm_status = INTEGRITY_NOLABEL;
		break;
	default:
		evm_status = INTEGRITY_FAIL;
	}
out:
	if (iint)
		iint->evm_status = evm_status;
	return evm_status;
}