2009-02-04 21:06:58 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 IBM Corporation
|
|
|
|
*
|
|
|
|
* Author: Mimi Zohar <zohar@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation, version 2 of the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* File: ima_api.c
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
* Implements must_appraise_or_measure, collect_measurement,
|
|
|
|
* appraise_measurement, store_measurement and store_template.
|
2009-02-04 21:06:58 +07:00
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/xattr.h>
|
|
|
|
#include <linux/evm.h>
|
2013-06-07 17:16:24 +07:00
|
|
|
#include <crypto/hash_info.h>
|
2009-02-04 21:06:58 +07:00
|
|
|
#include "ima.h"
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
|
2013-12-03 01:40:34 +07:00
|
|
|
/*
|
|
|
|
* ima_free_template_entry - free an existing template entry
|
|
|
|
*/
|
|
|
|
void ima_free_template_entry(struct ima_template_entry *entry)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < entry->template_desc->num_fields; i++)
|
|
|
|
kfree(entry->template_data[i].data);
|
|
|
|
|
|
|
|
kfree(entry);
|
|
|
|
}
|
|
|
|
|
2013-06-07 17:16:28 +07:00
|
|
|
/*
|
|
|
|
* ima_alloc_init_template - create and initialize a new template entry
|
|
|
|
*/
|
|
|
|
int ima_alloc_init_template(struct integrity_iint_cache *iint,
|
|
|
|
struct file *file, const unsigned char *filename,
|
2013-07-23 22:15:00 +07:00
|
|
|
struct evm_ima_xattr_data *xattr_value,
|
|
|
|
int xattr_len, struct ima_template_entry **entry)
|
2013-06-07 17:16:28 +07:00
|
|
|
{
|
2013-06-07 17:16:33 +07:00
|
|
|
struct ima_template_desc *template_desc = ima_template_desc_current();
|
|
|
|
int i, result = 0;
|
2013-06-07 17:16:28 +07:00
|
|
|
|
2013-06-07 17:16:33 +07:00
|
|
|
*entry = kzalloc(sizeof(**entry) + template_desc->num_fields *
|
|
|
|
sizeof(struct ima_field_data), GFP_NOFS);
|
|
|
|
if (!*entry)
|
2013-06-07 17:16:28 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-12-03 01:40:34 +07:00
|
|
|
(*entry)->template_desc = template_desc;
|
2013-06-07 17:16:33 +07:00
|
|
|
for (i = 0; i < template_desc->num_fields; i++) {
|
|
|
|
struct ima_template_field *field = template_desc->fields[i];
|
|
|
|
u32 len;
|
2013-06-07 17:16:28 +07:00
|
|
|
|
2013-06-07 17:16:33 +07:00
|
|
|
result = field->field_init(iint, file, filename,
|
2013-07-23 22:15:00 +07:00
|
|
|
xattr_value, xattr_len,
|
2013-06-07 17:16:33 +07:00
|
|
|
&((*entry)->template_data[i]));
|
|
|
|
if (result != 0)
|
|
|
|
goto out;
|
2013-06-07 17:16:28 +07:00
|
|
|
|
2013-06-07 17:16:33 +07:00
|
|
|
len = (*entry)->template_data[i].len;
|
|
|
|
(*entry)->template_data_len += sizeof(len);
|
|
|
|
(*entry)->template_data_len += len;
|
|
|
|
}
|
2013-06-07 17:16:28 +07:00
|
|
|
return 0;
|
2013-06-07 17:16:33 +07:00
|
|
|
out:
|
2013-12-03 01:40:34 +07:00
|
|
|
ima_free_template_entry(*entry);
|
2013-06-07 17:16:33 +07:00
|
|
|
*entry = NULL;
|
2013-06-07 17:16:28 +07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-02-04 21:06:58 +07:00
|
|
|
/*
|
|
|
|
* ima_store_template - store ima template measurements
|
|
|
|
*
|
|
|
|
* Calculate the hash of a template entry, add the template entry
|
|
|
|
* to an ordered list of measurement entries maintained inside the kernel,
|
|
|
|
* and also update the aggregate integrity value (maintained inside the
|
|
|
|
* configured TPM PCR) over the hashes of the current list of measurement
|
|
|
|
* entries.
|
|
|
|
*
|
|
|
|
* Applications retrieve the current kernel-held measurement list through
|
|
|
|
* the securityfs entries in /sys/kernel/security/ima. The signed aggregate
|
|
|
|
* TPM PCR (called quote) can be retrieved using a TPM user space library
|
|
|
|
* and is used to validate the measurement list.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, error code otherwise
|
|
|
|
*/
|
|
|
|
int ima_store_template(struct ima_template_entry *entry,
|
2013-06-07 17:16:27 +07:00
|
|
|
int violation, struct inode *inode,
|
|
|
|
const unsigned char *filename)
|
2009-02-04 21:06:58 +07:00
|
|
|
{
|
|
|
|
const char *op = "add_template_measure";
|
|
|
|
const char *audit_cause = "hashing_error";
|
2013-06-07 17:16:33 +07:00
|
|
|
char *template_name = entry->template_desc->name;
|
2009-02-04 21:06:58 +07:00
|
|
|
int result;
|
2013-04-25 14:44:04 +07:00
|
|
|
struct {
|
|
|
|
struct ima_digest_data hdr;
|
2013-03-12 07:29:47 +07:00
|
|
|
char digest[TPM_DIGEST_SIZE];
|
2013-04-25 14:44:04 +07:00
|
|
|
} hash;
|
2009-02-04 21:06:58 +07:00
|
|
|
|
|
|
|
if (!violation) {
|
2013-06-07 17:16:33 +07:00
|
|
|
int num_fields = entry->template_desc->num_fields;
|
|
|
|
|
2013-06-07 17:16:24 +07:00
|
|
|
/* this function uses default algo */
|
|
|
|
hash.hdr.algo = HASH_ALGO_SHA1;
|
2013-06-07 17:16:33 +07:00
|
|
|
result = ima_calc_field_array_hash(&entry->template_data[0],
|
2013-11-09 01:21:39 +07:00
|
|
|
entry->template_desc,
|
2013-06-07 17:16:33 +07:00
|
|
|
num_fields, &hash.hdr);
|
2009-02-04 21:06:58 +07:00
|
|
|
if (result < 0) {
|
|
|
|
integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode,
|
2013-06-07 17:16:33 +07:00
|
|
|
template_name, op,
|
2009-02-04 21:06:58 +07:00
|
|
|
audit_cause, result, 0);
|
|
|
|
return result;
|
|
|
|
}
|
2013-04-25 14:44:04 +07:00
|
|
|
memcpy(entry->digest, hash.hdr.digest, hash.hdr.length);
|
2009-02-04 21:06:58 +07:00
|
|
|
}
|
2013-06-07 17:16:27 +07:00
|
|
|
result = ima_add_template_entry(entry, violation, op, inode, filename);
|
2009-02-04 21:06:58 +07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ima_add_violation - add violation to measurement list.
|
|
|
|
*
|
|
|
|
* Violations are flagged in the measurement list with zero hash values.
|
|
|
|
* By extending the PCR with 0xFF's instead of with zeroes, the PCR
|
|
|
|
* value is invalidated.
|
|
|
|
*/
|
2013-06-07 17:16:26 +07:00
|
|
|
void ima_add_violation(struct file *file, const unsigned char *filename,
|
2009-02-04 21:06:58 +07:00
|
|
|
const char *op, const char *cause)
|
|
|
|
{
|
|
|
|
struct ima_template_entry *entry;
|
2013-06-07 17:16:26 +07:00
|
|
|
struct inode *inode = file->f_dentry->d_inode;
|
2009-02-04 21:06:58 +07:00
|
|
|
int violation = 1;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
/* can overflow, only indicator */
|
|
|
|
atomic_long_inc(&ima_htable.violations);
|
|
|
|
|
2013-07-23 22:15:00 +07:00
|
|
|
result = ima_alloc_init_template(NULL, file, filename,
|
|
|
|
NULL, 0, &entry);
|
2013-06-07 17:16:28 +07:00
|
|
|
if (result < 0) {
|
2009-02-04 21:06:58 +07:00
|
|
|
result = -ENOMEM;
|
|
|
|
goto err_out;
|
|
|
|
}
|
2013-06-07 17:16:27 +07:00
|
|
|
result = ima_store_template(entry, violation, inode, filename);
|
2009-02-04 21:06:58 +07:00
|
|
|
if (result < 0)
|
2013-12-03 01:40:34 +07:00
|
|
|
ima_free_template_entry(entry);
|
2009-02-04 21:06:58 +07:00
|
|
|
err_out:
|
|
|
|
integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode, filename,
|
|
|
|
op, cause, result, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-27 15:26:14 +07:00
|
|
|
* ima_get_action - appraise & measure decision based on policy.
|
2009-02-04 21:06:58 +07:00
|
|
|
* @inode: pointer to inode to measure
|
|
|
|
* @mask: contains the permission mask (MAY_READ, MAY_WRITE, MAY_EXECUTE)
|
2012-12-13 23:15:04 +07:00
|
|
|
* @function: calling function (FILE_CHECK, BPRM_CHECK, MMAP_CHECK, MODULE_CHECK)
|
2009-02-04 21:06:58 +07:00
|
|
|
*
|
|
|
|
* The policy is defined in terms of keypairs:
|
|
|
|
* subj=, obj=, type=, func=, mask=, fsmagic=
|
|
|
|
* subj,obj, and type: are LSM specific.
|
2012-12-13 23:15:04 +07:00
|
|
|
* func: FILE_CHECK | BPRM_CHECK | MMAP_CHECK | MODULE_CHECK
|
2009-02-04 21:06:58 +07:00
|
|
|
* mask: contains the permission mask
|
|
|
|
* fsmagic: hex value
|
|
|
|
*
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
* Returns IMA_MEASURE, IMA_APPRAISE mask.
|
|
|
|
*
|
|
|
|
*/
|
2012-06-27 15:26:14 +07:00
|
|
|
int ima_get_action(struct inode *inode, int mask, int function)
|
2009-02-04 21:06:58 +07:00
|
|
|
{
|
2012-06-15 00:04:36 +07:00
|
|
|
int flags = IMA_MEASURE | IMA_AUDIT | IMA_APPRAISE;
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
|
|
|
|
if (!ima_appraise)
|
|
|
|
flags &= ~IMA_APPRAISE;
|
|
|
|
|
|
|
|
return ima_match_policy(inode, function, mask, flags);
|
|
|
|
}
|
2009-02-04 21:06:58 +07:00
|
|
|
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
int ima_must_measure(struct inode *inode, int mask, int function)
|
|
|
|
{
|
|
|
|
return ima_match_policy(inode, function, mask, IMA_MEASURE);
|
2009-02-04 21:06:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ima_collect_measurement - collect file measurement
|
|
|
|
*
|
|
|
|
* Calculate the file hash, if it doesn't already exist,
|
|
|
|
* storing the measurement and i_version in the iint.
|
|
|
|
*
|
|
|
|
* Must be called with iint->mutex held.
|
|
|
|
*
|
|
|
|
* Return 0 on success, error code otherwise
|
|
|
|
*/
|
2011-03-10 02:13:22 +07:00
|
|
|
int ima_collect_measurement(struct integrity_iint_cache *iint,
|
2013-04-25 14:44:04 +07:00
|
|
|
struct file *file,
|
|
|
|
struct evm_ima_xattr_data **xattr_value,
|
|
|
|
int *xattr_len)
|
2009-02-04 21:06:58 +07:00
|
|
|
{
|
2013-01-24 05:07:38 +07:00
|
|
|
struct inode *inode = file_inode(file);
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
const char *filename = file->f_dentry->d_name.name;
|
|
|
|
int result = 0;
|
2013-04-25 14:44:04 +07:00
|
|
|
struct {
|
|
|
|
struct ima_digest_data hdr;
|
|
|
|
char digest[IMA_MAX_DIGEST_SIZE];
|
|
|
|
} hash;
|
2009-02-04 21:06:58 +07:00
|
|
|
|
2013-04-25 14:44:04 +07:00
|
|
|
if (xattr_value)
|
|
|
|
*xattr_len = ima_read_xattr(file->f_dentry, xattr_value);
|
|
|
|
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
if (!(iint->flags & IMA_COLLECTED)) {
|
2013-01-24 05:07:38 +07:00
|
|
|
u64 i_version = file_inode(file)->i_version;
|
2009-02-04 21:06:58 +07:00
|
|
|
|
2013-04-25 14:43:56 +07:00
|
|
|
/* use default hash algorithm */
|
2013-04-25 14:44:04 +07:00
|
|
|
hash.hdr.algo = ima_hash_algo;
|
2013-04-25 14:44:04 +07:00
|
|
|
|
|
|
|
if (xattr_value)
|
2013-04-25 14:44:04 +07:00
|
|
|
ima_get_hash_algo(*xattr_value, *xattr_len, &hash.hdr);
|
2013-04-25 14:44:04 +07:00
|
|
|
|
2013-04-25 14:44:04 +07:00
|
|
|
result = ima_calc_file_hash(file, &hash.hdr);
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
if (!result) {
|
2013-04-25 14:44:04 +07:00
|
|
|
int length = sizeof(hash.hdr) + hash.hdr.length;
|
|
|
|
void *tmpbuf = krealloc(iint->ima_hash, length,
|
|
|
|
GFP_NOFS);
|
|
|
|
if (tmpbuf) {
|
|
|
|
iint->ima_hash = tmpbuf;
|
|
|
|
memcpy(iint->ima_hash, &hash, length);
|
|
|
|
iint->version = i_version;
|
|
|
|
iint->flags |= IMA_COLLECTED;
|
|
|
|
} else
|
|
|
|
result = -ENOMEM;
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
}
|
2009-02-04 21:06:58 +07:00
|
|
|
}
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
if (result)
|
|
|
|
integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode,
|
|
|
|
filename, "collect_data", "failed",
|
|
|
|
result, 0);
|
2009-02-04 21:06:58 +07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ima_store_measurement - store file measurement
|
|
|
|
*
|
|
|
|
* Create an "ima" template and then store the template by calling
|
|
|
|
* ima_store_template.
|
|
|
|
*
|
|
|
|
* We only get here if the inode has not already been measured,
|
|
|
|
* but the measurement could already exist:
|
|
|
|
* - multiple copies of the same file on either the same or
|
|
|
|
* different filesystems.
|
|
|
|
* - the inode was previously flushed as well as the iint info,
|
|
|
|
* containing the hashing info.
|
|
|
|
*
|
|
|
|
* Must be called with iint->mutex held.
|
|
|
|
*/
|
2011-03-10 02:13:22 +07:00
|
|
|
void ima_store_measurement(struct integrity_iint_cache *iint,
|
2013-07-23 22:15:00 +07:00
|
|
|
struct file *file, const unsigned char *filename,
|
|
|
|
struct evm_ima_xattr_data *xattr_value,
|
|
|
|
int xattr_len)
|
2009-02-04 21:06:58 +07:00
|
|
|
{
|
|
|
|
const char *op = "add_template_measure";
|
|
|
|
const char *audit_cause = "ENOMEM";
|
|
|
|
int result = -ENOMEM;
|
2013-01-24 05:07:38 +07:00
|
|
|
struct inode *inode = file_inode(file);
|
2009-02-04 21:06:58 +07:00
|
|
|
struct ima_template_entry *entry;
|
|
|
|
int violation = 0;
|
|
|
|
|
ima: integrity appraisal extension
IMA currently maintains an integrity measurement list used to assert the
integrity of the running system to a third party. The IMA-appraisal
extension adds local integrity validation and enforcement of the
measurement against a "good" value stored as an extended attribute
'security.ima'. The initial methods for validating 'security.ima' are
hashed based, which provides file data integrity, and digital signature
based, which in addition to providing file data integrity, provides
authenticity.
This patch creates and maintains the 'security.ima' xattr, containing
the file data hash measurement. Protection of the xattr is provided by
EVM, if enabled and configured.
Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
integrity and, assuming success, compares the file's current hash value
with the one stored as an extended attribute in 'security.ima'.
Changelov v4:
- changed iint cache flags to hex values
Changelog v3:
- change appraisal default for filesystems without xattr support to fail
Changelog v2:
- fix audit msg 'res' value
- removed unused 'ima_appraise=' values
Changelog v1:
- removed unused iint mutex (Dmitry Kasatkin)
- setattr hook must not reset appraised (Dmitry Kasatkin)
- evm_verifyxattr() now differentiates between no 'security.evm' xattr
(INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
'security.evm' (INTEGRITY_NOXATTRS).
- replace hash_status with ima_status (Dmitry Kasatkin)
- re-initialize slab element ima_status on free (Dmitry Kasatkin)
- include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
- merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
- removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
- use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
(moved ima_inode_post_setattr() to ima_appraise.c)
- make sure ima_collect_measurement() can read file
Changelog:
- add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
- fix the race condition between chmod, which takes the i_mutex and then
iint->mutex, and ima_file_free() and process_measurement(), which take
the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
- cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
- changes as a result of the iint not allocated for all regular files, but
only for those measured/appraised.
- don't try to appraise new/empty files
- expanded ima_appraisal description in ima/Kconfig
- IMA appraise definitions required even if IMA_APPRAISE not enabled
- add return value to ima_must_appraise() stub
- unconditionally set status = INTEGRITY_PASS *after* testing status,
not before. (Found by Joe Perches)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
2012-02-13 22:15:05 +07:00
|
|
|
if (iint->flags & IMA_MEASURED)
|
|
|
|
return;
|
|
|
|
|
2013-07-23 22:15:00 +07:00
|
|
|
result = ima_alloc_init_template(iint, file, filename,
|
|
|
|
xattr_value, xattr_len, &entry);
|
2013-06-07 17:16:28 +07:00
|
|
|
if (result < 0) {
|
2009-02-04 21:06:58 +07:00
|
|
|
integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode, filename,
|
|
|
|
op, audit_cause, result, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-07 17:16:27 +07:00
|
|
|
result = ima_store_template(entry, violation, inode, filename);
|
2011-12-19 21:57:27 +07:00
|
|
|
if (!result || result == -EEXIST)
|
2009-02-04 21:06:58 +07:00
|
|
|
iint->flags |= IMA_MEASURED;
|
2011-12-19 21:57:27 +07:00
|
|
|
if (result < 0)
|
2013-12-03 01:40:34 +07:00
|
|
|
ima_free_template_entry(entry);
|
2009-02-04 21:06:58 +07:00
|
|
|
}
|
2012-06-15 00:04:36 +07:00
|
|
|
|
|
|
|
void ima_audit_measurement(struct integrity_iint_cache *iint,
|
|
|
|
const unsigned char *filename)
|
|
|
|
{
|
|
|
|
struct audit_buffer *ab;
|
2013-04-25 14:44:04 +07:00
|
|
|
char hash[(iint->ima_hash->length * 2) + 1];
|
2013-06-07 17:16:38 +07:00
|
|
|
const char *algo_name = hash_algo_name[iint->ima_hash->algo];
|
|
|
|
char algo_hash[sizeof(hash) + strlen(algo_name) + 2];
|
2012-06-15 00:04:36 +07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (iint->flags & IMA_AUDITED)
|
|
|
|
return;
|
|
|
|
|
2013-04-25 14:44:04 +07:00
|
|
|
for (i = 0; i < iint->ima_hash->length; i++)
|
|
|
|
hex_byte_pack(hash + (i * 2), iint->ima_hash->digest[i]);
|
2012-06-15 00:04:36 +07:00
|
|
|
hash[i * 2] = '\0';
|
|
|
|
|
|
|
|
ab = audit_log_start(current->audit_context, GFP_KERNEL,
|
|
|
|
AUDIT_INTEGRITY_RULE);
|
|
|
|
if (!ab)
|
|
|
|
return;
|
|
|
|
|
|
|
|
audit_log_format(ab, "file=");
|
|
|
|
audit_log_untrustedstring(ab, filename);
|
|
|
|
audit_log_format(ab, " hash=");
|
2013-06-07 17:16:38 +07:00
|
|
|
snprintf(algo_hash, sizeof(algo_hash), "%s:%s", algo_name, hash);
|
|
|
|
audit_log_untrustedstring(ab, algo_hash);
|
2012-06-15 00:04:36 +07:00
|
|
|
|
|
|
|
audit_log_task_info(ab, current);
|
|
|
|
audit_log_end(ab);
|
|
|
|
|
|
|
|
iint->flags |= IMA_AUDITED;
|
|
|
|
}
|
2012-09-04 04:40:17 +07:00
|
|
|
|
|
|
|
const char *ima_d_path(struct path *path, char **pathbuf)
|
|
|
|
{
|
|
|
|
char *pathname = NULL;
|
|
|
|
|
|
|
|
/* We will allow 11 spaces for ' (deleted)' to be appended */
|
|
|
|
*pathbuf = kmalloc(PATH_MAX + 11, GFP_KERNEL);
|
|
|
|
if (*pathbuf) {
|
|
|
|
pathname = d_path(path, *pathbuf, PATH_MAX + 11);
|
|
|
|
if (IS_ERR(pathname)) {
|
|
|
|
kfree(*pathbuf);
|
|
|
|
*pathbuf = NULL;
|
|
|
|
pathname = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pathname;
|
|
|
|
}
|