On 2020/7/15 17:11, Roberto Sassu wrote:
-----Original Message----- From: Roberto Sassu [mailto:roberto.sassu@huawei.com] Sent: Monday, July 6, 2020 5:41 PM To: kernel@openeuler.org Cc: Silviu Vlasceanu Silviu.Vlasceanu@huawei.com Subject: [PATCH 29/35] ima: Add support for appraisal with digest lists
hulk inclusion category: feature feature: digest-lists
IMA-Appraise grants access to files with a valid signature or with actual file digest equal to the digest included in security.ima.
This patch adds support for appraisal based on digest lists. Instead of using the reference value from security.ima, this patch checks if the calculated file digest is included in the uploaded digest lists.
This functionality must be explicitly enabled by providing one of the following values for the ima_appraise_digest_list= kernel option:
digest: this mode enables appraisal verification with digest lists until EVM is initialized; after that, EVM verification must be successful even if the file digest is found in a digest list;
digest-nometadata: this mode enables appraisal verification with digest lists even after EVM has been initialized; files without security.evm are allowed if the digest of the content is found in the digest list, and security.evm is created with current values of xattrs (trust at first use); all files created in this way will have the new security.ima type EVM_IMA_XATTR_DIGEST_LIST; they can be accessed later only if this
mode has been selected.
Signed-off-by: Roberto Sassu roberto.sassu@huawei.com
.../admin-guide/kernel-parameters.txt | 9 +++ security/integrity/ima/ima.h | 5 +- security/integrity/ima/ima_appraise.c | 70 ++++++++++++++++++- security/integrity/ima/ima_main.c | 4 +- security/integrity/integrity.h | 1 + 5 files changed, 83 insertions(+), 6 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index d6423042d787..65efa24e3dd0 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1557,6 +1557,15 @@ "enforce-evm" | "log-evm" } default: "enforce"
- ima_appraise_digest_list= [IMA]
Format: { "digest" | "digest-nometadata" }
digest: enables appraisal of files with digest lists
until EVM is initialized.
digest-nometadata: enables appraisal of files with
digest lists even after EVM is initialized.
- ima_appraise_tcb [IMA] The builtin appraise policy appraises all files owned by uid=0.
diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index dbdbd9c84262..9fea7431b0cc 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -247,7 +247,7 @@ int ima_appraise_measurement(enum ima_hooks func, struct integrity_iint_cache *iint, struct file *file, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value,
int xattr_len);
int ima_must_appraise(struct inode *inode, int mask, enum ima_hooksint xattr_len, struct ima_digest *found_digest);
func); void ima_update_xattr(struct integrity_iint_cache *iint, struct file *file); enum integrity_status ima_get_cache_status(struct integrity_iint_cache *iint, @@ -258,7 +258,8 @@ static inline int ima_appraise_measurement(enum ima_hooks func, struct file *file, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value,
int xattr_len)
int xattr_len,
{ return INTEGRITY_UNKNOWN; }struct ima_digest *found_digest)
diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index f51ab67f7ab5..b7f234292054 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -17,6 +17,7 @@ #include <linux/evm.h>
#include "ima.h" +#include "ima_digest_list.h"
static bool ima_appraise_req_evm __ro_after_init; static int __init default_appraise_setup(char *str) @@ -37,6 +38,22 @@ static int __init default_appraise_setup(char *str)
__setup("ima_appraise=", default_appraise_setup);
+static bool ima_appraise_no_metadata __ro_after_init; +#ifdef CONFIG_IMA_DIGEST_LIST +static int __init appraise_digest_list_setup(char *str) +{
- if (!strncmp(str, "digest", 6)) {
ima_digest_list_actions |= IMA_APPRAISE;
if (!strcmp(str + 6, "-nometadata"))
ima_appraise_no_metadata = true;
- }
- return 1;
+} +__setup("ima_appraise_digest_list=", appraise_digest_list_setup); +#endif
- /*
- is_ima_appraise_enabled - return appraise status
@@ -70,7 +87,11 @@ static int ima_fix_xattr(struct dentry *dentry, int rc, offset; u8 algo = iint->ima_hash->algo;
- if (algo <= HASH_ALGO_SHA1) {
- if (test_bit(IMA_DIGEST_LIST, &iint->atomic_flags)) {
offset = 0;
iint->ima_hash->xattr.ng.type =
EVM_IMA_XATTR_DIGEST_LIST;
iint->ima_hash->xattr.ng.algo = algo;
- } else if (algo <= HASH_ALGO_SHA1) { offset = 1; iint->ima_hash->xattr.sha1.type = IMA_XATTR_DIGEST; } else {
@@ -165,18 +186,29 @@ int ima_appraise_measurement(enum ima_hooks func, struct integrity_iint_cache *iint, struct file *file, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value,
int xattr_len)
{ static const char op[] = "appraise_data"; const char *cause = "unknown"; struct dentry *dentry = file_dentry(file); struct inode *inode = d_backing_inode(dentry); enum integrity_status status = INTEGRITY_UNKNOWN;int xattr_len, struct ima_digest *found_digest)
- struct evm_ima_xattr_data digest_list_value;
I will fix this. Maximum size of the digest is SHA1_DIGEST_SIZE. It is not enough for SHA256 digests.
I think add a patch on top will be good.
Thanks Hanjun