2019-06-01 10:08:55 +02:00
/* SPDX-License-Identifier: GPL-2.0-only */
2009-02-04 09:06:58 -05:00
/*
* Copyright ( C ) 2005 , 2006 , 2007 , 2008 IBM Corporation
*
* Authors :
* Reiner Sailer < sailer @ watson . ibm . com >
* Mimi Zohar < zohar @ us . ibm . com >
*
* File : ima . h
* internal Integrity Measurement Architecture ( IMA ) definitions
*/
# ifndef __LINUX_IMA_H
# define __LINUX_IMA_H
# include <linux/types.h>
# include <linux/crypto.h>
2016-01-14 17:57:47 -05:00
# include <linux/fs.h>
2009-02-04 09:06:58 -05:00
# include <linux/security.h>
# include <linux/hash.h>
# include <linux/tpm.h>
# include <linux/audit.h>
2014-10-30 12:39:39 +02:00
# include <crypto/hash_info.h>
2009-02-04 09:06:58 -05:00
2011-03-09 14:13:22 -05:00
# include "../integrity.h"
2013-11-08 19:21:40 +01:00
enum ima_show_type { IMA_SHOW_BINARY , IMA_SHOW_BINARY_NO_FIELD_LEN ,
2014-02-03 13:56:04 +01:00
IMA_SHOW_BINARY_OLD_STRING_FMT , IMA_SHOW_ASCII } ;
2020-06-23 11:57:32 -04:00
enum tpm_pcrs { TPM_PCR0 = 0 , TPM_PCR8 = 8 , TPM_PCR10 = 10 } ;
2009-02-04 09:06:58 -05:00
/* digest size for IMA, fits SHA1 or MD5 */
2011-03-09 14:13:22 -05:00
# define IMA_DIGEST_SIZE SHA1_DIGEST_SIZE
2009-02-04 09:06:58 -05:00
# define IMA_EVENT_NAME_LEN_MAX 255
2020-04-28 09:30:10 +02:00
# define IMA_HASH_BITS 10
2009-02-04 09:06:58 -05:00
# define IMA_MEASURE_HTABLE_SIZE (1 << IMA_HASH_BITS)
ima: new templates management mechanism
The original 'ima' template is fixed length, containing the filedata hash
and pathname. The filedata hash is limited to 20 bytes (md5/sha1). The
pathname is a null terminated string, limited to 255 characters. To
overcome these limitations and to add additional file metadata, it is
necessary to extend the current version of IMA by defining additional
templates.
The main reason to introduce this feature is that, each time a new
template is defined, the functions that generate and display the
measurement list would include the code for handling a new format and,
thus, would significantly grow over time.
This patch set solves this problem by separating the template management
from the remaining IMA code. The core of this solution is the definition
of two new data structures: a template descriptor, to determine which
information should be included in the measurement list, and a template
field, to generate and display data of a given type.
To define a new template field, developers define the field identifier
and implement two functions, init() and show(), respectively to generate
and display measurement entries. Initially, this patch set defines the
following template fields (support for additional data types will be
added later):
- 'd': the digest of the event (i.e. the digest of a measured file),
calculated with the SHA1 or MD5 hash algorithm;
- 'n': the name of the event (i.e. the file name), with size up to
255 bytes;
- 'd-ng': the digest of the event, calculated with an arbitrary hash
algorithm (field format: [<hash algo>:]digest, where the digest
prefix is shown only if the hash algorithm is not SHA1 or MD5);
- 'n-ng': the name of the event, without size limitations.
Defining a new template descriptor requires specifying the template format,
a string of field identifiers separated by the '|' character. This patch
set defines the following template descriptors:
- "ima": its format is 'd|n';
- "ima-ng" (default): its format is 'd-ng|n-ng'
Further details about the new template architecture can be found in
Documentation/security/IMA-templates.txt.
Changelog:
- don't defer calling ima_init_template() - Mimi
- don't define ima_lookup_template_desc() until used - Mimi
- squashed with documentation patch - Mimi
Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
2013-06-07 12:16:29 +02:00
# define IMA_TEMPLATE_FIELD_ID_MAX_LEN 16
# define IMA_TEMPLATE_NUM_FIELDS_MAX 15
2013-06-07 12:16:30 +02:00
# define IMA_TEMPLATE_IMA_NAME "ima"
# define IMA_TEMPLATE_IMA_FMT "d|n"
2020-03-25 11:47:09 +01:00
# define NR_BANKS(chip) ((chip != NULL) ? chip->nr_allocated_banks : 0)
2014-09-12 19:35:54 +02:00
/* current content of the policy */
extern int ima_policy_flag ;
2021-08-16 08:11:01 +00:00
/* bitset of digests algorithms allowed in the setxattr hook */
extern atomic_t ima_setxattr_allowed_hash_algorithms ;
2024-04-12 11:09:53 +02:00
/* IMA hash algorithm description */
struct ima_algo_desc {
struct crypto_shash * tfm ;
enum hash_algo algo ;
} ;
2009-02-04 09:06:58 -05:00
/* set during initialization */
2021-08-16 08:11:00 +00:00
extern int ima_hash_algo __ro_after_init ;
2020-03-25 11:47:09 +01:00
extern int ima_sha1_idx __ro_after_init ;
2020-03-25 11:54:24 +01:00
extern int ima_hash_algo_idx __ro_after_init ;
2020-03-25 11:47:09 +01:00
extern int ima_extra_slots __ro_after_init ;
2024-04-12 11:09:53 +02:00
extern struct ima_algo_desc * ima_algo_array __ro_after_init ;
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 10:15:05 -05:00
extern int ima_appraise ;
2018-06-26 15:09:32 -04:00
extern struct tpm_chip * ima_tpm_chip ;
2020-06-03 17:08:21 +02:00
extern const char boot_aggregate_name [ ] ;
2009-02-04 09:06:58 -05:00
2015-04-11 17:09:50 +02:00
/* IMA event related data */
struct ima_event_data {
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
struct ima_iint_cache * iint ;
2015-04-11 17:09:50 +02:00
struct file * file ;
const unsigned char * filename ;
struct evm_ima_xattr_data * xattr_value ;
int xattr_len ;
2019-06-27 23:19:32 -03:00
const struct modsig * modsig ;
2015-04-11 17:12:39 +02:00
const char * violation ;
2019-06-23 23:23:30 -07:00
const void * buf ;
int buf_len ;
2015-04-11 17:09:50 +02:00
} ;
ima: new templates management mechanism
The original 'ima' template is fixed length, containing the filedata hash
and pathname. The filedata hash is limited to 20 bytes (md5/sha1). The
pathname is a null terminated string, limited to 255 characters. To
overcome these limitations and to add additional file metadata, it is
necessary to extend the current version of IMA by defining additional
templates.
The main reason to introduce this feature is that, each time a new
template is defined, the functions that generate and display the
measurement list would include the code for handling a new format and,
thus, would significantly grow over time.
This patch set solves this problem by separating the template management
from the remaining IMA code. The core of this solution is the definition
of two new data structures: a template descriptor, to determine which
information should be included in the measurement list, and a template
field, to generate and display data of a given type.
To define a new template field, developers define the field identifier
and implement two functions, init() and show(), respectively to generate
and display measurement entries. Initially, this patch set defines the
following template fields (support for additional data types will be
added later):
- 'd': the digest of the event (i.e. the digest of a measured file),
calculated with the SHA1 or MD5 hash algorithm;
- 'n': the name of the event (i.e. the file name), with size up to
255 bytes;
- 'd-ng': the digest of the event, calculated with an arbitrary hash
algorithm (field format: [<hash algo>:]digest, where the digest
prefix is shown only if the hash algorithm is not SHA1 or MD5);
- 'n-ng': the name of the event, without size limitations.
Defining a new template descriptor requires specifying the template format,
a string of field identifiers separated by the '|' character. This patch
set defines the following template descriptors:
- "ima": its format is 'd|n';
- "ima-ng" (default): its format is 'd-ng|n-ng'
Further details about the new template architecture can be found in
Documentation/security/IMA-templates.txt.
Changelog:
- don't defer calling ima_init_template() - Mimi
- don't define ima_lookup_template_desc() until used - Mimi
- squashed with documentation patch - Mimi
Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
2013-06-07 12:16:29 +02:00
/* IMA template field data definition */
struct ima_field_data {
u8 * data ;
u32 len ;
} ;
/* IMA template field definition */
struct ima_template_field {
const char field_id [ IMA_TEMPLATE_FIELD_ID_MAX_LEN ] ;
2015-04-11 17:09:50 +02:00
int ( * field_init ) ( struct ima_event_data * event_data ,
struct ima_field_data * field_data ) ;
void ( * field_show ) ( struct seq_file * m , enum ima_show_type show ,
struct ima_field_data * field_data ) ;
ima: new templates management mechanism
The original 'ima' template is fixed length, containing the filedata hash
and pathname. The filedata hash is limited to 20 bytes (md5/sha1). The
pathname is a null terminated string, limited to 255 characters. To
overcome these limitations and to add additional file metadata, it is
necessary to extend the current version of IMA by defining additional
templates.
The main reason to introduce this feature is that, each time a new
template is defined, the functions that generate and display the
measurement list would include the code for handling a new format and,
thus, would significantly grow over time.
This patch set solves this problem by separating the template management
from the remaining IMA code. The core of this solution is the definition
of two new data structures: a template descriptor, to determine which
information should be included in the measurement list, and a template
field, to generate and display data of a given type.
To define a new template field, developers define the field identifier
and implement two functions, init() and show(), respectively to generate
and display measurement entries. Initially, this patch set defines the
following template fields (support for additional data types will be
added later):
- 'd': the digest of the event (i.e. the digest of a measured file),
calculated with the SHA1 or MD5 hash algorithm;
- 'n': the name of the event (i.e. the file name), with size up to
255 bytes;
- 'd-ng': the digest of the event, calculated with an arbitrary hash
algorithm (field format: [<hash algo>:]digest, where the digest
prefix is shown only if the hash algorithm is not SHA1 or MD5);
- 'n-ng': the name of the event, without size limitations.
Defining a new template descriptor requires specifying the template format,
a string of field identifiers separated by the '|' character. This patch
set defines the following template descriptors:
- "ima": its format is 'd|n';
- "ima-ng" (default): its format is 'd-ng|n-ng'
Further details about the new template architecture can be found in
Documentation/security/IMA-templates.txt.
Changelog:
- don't defer calling ima_init_template() - Mimi
- don't define ima_lookup_template_desc() until used - Mimi
- squashed with documentation patch - Mimi
Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
2013-06-07 12:16:29 +02:00
} ;
/* IMA template descriptor definition */
struct ima_template_desc {
2016-12-19 16:22:51 -08:00
struct list_head list ;
ima: new templates management mechanism
The original 'ima' template is fixed length, containing the filedata hash
and pathname. The filedata hash is limited to 20 bytes (md5/sha1). The
pathname is a null terminated string, limited to 255 characters. To
overcome these limitations and to add additional file metadata, it is
necessary to extend the current version of IMA by defining additional
templates.
The main reason to introduce this feature is that, each time a new
template is defined, the functions that generate and display the
measurement list would include the code for handling a new format and,
thus, would significantly grow over time.
This patch set solves this problem by separating the template management
from the remaining IMA code. The core of this solution is the definition
of two new data structures: a template descriptor, to determine which
information should be included in the measurement list, and a template
field, to generate and display data of a given type.
To define a new template field, developers define the field identifier
and implement two functions, init() and show(), respectively to generate
and display measurement entries. Initially, this patch set defines the
following template fields (support for additional data types will be
added later):
- 'd': the digest of the event (i.e. the digest of a measured file),
calculated with the SHA1 or MD5 hash algorithm;
- 'n': the name of the event (i.e. the file name), with size up to
255 bytes;
- 'd-ng': the digest of the event, calculated with an arbitrary hash
algorithm (field format: [<hash algo>:]digest, where the digest
prefix is shown only if the hash algorithm is not SHA1 or MD5);
- 'n-ng': the name of the event, without size limitations.
Defining a new template descriptor requires specifying the template format,
a string of field identifiers separated by the '|' character. This patch
set defines the following template descriptors:
- "ima": its format is 'd|n';
- "ima-ng" (default): its format is 'd-ng|n-ng'
Further details about the new template architecture can be found in
Documentation/security/IMA-templates.txt.
Changelog:
- don't defer calling ima_init_template() - Mimi
- don't define ima_lookup_template_desc() until used - Mimi
- squashed with documentation patch - Mimi
Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
2013-06-07 12:16:29 +02:00
char * name ;
char * fmt ;
int num_fields ;
2018-09-07 13:22:23 -07:00
const struct ima_template_field * * fields ;
ima: new templates management mechanism
The original 'ima' template is fixed length, containing the filedata hash
and pathname. The filedata hash is limited to 20 bytes (md5/sha1). The
pathname is a null terminated string, limited to 255 characters. To
overcome these limitations and to add additional file metadata, it is
necessary to extend the current version of IMA by defining additional
templates.
The main reason to introduce this feature is that, each time a new
template is defined, the functions that generate and display the
measurement list would include the code for handling a new format and,
thus, would significantly grow over time.
This patch set solves this problem by separating the template management
from the remaining IMA code. The core of this solution is the definition
of two new data structures: a template descriptor, to determine which
information should be included in the measurement list, and a template
field, to generate and display data of a given type.
To define a new template field, developers define the field identifier
and implement two functions, init() and show(), respectively to generate
and display measurement entries. Initially, this patch set defines the
following template fields (support for additional data types will be
added later):
- 'd': the digest of the event (i.e. the digest of a measured file),
calculated with the SHA1 or MD5 hash algorithm;
- 'n': the name of the event (i.e. the file name), with size up to
255 bytes;
- 'd-ng': the digest of the event, calculated with an arbitrary hash
algorithm (field format: [<hash algo>:]digest, where the digest
prefix is shown only if the hash algorithm is not SHA1 or MD5);
- 'n-ng': the name of the event, without size limitations.
Defining a new template descriptor requires specifying the template format,
a string of field identifiers separated by the '|' character. This patch
set defines the following template descriptors:
- "ima": its format is 'd|n';
- "ima-ng" (default): its format is 'd-ng|n-ng'
Further details about the new template architecture can be found in
Documentation/security/IMA-templates.txt.
Changelog:
- don't defer calling ima_init_template() - Mimi
- don't define ima_lookup_template_desc() until used - Mimi
- squashed with documentation patch - Mimi
Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
2013-06-07 12:16:29 +02:00
} ;
2009-02-04 09:06:58 -05:00
struct ima_template_entry {
2016-06-01 13:14:03 -05:00
int pcr ;
2020-03-25 11:47:09 +01:00
struct tpm_digest * digests ;
2013-06-07 12:16:33 +02:00
struct ima_template_desc * template_desc ; /* template descriptor */
u32 template_data_len ;
2020-08-31 08:25:42 -05:00
struct ima_field_data template_data [ ] ; /* template related data */
2009-02-04 09:06:58 -05:00
} ;
struct ima_queue_entry {
struct hlist_node hnext ; /* place in hash collision list */
struct list_head later ; /* place in ima_measurements list */
struct ima_template_entry * entry ;
} ;
extern struct list_head ima_measurements ; /* list of all measurements */
2016-12-19 16:22:35 -08:00
/* Some details preceding the binary serialized measurement list */
struct ima_kexec_hdr {
u16 version ;
u16 _reserved0 ;
u32 _reserved1 ;
u64 buffer_size ;
u64 count ;
} ;
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
/* IMA iint action cache flags */
# define IMA_MEASURE 0x00000001
# define IMA_MEASURED 0x00000002
# define IMA_APPRAISE 0x00000004
# define IMA_APPRAISED 0x00000008
/*#define IMA_COLLECT 0x00000010 do not use this flag */
# define IMA_COLLECTED 0x00000020
# define IMA_AUDIT 0x00000040
# define IMA_AUDITED 0x00000080
# define IMA_HASH 0x00000100
# define IMA_HASHED 0x00000200
/* IMA iint policy rule cache flags */
# define IMA_NONACTION_FLAGS 0xff000000
# define IMA_DIGSIG_REQUIRED 0x01000000
# define IMA_PERMIT_DIRECTIO 0x02000000
# define IMA_NEW_FILE 0x04000000
# define IMA_FAIL_UNVERIFIABLE_SIGS 0x10000000
# define IMA_MODSIG_ALLOWED 0x20000000
# define IMA_CHECK_BLACKLIST 0x40000000
# define IMA_VERITY_REQUIRED 0x80000000
# define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \
IMA_HASH | IMA_APPRAISE_SUBMASK )
# define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED | \
IMA_HASHED | IMA_COLLECTED | \
IMA_APPRAISED_SUBMASK )
/* IMA iint subaction appraise cache flags */
# define IMA_FILE_APPRAISE 0x00001000
# define IMA_FILE_APPRAISED 0x00002000
# define IMA_MMAP_APPRAISE 0x00004000
# define IMA_MMAP_APPRAISED 0x00008000
# define IMA_BPRM_APPRAISE 0x00010000
# define IMA_BPRM_APPRAISED 0x00020000
# define IMA_READ_APPRAISE 0x00040000
# define IMA_READ_APPRAISED 0x00080000
# define IMA_CREDS_APPRAISE 0x00100000
# define IMA_CREDS_APPRAISED 0x00200000
# define IMA_APPRAISE_SUBMASK (IMA_FILE_APPRAISE | IMA_MMAP_APPRAISE | \
IMA_BPRM_APPRAISE | IMA_READ_APPRAISE | \
IMA_CREDS_APPRAISE )
# define IMA_APPRAISED_SUBMASK (IMA_FILE_APPRAISED | IMA_MMAP_APPRAISED | \
IMA_BPRM_APPRAISED | IMA_READ_APPRAISED | \
IMA_CREDS_APPRAISED )
/* IMA iint cache atomic_flags */
# define IMA_CHANGE_XATTR 0
# define IMA_UPDATE_XATTR 1
# define IMA_CHANGE_ATTR 2
# define IMA_DIGSIG 3
# define IMA_MUST_MEASURE 4
/* IMA integrity metadata associated with an inode */
struct ima_iint_cache {
struct mutex mutex ; /* protects: version, flags, digest */
2024-02-23 12:25:08 -05:00
struct integrity_inode_attributes real_inode ;
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
unsigned long flags ;
unsigned long measured_pcrs ;
unsigned long atomic_flags ;
enum integrity_status ima_file_status : 4 ;
enum integrity_status ima_mmap_status : 4 ;
enum integrity_status ima_bprm_status : 4 ;
enum integrity_status ima_read_status : 4 ;
enum integrity_status ima_creds_status : 4 ;
struct ima_digest_data * ima_hash ;
} ;
extern struct lsm_blob_sizes ima_blob_sizes ;
static inline struct ima_iint_cache *
ima_inode_get_iint ( const struct inode * inode )
{
struct ima_iint_cache * * iint_sec ;
if ( unlikely ( ! inode - > i_security ) )
return NULL ;
iint_sec = inode - > i_security + ima_blob_sizes . lbs_inode ;
return * iint_sec ;
}
static inline void ima_inode_set_iint ( const struct inode * inode ,
struct ima_iint_cache * iint )
{
struct ima_iint_cache * * iint_sec ;
if ( unlikely ( ! inode - > i_security ) )
return ;
iint_sec = inode - > i_security + ima_blob_sizes . lbs_inode ;
* iint_sec = iint ;
}
struct ima_iint_cache * ima_iint_find ( struct inode * inode ) ;
struct ima_iint_cache * ima_inode_get ( struct inode * inode ) ;
void ima_inode_free ( struct inode * inode ) ;
void __init ima_iintcache_init ( void ) ;
2019-08-19 17:18:01 -07:00
extern const int read_idmap [ ] ;
2016-12-19 16:22:35 -08:00
# ifdef CONFIG_HAVE_IMA_KEXEC
void ima_load_kexec_buffer ( void ) ;
# else
static inline void ima_load_kexec_buffer ( void ) { }
# endif /* CONFIG_HAVE_IMA_KEXEC */
ima: Move to LSM infrastructure
Move hardcoded IMA function calls (not appraisal-specific functions) from
various places in the kernel to the LSM infrastructure, by introducing a
new LSM named 'ima' (at the end of the LSM list and always enabled like
'integrity').
Having IMA before EVM in the Makefile is sufficient to preserve the
relative order of the new 'ima' LSM in respect to the upcoming 'evm' LSM,
and thus the order of IMA and EVM function calls as when they were
hardcoded.
Make moved functions as static (except ima_post_key_create_or_update(),
which is not in ima_main.c), and register them as implementation of the
respective hooks in the new function init_ima_lsm().
Select CONFIG_SECURITY_PATH, to ensure that the path-based LSM hook
path_post_mknod is always available and ima_post_path_mknod() is always
executed to mark files as new, as before the move.
A slight difference is that IMA and EVM functions registered for the
inode_post_setattr, inode_post_removexattr, path_post_mknod,
inode_post_create_tmpfile, inode_post_set_acl and inode_post_remove_acl
won't be executed for private inodes. Since those inodes are supposed to be
fs-internal, they should not be of interest to IMA or EVM. The S_PRIVATE
flag is used for anonymous inodes, hugetlbfs, reiserfs xattrs, XFS scrub
and kernel-internal tmpfs files.
Conditionally register ima_post_key_create_or_update() if
CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS is enabled. Also, conditionally register
ima_kernel_module_request() if CONFIG_INTEGRITY_ASYMMETRIC_KEYS is enabled.
Finally, add the LSM_ID_IMA case in lsm_list_modules_test.c.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Acked-by: Chuck Lever <chuck.lever@oracle.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:08 +01:00
# ifdef CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS
void ima_post_key_create_or_update ( struct key * keyring , struct key * key ,
const void * payload , size_t plen ,
unsigned long flags , bool create ) ;
# endif
2016-12-19 16:22:57 -08:00
/*
* The default binary_runtime_measurements list format is defined as the
* platform native format . The canonical format is defined as little - endian .
*/
extern bool ima_canonical_fmt ;
2009-02-04 09:06:58 -05:00
/* Internal IMA function definitions */
int ima_init ( void ) ;
2009-02-04 09:06:59 -05:00
int ima_fs_init ( void ) ;
2009-02-04 09:06:58 -05:00
int ima_add_template_entry ( struct ima_template_entry * entry , int violation ,
2013-06-07 12:16:27 +02:00
const char * op , struct inode * inode ,
const unsigned char * filename ) ;
2013-04-25 10:43:56 +03:00
int ima_calc_file_hash ( struct file * file , struct ima_digest_data * hash ) ;
2014-04-17 12:01:40 +03:00
int ima_calc_buffer_hash ( const void * buf , loff_t len ,
struct ima_digest_data * hash ) ;
2013-11-08 19:21:39 +01:00
int ima_calc_field_array_hash ( struct ima_field_data * field_data ,
2020-03-25 11:47:08 +01:00
struct ima_template_entry * entry ) ;
2020-06-03 17:08:21 +02:00
int ima_calc_boot_aggregate ( struct ima_digest_data * hash ) ;
2013-06-07 12:16:26 +02:00
void ima_add_violation ( struct file * file , const unsigned char * filename ,
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
struct ima_iint_cache * iint , const char * op ,
const char * cause ) ;
2012-06-08 10:42:30 +03:00
int ima_init_crypto ( void ) ;
2013-06-07 12:16:30 +02:00
void ima_putc ( struct seq_file * m , void * data , int datalen ) ;
2015-06-11 11:54:42 -04:00
void ima_print_digest ( struct seq_file * m , u8 * digest , u32 size ) ;
2019-06-19 15:46:11 -07:00
int template_desc_init_fields ( const char * template_fmt ,
const struct ima_template_field * * * fields ,
int * num_fields ) ;
2013-06-07 12:16:33 +02:00
struct ima_template_desc * ima_template_desc_current ( void ) ;
2020-11-12 12:39:59 -08:00
struct ima_template_desc * ima_template_desc_buf ( void ) ;
2019-06-19 15:46:11 -07:00
struct ima_template_desc * lookup_template_desc ( const char * name ) ;
2019-06-27 23:19:33 -03:00
bool ima_template_has_modsig ( const struct ima_template_desc * ima_template ) ;
2016-12-19 16:22:35 -08:00
int ima_restore_measurement_entry ( struct ima_template_entry * entry ) ;
int ima_restore_measurement_list ( loff_t bufsize , void * buf ) ;
2016-12-19 16:22:48 -08:00
int ima_measurements_show ( struct seq_file * m , void * v ) ;
2016-12-19 16:22:42 -08:00
unsigned long ima_get_binary_runtime_size ( void ) ;
2013-06-07 12:16:33 +02:00
int ima_init_template ( void ) ;
2016-12-19 16:22:51 -08:00
void ima_init_template_list ( void ) ;
2019-02-06 17:24:52 +01:00
int __init ima_init_digests ( void ) ;
2019-06-14 15:20:15 +03:00
int ima_lsm_policy_change ( struct notifier_block * nb , unsigned long event ,
void * lsm_data ) ;
2009-02-04 09:06:58 -05:00
/*
* used to protect h_table and sha_table
*/
extern spinlock_t ima_queue_lock ;
struct ima_h_table {
atomic_long_t len ; /* number of stored measurements in the list */
atomic_long_t violations ;
struct hlist_head queue [ IMA_MEASURE_HTABLE_SIZE ] ;
} ;
extern struct ima_h_table ima_htable ;
2020-04-28 09:30:10 +02:00
static inline unsigned int ima_hash_key ( u8 * digest )
2009-02-04 09:06:58 -05:00
{
2020-04-28 09:30:10 +02:00
/* there is no point in taking a hash of part of a digest */
return ( digest [ 0 ] | digest [ 1 ] < < 8 ) % IMA_MEASURE_HTABLE_SIZE ;
2009-02-04 09:06:58 -05:00
}
2020-06-18 14:10:12 -07:00
# define __ima_hooks(hook) \
hook ( NONE , none ) \
hook ( FILE_CHECK , file ) \
hook ( MMAP_CHECK , mmap ) \
2023-01-31 18:42:44 +01:00
hook ( MMAP_CHECK_REQPROT , mmap_reqprot ) \
2020-06-18 14:10:12 -07:00
hook ( BPRM_CHECK , bprm ) \
hook ( CREDS_CHECK , creds ) \
hook ( POST_SETATTR , post_setattr ) \
hook ( MODULE_CHECK , module ) \
hook ( FIRMWARE_CHECK , firmware ) \
hook ( KEXEC_KERNEL_CHECK , kexec_kernel ) \
hook ( KEXEC_INITRAMFS_CHECK , kexec_initramfs ) \
hook ( POLICY_CHECK , policy ) \
hook ( KEXEC_CMDLINE , kexec_cmdline ) \
hook ( KEY_CHECK , key ) \
2021-01-07 20:07:03 -08:00
hook ( CRITICAL_DATA , critical_data ) \
2021-08-16 08:11:01 +00:00
hook ( SETXATTR_CHECK , setxattr_check ) \
2020-06-18 14:10:12 -07:00
hook ( MAX_CHECK , none )
# define __ima_hook_enumify(ENUM, str) ENUM,
# define __ima_stringify(arg) (#arg)
# define __ima_hook_measuring_stringify(ENUM, str) \
( __ima_stringify ( measuring_ # # str ) ) ,
2017-06-07 22:49:11 -03:00
2016-01-14 20:59:14 -05:00
enum ima_hooks {
2017-06-07 22:49:11 -03:00
__ima_hooks ( __ima_hook_enumify )
2016-01-14 20:59:14 -05:00
} ;
2020-06-18 14:10:12 -07:00
static const char * const ima_hooks_measure_str [ ] = {
__ima_hooks ( __ima_hook_measuring_stringify )
} ;
static inline const char * func_measure_str ( enum ima_hooks func )
{
if ( func > = MAX_CHECK )
return ima_hooks_measure_str [ NONE ] ;
return ima_hooks_measure_str [ func ] ;
}
2019-06-27 23:19:30 -03:00
extern const char * const func_tokens [ ] ;
struct modsig ;
2020-01-22 17:32:04 -08:00
# ifdef CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS
/*
* To track keys that need to be measured .
*/
struct ima_key_entry {
struct list_head list ;
void * payload ;
size_t payload_len ;
char * keyring_name ;
} ;
2020-01-22 17:32:06 -08:00
void ima_init_key_queue ( void ) ;
2020-01-22 17:32:04 -08:00
bool ima_should_queue_key ( void ) ;
bool ima_queue_key ( struct key * keyring , const void * payload ,
size_t payload_len ) ;
void ima_process_queued_keys ( void ) ;
# else
2020-01-22 17:32:06 -08:00
static inline void ima_init_key_queue ( void ) { }
2020-01-22 17:32:04 -08:00
static inline bool ima_should_queue_key ( void ) { return false ; }
static inline bool ima_queue_key ( struct key * keyring ,
const void * payload ,
size_t payload_len ) { return false ; }
static inline void ima_process_queued_keys ( void ) { }
# endif /* CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS */
2009-02-04 09:06:58 -05:00
/* LIM API function definitions */
2023-01-13 12:49:23 +01:00
int ima_get_action ( struct mnt_idmap * idmap , struct inode * inode ,
2021-01-21 14:19:45 +01:00
const struct cred * cred , u32 secid , int mask ,
enum ima_hooks func , int * pcr ,
2019-12-11 08:47:06 -08:00
struct ima_template_desc * * template_desc ,
2021-08-16 08:11:00 +00:00
const char * func_data , unsigned int * allowed_algos ) ;
2016-01-14 20:59:14 -05:00
int ima_must_measure ( struct inode * inode , int mask , enum ima_hooks func ) ;
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
int ima_collect_measurement ( struct ima_iint_cache * iint , struct file * file ,
void * buf , loff_t size , enum hash_algo algo ,
struct modsig * modsig ) ;
void ima_store_measurement ( struct ima_iint_cache * iint , struct file * file ,
2013-07-23 11:15:00 -04:00
const unsigned char * filename ,
struct evm_ima_xattr_data * xattr_value ,
2019-06-27 23:19:32 -03:00
int xattr_len , const struct modsig * modsig , int pcr ,
2019-06-19 15:46:11 -07:00
struct ima_template_desc * template_desc ) ;
2023-01-13 12:49:23 +01:00
int process_buffer_measurement ( struct mnt_idmap * idmap ,
ima: Return int in the functions to measure a buffer
ima_measure_critical_data() and process_buffer_measurement() currently
don't return a result as, unlike appraisal-related functions, the result is
not used by callers to deny an operation. Measurement-related functions
instead rely on the audit subsystem to notify the system administrator when
an error occurs.
However, ima_measure_critical_data() and process_buffer_measurement() are a
special case, as these are the only functions that can return a buffer
measurement (for files, there is ima_file_hash()). In a subsequent patch,
they will be modified to return the calculated digest.
In preparation to return the result of the digest calculation, this patch
modifies the return type from void to int, and returns 0 if the buffer has
been successfully measured, a negative value otherwise.
Given that the result of the measurement is still not necessary, this patch
does not modify the behavior of existing callers by processing the returned
value. For those, the return value is ignored.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com>
Acked-by: Paul Moore <paul@paul-moore.com> (for the SELinux bits)
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2021-07-23 10:53:03 +02:00
struct inode * inode , const void * buf , int size ,
const char * eventname , enum ima_hooks func ,
int pcr , const char * func_data ,
2021-07-23 10:53:04 +02:00
bool buf_hash , u8 * digest , size_t digest_len ) ;
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
void ima_audit_measurement ( struct ima_iint_cache * iint ,
2012-06-14 10:04:36 -07:00
const unsigned char * filename ) ;
2015-04-11 17:09:50 +02:00
int ima_alloc_init_template ( struct ima_event_data * event_data ,
2019-06-19 15:46:11 -07:00
struct ima_template_entry * * entry ,
struct ima_template_desc * template_desc ) ;
2009-02-04 09:06:58 -05:00
int ima_store_template ( struct ima_template_entry * entry , int violation ,
2016-06-01 13:14:03 -05:00
struct inode * inode ,
const unsigned char * filename , int pcr ) ;
2013-12-02 19:40:34 +01:00
void ima_free_template_entry ( struct ima_template_entry * entry ) ;
2017-01-17 06:45:41 -05:00
const char * ima_d_path ( const struct path * path , char * * pathbuf , char * filename ) ;
2009-02-04 09:06:58 -05:00
/* IMA policy related functions */
2023-01-13 12:49:23 +01:00
int ima_match_policy ( struct mnt_idmap * idmap , struct inode * inode ,
2021-01-21 14:19:45 +01:00
const struct cred * cred , u32 secid , enum ima_hooks func ,
int mask , int flags , int * pcr ,
2019-12-11 08:47:06 -08:00
struct ima_template_desc * * template_desc ,
2021-08-16 08:11:00 +00:00
const char * func_data , unsigned int * allowed_algos ) ;
2009-02-04 09:06:58 -05:00
void ima_init_policy ( void ) ;
void ima_update_policy ( void ) ;
2021-08-16 08:11:01 +00:00
void ima_update_policy_flags ( void ) ;
2010-04-20 10:20:54 -04:00
ssize_t ima_parse_add_rule ( char * ) ;
2009-02-04 09:07:00 -05:00
void ima_delete_rules ( void ) ;
2015-12-22 08:51:23 -05:00
int ima_check_policy ( void ) ;
2015-12-02 17:47:56 +02:00
void * ima_policy_start ( struct seq_file * m , loff_t * pos ) ;
void * ima_policy_next ( struct seq_file * m , void * v , loff_t * pos ) ;
void ima_policy_stop ( struct seq_file * m , void * v ) ;
int ima_policy_show ( struct seq_file * m , void * v ) ;
2009-02-04 09:07:00 -05: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 10:15:05 -05:00
/* Appraise integrity measurements */
# define IMA_APPRAISE_ENFORCE 0x01
# define IMA_APPRAISE_FIX 0x02
2014-05-08 13:11:29 +03:00
# define IMA_APPRAISE_LOG 0x04
# define IMA_APPRAISE_MODULES 0x08
# define IMA_APPRAISE_FIRMWARE 0x10
2016-01-15 10:17:12 -05:00
# define IMA_APPRAISE_POLICY 0x20
2018-07-13 14:05:58 -04:00
# define IMA_APPRAISE_KEXEC 0x40
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 10:15:05 -05:00
# ifdef CONFIG_IMA_APPRAISE
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
int ima_check_blacklist ( struct ima_iint_cache * iint ,
2019-10-30 23:31:32 -04:00
const struct modsig * modsig , int pcr ) ;
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
int ima_appraise_measurement ( enum ima_hooks func , struct ima_iint_cache * iint ,
2013-04-25 10:44:04 +03:00
struct file * file , const unsigned char * filename ,
struct evm_ima_xattr_data * xattr_value ,
2019-06-27 23:19:30 -03:00
int xattr_len , const struct modsig * modsig ) ;
2023-01-13 12:49:23 +01:00
int ima_must_appraise ( struct mnt_idmap * idmap , struct inode * inode ,
2021-01-21 14:19:45 +01:00
int mask , enum ima_hooks func ) ;
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
void ima_update_xattr ( struct ima_iint_cache * iint , struct file * file ) ;
enum integrity_status ima_get_cache_status ( struct ima_iint_cache * iint ,
2016-01-14 20:59:14 -05:00
enum ima_hooks func ) ;
2021-08-16 08:10:59 +00:00
enum hash_algo ima_get_hash_algo ( const struct evm_ima_xattr_data * xattr_value ,
2014-10-30 12:39:39 +02:00
int xattr_len ) ;
2013-04-25 10:44:04 +03:00
int ima_read_xattr ( struct dentry * dentry ,
2022-11-09 14:14:35 -05:00
struct evm_ima_xattr_data * * xattr_value , int xattr_len ) ;
2024-02-15 11:31:09 +01:00
void __init init_ima_appraise_lsm ( const struct lsm_id * lsmid ) ;
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 10:15:05 -05:00
# else
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
static inline int ima_check_blacklist ( struct ima_iint_cache * iint ,
2019-10-30 23:31:32 -04:00
const struct modsig * modsig , int pcr )
{
return 0 ;
}
2016-01-14 20:59:14 -05:00
static inline int ima_appraise_measurement ( enum ima_hooks func ,
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
struct ima_iint_cache * iint ,
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 10:15:05 -05:00
struct file * file ,
2013-04-25 10:44:04 +03:00
const unsigned char * filename ,
struct evm_ima_xattr_data * xattr_value ,
2019-06-27 23:19:30 -03:00
int xattr_len ,
const struct modsig * modsig )
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 10:15:05 -05:00
{
return INTEGRITY_UNKNOWN ;
}
2023-01-13 12:49:23 +01:00
static inline int ima_must_appraise ( struct mnt_idmap * idmap ,
2021-01-21 14:19:45 +01:00
struct inode * inode , int mask ,
2012-09-27 18:26:53 +03:00
enum ima_hooks func )
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 10:15:05 -05:00
{
return 0 ;
}
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
static inline void ima_update_xattr ( struct ima_iint_cache * iint ,
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 10:15:05 -05:00
struct file * file )
{
}
2012-12-03 17:08:11 -05:00
ima: Make it independent from 'integrity' LSM
Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.
Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.
Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().
Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.
Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.
Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().
Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-02-15 11:31:12 +01:00
static inline enum integrity_status
ima_get_cache_status ( struct ima_iint_cache * iint , enum ima_hooks func )
2012-12-03 17:08:11 -05:00
{
return INTEGRITY_UNKNOWN ;
}
2013-04-25 10:44:04 +03:00
2014-10-30 12:39:39 +02:00
static inline enum hash_algo
ima_get_hash_algo ( struct evm_ima_xattr_data * xattr_value , int xattr_len )
2013-04-25 10:44:04 +03:00
{
2014-10-30 12:39:39 +02:00
return ima_hash_algo ;
2013-04-25 10:44:04 +03:00
}
static inline int ima_read_xattr ( struct dentry * dentry ,
2022-11-09 14:14:35 -05:00
struct evm_ima_xattr_data * * xattr_value ,
int xattr_len )
2013-04-25 10:44:04 +03:00
{
return 0 ;
}
2024-02-15 11:31:09 +01:00
static inline void __init init_ima_appraise_lsm ( const struct lsm_id * lsmid )
{
}
2017-06-07 22:49:10 -03:00
# endif /* CONFIG_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 10:15:05 -05:00
2019-06-27 23:19:28 -03:00
# ifdef CONFIG_IMA_APPRAISE_MODSIG
2019-06-27 23:19:30 -03:00
int ima_read_modsig ( enum ima_hooks func , const void * buf , loff_t buf_len ,
struct modsig * * modsig ) ;
2019-06-27 23:19:31 -03:00
void ima_collect_modsig ( struct modsig * modsig , const void * buf , loff_t size ) ;
2019-06-27 23:19:32 -03:00
int ima_get_modsig_digest ( const struct modsig * modsig , enum hash_algo * algo ,
const u8 * * digest , u32 * digest_size ) ;
int ima_get_raw_modsig ( const struct modsig * modsig , const void * * data ,
u32 * data_len ) ;
2019-06-27 23:19:30 -03:00
void ima_free_modsig ( struct modsig * modsig ) ;
2019-06-27 23:19:28 -03:00
# else
2019-06-27 23:19:30 -03:00
static inline int ima_read_modsig ( enum ima_hooks func , const void * buf ,
loff_t buf_len , struct modsig * * modsig )
{
return - EOPNOTSUPP ;
}
2019-06-27 23:19:31 -03:00
static inline void ima_collect_modsig ( struct modsig * modsig , const void * buf ,
loff_t size )
{
}
2019-06-27 23:19:32 -03:00
static inline int ima_get_modsig_digest ( const struct modsig * modsig ,
enum hash_algo * algo , const u8 * * digest ,
u32 * digest_size )
{
return - EOPNOTSUPP ;
}
static inline int ima_get_raw_modsig ( const struct modsig * modsig ,
const void * * data , u32 * data_len )
{
return - EOPNOTSUPP ;
}
2019-06-27 23:19:30 -03:00
static inline void ima_free_modsig ( struct modsig * modsig )
{
}
2019-06-27 23:19:28 -03:00
# endif /* CONFIG_IMA_APPRAISE_MODSIG */
2009-02-04 09:07:00 -05:00
/* LSM based policy rules require audit */
# ifdef CONFIG_IMA_LSM_RULES
2020-07-10 15:37:50 -05:00
# define ima_filter_rule_init security_audit_rule_init
# define ima_filter_rule_free security_audit_rule_free
# define ima_filter_rule_match security_audit_rule_match
2009-02-04 09:07:00 -05:00
# else
2020-07-10 15:37:50 -05:00
static inline int ima_filter_rule_init ( u32 field , u32 op , char * rulestr ,
void * * lsmrule )
2009-02-04 09:07:00 -05:00
{
return - EINVAL ;
}
2020-07-10 15:37:50 -05:00
static inline void ima_filter_rule_free ( void * lsmrule )
2020-07-09 01:19:00 -05:00
{
}
2020-07-10 15:37:50 -05:00
static inline int ima_filter_rule_match ( u32 secid , u32 field , u32 op ,
void * lsmrule )
2009-02-04 09:07:00 -05:00
{
return - EINVAL ;
}
2017-05-05 11:15:47 -06:00
# endif /* CONFIG_IMA_LSM_RULES */
2015-12-02 17:47:56 +02:00
# ifdef CONFIG_IMA_READ_POLICY
# define POLICY_FILE_FLAGS (S_IWUSR | S_IRUSR)
# else
# define POLICY_FILE_FLAGS S_IWUSR
2017-05-05 11:15:47 -06:00
# endif /* CONFIG_IMA_READ_POLICY */
2015-12-02 17:47:56 +02:00
# endif /* __LINUX_IMA_H */