2019-06-01 01:08:55 -07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2011-03-09 12:13:22 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009-2010 IBM Corporation
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Mimi Zohar <zohar@us.ibm.com>
|
|
|
|
*/
|
|
|
|
|
2020-02-18 17:06:11 -07:00
|
|
|
#ifdef pr_fmt
|
|
|
|
#undef pr_fmt
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2011-03-09 12:13:22 -07:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/integrity.h>
|
2020-11-12 22:20:21 -07:00
|
|
|
#include <crypto/sha1.h>
|
2022-01-24 12:26:23 -07:00
|
|
|
#include <crypto/hash.h>
|
2013-02-06 15:12:08 -07:00
|
|
|
#include <linux/key.h>
|
2018-06-04 13:54:54 -07:00
|
|
|
#include <linux/audit.h>
|
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 03:31:08 -07:00
|
|
|
#include <linux/lsm_hooks.h>
|
2011-03-09 12:13:22 -07:00
|
|
|
|
2011-03-09 12:28:20 -07:00
|
|
|
enum evm_ima_xattr_type {
|
|
|
|
IMA_XATTR_DIGEST = 0x01,
|
|
|
|
EVM_XATTR_HMAC,
|
|
|
|
EVM_IMA_XATTR_DIGSIG,
|
2013-08-12 01:22:51 -07:00
|
|
|
IMA_XATTR_DIGEST_NG,
|
2017-11-07 08:17:42 -07:00
|
|
|
EVM_XATTR_PORTABLE_DIGSIG,
|
ima: support fs-verity file digest based version 3 signatures
IMA may verify a file's integrity against a "good" value stored in the
'security.ima' xattr or as an appended signature, based on policy. When
the "good value" is stored in the xattr, the xattr may contain a file
hash or signature. In either case, the "good" value is preceded by a
header. The first byte of the xattr header indicates the type of data
- hash, signature - stored in the xattr. To support storing fs-verity
signatures in the 'security.ima' xattr requires further differentiating
the fs-verity signature from the existing IMA signature.
In addition the signatures stored in 'security.ima' xattr, need to be
disambiguated. Instead of directly signing the fs-verity digest, a new
signature format version 3 is defined as the hash of the ima_file_id
structure, which identifies the type of signature and the digest.
The IMA policy defines "which" files are to be measured, verified, and/or
audited. For those files being verified, the policy rules indicate "how"
the file should be verified. For example to require a file be signed,
the appraise policy rule must include the 'appraise_type' option.
appraise_type:= [imasig] | [imasig|modsig] | [sigv3]
where 'imasig' is the original or signature format v2 (default),
where 'modsig' is an appended signature,
where 'sigv3' is the signature format v3.
The policy rule must also indicate the type of digest, if not the IMA
default, by first specifying the digest type:
digest_type:= [verity]
The following policy rule requires fsverity signatures. The rule may be
constrained, for example based on a fsuuid or LSM label.
appraise func=BPRM_CHECK digest_type=verity appraise_type=sigv3
Acked-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2021-11-24 08:56:33 -07:00
|
|
|
IMA_VERITY_DIGSIG,
|
2014-10-28 04:31:22 -07:00
|
|
|
IMA_XATTR_LAST
|
2011-03-09 12:28:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct evm_ima_xattr_data {
|
integrity: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.
There is currently an object (`hdr)` in `struct ima_max_digest_data`
that contains a flexible structure (`struct ima_digest_data`):
struct ima_max_digest_data {
struct ima_digest_data hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
So, in order to avoid ending up with a flexible-array member in the
middle of a struct, we use the `__struct_group()` helper to separate
the flexible array from the rest of the members in the flexible
structure:
struct ima_digest_data {
__struct_group(ima_digest_data_hdr, hdr, __packed,
... the rest of the members
);
u8 digest[];
} __packed;
And similarly for `struct evm_ima_xattr_data`.
With the change described above, we can now declare an object of the
type of the tagged `struct ima_digest_data_hdr`, without embedding the
flexible array in the middle of another struct:
struct ima_max_digest_data {
struct ima_digest_data_hdr hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
And similarly for `struct evm_digest` and `struct evm_xattr`.
We also use `container_of()` whenever we need to retrieve a pointer to
the flexible structure.
So, with these changes, fix the following warnings:
security/integrity/evm/evm.h:64:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Link: https://github.com/KSPP/linux/issues/202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2024-04-04 08:00:48 -07:00
|
|
|
/* New members must be added within the __struct_group() macro below. */
|
|
|
|
__struct_group(evm_ima_xattr_data_hdr, hdr, __packed,
|
|
|
|
u8 type;
|
|
|
|
);
|
2019-06-10 23:28:08 -07:00
|
|
|
u8 data[];
|
|
|
|
} __packed;
|
2024-08-08 15:04:59 -07:00
|
|
|
static_assert(offsetof(struct evm_ima_xattr_data, data) == sizeof(struct evm_ima_xattr_data_hdr),
|
|
|
|
"struct member likely outside of __struct_group()");
|
2019-06-10 23:28:08 -07:00
|
|
|
|
|
|
|
/* Only used in the EVM HMAC code. */
|
|
|
|
struct evm_xattr {
|
integrity: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.
There is currently an object (`hdr)` in `struct ima_max_digest_data`
that contains a flexible structure (`struct ima_digest_data`):
struct ima_max_digest_data {
struct ima_digest_data hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
So, in order to avoid ending up with a flexible-array member in the
middle of a struct, we use the `__struct_group()` helper to separate
the flexible array from the rest of the members in the flexible
structure:
struct ima_digest_data {
__struct_group(ima_digest_data_hdr, hdr, __packed,
... the rest of the members
);
u8 digest[];
} __packed;
And similarly for `struct evm_ima_xattr_data`.
With the change described above, we can now declare an object of the
type of the tagged `struct ima_digest_data_hdr`, without embedding the
flexible array in the middle of another struct:
struct ima_max_digest_data {
struct ima_digest_data_hdr hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
And similarly for `struct evm_digest` and `struct evm_xattr`.
We also use `container_of()` whenever we need to retrieve a pointer to
the flexible structure.
So, with these changes, fix the following warnings:
security/integrity/evm/evm.h:64:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Link: https://github.com/KSPP/linux/issues/202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2024-04-04 08:00:48 -07:00
|
|
|
struct evm_ima_xattr_data_hdr data;
|
2011-03-09 12:28:20 -07:00
|
|
|
u8 digest[SHA1_DIGEST_SIZE];
|
2013-04-25 00:43:56 -07:00
|
|
|
} __packed;
|
|
|
|
|
ima: support fs-verity file digest based version 3 signatures
IMA may verify a file's integrity against a "good" value stored in the
'security.ima' xattr or as an appended signature, based on policy. When
the "good value" is stored in the xattr, the xattr may contain a file
hash or signature. In either case, the "good" value is preceded by a
header. The first byte of the xattr header indicates the type of data
- hash, signature - stored in the xattr. To support storing fs-verity
signatures in the 'security.ima' xattr requires further differentiating
the fs-verity signature from the existing IMA signature.
In addition the signatures stored in 'security.ima' xattr, need to be
disambiguated. Instead of directly signing the fs-verity digest, a new
signature format version 3 is defined as the hash of the ima_file_id
structure, which identifies the type of signature and the digest.
The IMA policy defines "which" files are to be measured, verified, and/or
audited. For those files being verified, the policy rules indicate "how"
the file should be verified. For example to require a file be signed,
the appraise policy rule must include the 'appraise_type' option.
appraise_type:= [imasig] | [imasig|modsig] | [sigv3]
where 'imasig' is the original or signature format v2 (default),
where 'modsig' is an appended signature,
where 'sigv3' is the signature format v3.
The policy rule must also indicate the type of digest, if not the IMA
default, by first specifying the digest type:
digest_type:= [verity]
The following policy rule requires fsverity signatures. The rule may be
constrained, for example based on a fsuuid or LSM label.
appraise func=BPRM_CHECK digest_type=verity appraise_type=sigv3
Acked-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2021-11-24 08:56:33 -07:00
|
|
|
#define IMA_MAX_DIGEST_SIZE HASH_MAX_DIGESTSIZE
|
2013-04-25 00:43:56 -07:00
|
|
|
|
|
|
|
struct ima_digest_data {
|
integrity: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.
There is currently an object (`hdr)` in `struct ima_max_digest_data`
that contains a flexible structure (`struct ima_digest_data`):
struct ima_max_digest_data {
struct ima_digest_data hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
So, in order to avoid ending up with a flexible-array member in the
middle of a struct, we use the `__struct_group()` helper to separate
the flexible array from the rest of the members in the flexible
structure:
struct ima_digest_data {
__struct_group(ima_digest_data_hdr, hdr, __packed,
... the rest of the members
);
u8 digest[];
} __packed;
And similarly for `struct evm_ima_xattr_data`.
With the change described above, we can now declare an object of the
type of the tagged `struct ima_digest_data_hdr`, without embedding the
flexible array in the middle of another struct:
struct ima_max_digest_data {
struct ima_digest_data_hdr hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
And similarly for `struct evm_digest` and `struct evm_xattr`.
We also use `container_of()` whenever we need to retrieve a pointer to
the flexible structure.
So, with these changes, fix the following warnings:
security/integrity/evm/evm.h:64:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Link: https://github.com/KSPP/linux/issues/202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2024-04-04 08:00:48 -07:00
|
|
|
/* New members must be added within the __struct_group() macro below. */
|
|
|
|
__struct_group(ima_digest_data_hdr, hdr, __packed,
|
2013-04-25 00:43:56 -07:00
|
|
|
u8 algo;
|
|
|
|
u8 length;
|
2013-08-12 01:22:51 -07:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
u8 unused;
|
|
|
|
u8 type;
|
|
|
|
} sha1;
|
|
|
|
struct {
|
|
|
|
u8 type;
|
|
|
|
u8 algo;
|
|
|
|
} ng;
|
|
|
|
u8 data[2];
|
|
|
|
} xattr;
|
integrity: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.
There is currently an object (`hdr)` in `struct ima_max_digest_data`
that contains a flexible structure (`struct ima_digest_data`):
struct ima_max_digest_data {
struct ima_digest_data hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
So, in order to avoid ending up with a flexible-array member in the
middle of a struct, we use the `__struct_group()` helper to separate
the flexible array from the rest of the members in the flexible
structure:
struct ima_digest_data {
__struct_group(ima_digest_data_hdr, hdr, __packed,
... the rest of the members
);
u8 digest[];
} __packed;
And similarly for `struct evm_ima_xattr_data`.
With the change described above, we can now declare an object of the
type of the tagged `struct ima_digest_data_hdr`, without embedding the
flexible array in the middle of another struct:
struct ima_max_digest_data {
struct ima_digest_data_hdr hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
And similarly for `struct evm_digest` and `struct evm_xattr`.
We also use `container_of()` whenever we need to retrieve a pointer to
the flexible structure.
So, with these changes, fix the following warnings:
security/integrity/evm/evm.h:64:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Link: https://github.com/KSPP/linux/issues/202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2024-04-04 08:00:48 -07:00
|
|
|
);
|
2020-05-28 07:35:11 -07:00
|
|
|
u8 digest[];
|
2013-04-25 00:43:56 -07:00
|
|
|
} __packed;
|
2024-08-08 15:04:59 -07:00
|
|
|
static_assert(offsetof(struct ima_digest_data, digest) == sizeof(struct ima_digest_data_hdr),
|
|
|
|
"struct member likely outside of __struct_group()");
|
2011-03-09 12:28:20 -07:00
|
|
|
|
2022-01-24 12:26:23 -07:00
|
|
|
/*
|
|
|
|
* Instead of wrapping the ima_digest_data struct inside a local structure
|
|
|
|
* with the maximum hash size, define ima_max_digest_data struct.
|
|
|
|
*/
|
|
|
|
struct ima_max_digest_data {
|
integrity: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.
There is currently an object (`hdr)` in `struct ima_max_digest_data`
that contains a flexible structure (`struct ima_digest_data`):
struct ima_max_digest_data {
struct ima_digest_data hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
So, in order to avoid ending up with a flexible-array member in the
middle of a struct, we use the `__struct_group()` helper to separate
the flexible array from the rest of the members in the flexible
structure:
struct ima_digest_data {
__struct_group(ima_digest_data_hdr, hdr, __packed,
... the rest of the members
);
u8 digest[];
} __packed;
And similarly for `struct evm_ima_xattr_data`.
With the change described above, we can now declare an object of the
type of the tagged `struct ima_digest_data_hdr`, without embedding the
flexible array in the middle of another struct:
struct ima_max_digest_data {
struct ima_digest_data_hdr hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;
And similarly for `struct evm_digest` and `struct evm_xattr`.
We also use `container_of()` whenever we need to retrieve a pointer to
the flexible structure.
So, with these changes, fix the following warnings:
security/integrity/evm/evm.h:64:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/evm/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/ima/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
security/integrity/platform_certs/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Link: https://github.com/KSPP/linux/issues/202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2024-04-04 08:00:48 -07:00
|
|
|
struct ima_digest_data_hdr hdr;
|
2022-01-24 12:26:23 -07:00
|
|
|
u8 digest[HASH_MAX_DIGESTSIZE];
|
|
|
|
} __packed;
|
|
|
|
|
2013-04-25 00:44:04 -07:00
|
|
|
/*
|
ima: support fs-verity file digest based version 3 signatures
IMA may verify a file's integrity against a "good" value stored in the
'security.ima' xattr or as an appended signature, based on policy. When
the "good value" is stored in the xattr, the xattr may contain a file
hash or signature. In either case, the "good" value is preceded by a
header. The first byte of the xattr header indicates the type of data
- hash, signature - stored in the xattr. To support storing fs-verity
signatures in the 'security.ima' xattr requires further differentiating
the fs-verity signature from the existing IMA signature.
In addition the signatures stored in 'security.ima' xattr, need to be
disambiguated. Instead of directly signing the fs-verity digest, a new
signature format version 3 is defined as the hash of the ima_file_id
structure, which identifies the type of signature and the digest.
The IMA policy defines "which" files are to be measured, verified, and/or
audited. For those files being verified, the policy rules indicate "how"
the file should be verified. For example to require a file be signed,
the appraise policy rule must include the 'appraise_type' option.
appraise_type:= [imasig] | [imasig|modsig] | [sigv3]
where 'imasig' is the original or signature format v2 (default),
where 'modsig' is an appended signature,
where 'sigv3' is the signature format v3.
The policy rule must also indicate the type of digest, if not the IMA
default, by first specifying the digest type:
digest_type:= [verity]
The following policy rule requires fsverity signatures. The rule may be
constrained, for example based on a fsuuid or LSM label.
appraise func=BPRM_CHECK digest_type=verity appraise_type=sigv3
Acked-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2021-11-24 08:56:33 -07:00
|
|
|
* signature header format v2 - for using with asymmetric keys
|
|
|
|
*
|
|
|
|
* The signature_v2_hdr struct includes a signature format version
|
|
|
|
* to simplify defining new signature formats.
|
|
|
|
*
|
|
|
|
* signature format:
|
|
|
|
* version 2: regular file data hash based signature
|
|
|
|
* version 3: struct ima_file_id data based signature
|
2013-04-25 00:44:04 -07:00
|
|
|
*/
|
|
|
|
struct signature_v2_hdr {
|
2013-10-10 00:12:03 -07:00
|
|
|
uint8_t type; /* xattr type */
|
2013-04-25 00:44:04 -07:00
|
|
|
uint8_t version; /* signature format version */
|
2016-03-03 14:49:27 -07:00
|
|
|
uint8_t hash_algo; /* Digest algorithm [enum hash_algo] */
|
2017-06-07 18:49:10 -07:00
|
|
|
__be32 keyid; /* IMA key identifier - not X509/PGP specific */
|
|
|
|
__be16 sig_size; /* signature size */
|
2020-05-28 07:35:11 -07:00
|
|
|
uint8_t sig[]; /* signature payload */
|
2013-04-25 00:44:04 -07:00
|
|
|
} __packed;
|
|
|
|
|
ima: support fs-verity file digest based version 3 signatures
IMA may verify a file's integrity against a "good" value stored in the
'security.ima' xattr or as an appended signature, based on policy. When
the "good value" is stored in the xattr, the xattr may contain a file
hash or signature. In either case, the "good" value is preceded by a
header. The first byte of the xattr header indicates the type of data
- hash, signature - stored in the xattr. To support storing fs-verity
signatures in the 'security.ima' xattr requires further differentiating
the fs-verity signature from the existing IMA signature.
In addition the signatures stored in 'security.ima' xattr, need to be
disambiguated. Instead of directly signing the fs-verity digest, a new
signature format version 3 is defined as the hash of the ima_file_id
structure, which identifies the type of signature and the digest.
The IMA policy defines "which" files are to be measured, verified, and/or
audited. For those files being verified, the policy rules indicate "how"
the file should be verified. For example to require a file be signed,
the appraise policy rule must include the 'appraise_type' option.
appraise_type:= [imasig] | [imasig|modsig] | [sigv3]
where 'imasig' is the original or signature format v2 (default),
where 'modsig' is an appended signature,
where 'sigv3' is the signature format v3.
The policy rule must also indicate the type of digest, if not the IMA
default, by first specifying the digest type:
digest_type:= [verity]
The following policy rule requires fsverity signatures. The rule may be
constrained, for example based on a fsuuid or LSM label.
appraise func=BPRM_CHECK digest_type=verity appraise_type=sigv3
Acked-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2021-11-24 08:56:33 -07:00
|
|
|
/*
|
|
|
|
* IMA signature version 3 disambiguates the data that is signed, by
|
|
|
|
* indirectly signing the hash of the ima_file_id structure data,
|
|
|
|
* containing either the fsverity_descriptor struct digest or, in the
|
|
|
|
* future, the regular IMA file hash.
|
|
|
|
*
|
|
|
|
* (The hash of the ima_file_id structure is only of the portion used.)
|
|
|
|
*/
|
|
|
|
struct ima_file_id {
|
|
|
|
__u8 hash_type; /* xattr type [enum evm_ima_xattr_type] */
|
|
|
|
__u8 hash_algorithm; /* Digest algorithm [enum hash_algo] */
|
|
|
|
__u8 hash[HASH_MAX_DIGESTSIZE];
|
|
|
|
} __packed;
|
|
|
|
|
2014-11-05 08:01:12 -07:00
|
|
|
int integrity_kernel_read(struct file *file, loff_t offset,
|
2017-06-07 18:49:10 -07:00
|
|
|
void *addr, unsigned long count);
|
|
|
|
|
2011-10-05 01:54:46 -07:00
|
|
|
#define INTEGRITY_KEYRING_EVM 0
|
2015-10-22 11:26:10 -07:00
|
|
|
#define INTEGRITY_KEYRING_IMA 1
|
2018-12-12 18:39:09 -07:00
|
|
|
#define INTEGRITY_KEYRING_PLATFORM 2
|
2022-01-25 19:58:28 -07:00
|
|
|
#define INTEGRITY_KEYRING_MACHINE 3
|
|
|
|
#define INTEGRITY_KEYRING_MAX 4
|
2011-10-05 01:54:46 -07:00
|
|
|
|
2018-05-11 16:12:34 -07:00
|
|
|
extern struct dentry *integrity_dir;
|
|
|
|
|
2019-06-27 19:19:30 -07:00
|
|
|
struct modsig;
|
|
|
|
|
2012-01-17 08:12:07 -07:00
|
|
|
#ifdef CONFIG_INTEGRITY_SIGNATURE
|
2011-10-05 01:54:46 -07:00
|
|
|
|
|
|
|
int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
|
2013-10-09 23:56:13 -07:00
|
|
|
const char *digest, int digestlen);
|
2019-06-27 19:19:30 -07:00
|
|
|
int integrity_modsig_verify(unsigned int id, const struct modsig *modsig);
|
2011-10-05 01:54:46 -07:00
|
|
|
|
2014-10-01 11:43:07 -07:00
|
|
|
int __init integrity_init_keyring(const unsigned int id);
|
2014-11-26 07:55:00 -07:00
|
|
|
int __init integrity_load_x509(const unsigned int id, const char *path);
|
2018-12-08 13:27:00 -07:00
|
|
|
int __init integrity_load_cert(const unsigned int id, const char *source,
|
2019-07-10 18:43:43 -07:00
|
|
|
const void *data, size_t len, key_perm_t perm);
|
2011-10-05 01:54:46 -07:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline int integrity_digsig_verify(const unsigned int id,
|
|
|
|
const char *sig, int siglen,
|
|
|
|
const char *digest, int digestlen)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2019-06-27 19:19:30 -07:00
|
|
|
static inline int integrity_modsig_verify(unsigned int id,
|
|
|
|
const struct modsig *modsig)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2013-08-13 05:47:43 -07:00
|
|
|
static inline int integrity_init_keyring(const unsigned int id)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-12-08 13:27:00 -07:00
|
|
|
|
|
|
|
static inline int __init integrity_load_cert(const unsigned int id,
|
|
|
|
const char *source,
|
|
|
|
const void *data, size_t len,
|
2019-07-10 18:43:43 -07:00
|
|
|
key_perm_t perm)
|
2018-12-08 13:27:00 -07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-17 08:12:07 -07:00
|
|
|
#endif /* CONFIG_INTEGRITY_SIGNATURE */
|
2011-10-05 01:54:46 -07:00
|
|
|
|
2013-02-06 15:12:08 -07:00
|
|
|
#ifdef CONFIG_INTEGRITY_ASYMMETRIC_KEYS
|
|
|
|
int asymmetric_verify(struct key *keyring, const char *sig,
|
|
|
|
int siglen, const char *data, int datalen);
|
|
|
|
#else
|
|
|
|
static inline int asymmetric_verify(struct key *keyring, const char *sig,
|
|
|
|
int siglen, const char *data, int datalen)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-27 19:19:30 -07:00
|
|
|
#ifdef CONFIG_IMA_APPRAISE_MODSIG
|
|
|
|
int ima_modsig_verify(struct key *keyring, const struct modsig *modsig);
|
|
|
|
#else
|
|
|
|
static inline int ima_modsig_verify(struct key *keyring,
|
|
|
|
const struct modsig *modsig)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-11-05 08:01:14 -07:00
|
|
|
#ifdef CONFIG_IMA_LOAD_X509
|
|
|
|
void __init ima_load_x509(void);
|
|
|
|
#else
|
|
|
|
static inline void ima_load_x509(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-22 11:26:21 -07:00
|
|
|
#ifdef CONFIG_EVM_LOAD_X509
|
|
|
|
void __init evm_load_x509(void);
|
|
|
|
#else
|
|
|
|
static inline void evm_load_x509(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-18 11:48:02 -07:00
|
|
|
#ifdef CONFIG_INTEGRITY_AUDIT
|
|
|
|
/* declarations */
|
|
|
|
void integrity_audit_msg(int audit_msgno, struct inode *inode,
|
|
|
|
const unsigned char *fname, const char *op,
|
|
|
|
const char *cause, int result, int info);
|
2018-06-04 13:54:54 -07:00
|
|
|
|
2020-06-18 14:10:11 -07:00
|
|
|
void integrity_audit_message(int audit_msgno, struct inode *inode,
|
|
|
|
const unsigned char *fname, const char *op,
|
|
|
|
const char *cause, int result, int info,
|
|
|
|
int errno);
|
|
|
|
|
2018-06-04 13:54:54 -07:00
|
|
|
static inline struct audit_buffer *
|
|
|
|
integrity_audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type)
|
|
|
|
{
|
|
|
|
return audit_log_start(ctx, gfp_mask, type);
|
|
|
|
}
|
|
|
|
|
2013-03-18 11:48:02 -07:00
|
|
|
#else
|
|
|
|
static inline void integrity_audit_msg(int audit_msgno, struct inode *inode,
|
|
|
|
const unsigned char *fname,
|
|
|
|
const char *op, const char *cause,
|
|
|
|
int result, int info)
|
|
|
|
{
|
|
|
|
}
|
2018-06-04 13:54:54 -07:00
|
|
|
|
2020-06-18 14:10:11 -07:00
|
|
|
static inline void integrity_audit_message(int audit_msgno,
|
|
|
|
struct inode *inode,
|
|
|
|
const unsigned char *fname,
|
|
|
|
const char *op, const char *cause,
|
|
|
|
int result, int info, int errno)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-04 13:54:54 -07:00
|
|
|
static inline struct audit_buffer *
|
|
|
|
integrity_audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-18 11:48:02 -07:00
|
|
|
#endif
|
2018-12-08 13:27:00 -07:00
|
|
|
|
|
|
|
#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING
|
|
|
|
void __init add_to_platform_keyring(const char *source, const void *data,
|
|
|
|
size_t len);
|
|
|
|
#else
|
|
|
|
static inline void __init add_to_platform_keyring(const char *source,
|
|
|
|
const void *data, size_t len)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2022-01-25 19:58:28 -07:00
|
|
|
|
|
|
|
#ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
|
|
|
|
void __init add_to_machine_keyring(const char *source, const void *data, size_t len);
|
2023-08-15 04:27:20 -07:00
|
|
|
bool __init imputed_trust_enabled(void);
|
2022-01-25 19:58:28 -07:00
|
|
|
#else
|
|
|
|
static inline void __init add_to_machine_keyring(const char *source,
|
|
|
|
const void *data, size_t len)
|
|
|
|
{
|
|
|
|
}
|
2023-08-15 04:27:20 -07:00
|
|
|
|
|
|
|
static inline bool __init imputed_trust_enabled(void)
|
2022-01-25 19:58:34 -07:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2022-01-25 19:58:28 -07:00
|
|
|
#endif
|