From: Mimi Zohar <zohar@linux.vnet.ibm.com>
To: linux-integrity@vger.kernel.org
Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
Roberto Sassu <roberto.sassu@huawei.com>,
"Bruno E . O . Meneguele" <brdeoliv@redhat.com>,
Mimi Zohar <zohar@linux.vnet.ibm.com>
Subject: [PATCH 09/10] ima-evm-utils: verify IMA file hashes stored as xattrs
Date: Mon, 22 Jan 2018 09:54:04 -0500 [thread overview]
Message-ID: <1516632845-7087-10-git-send-email-zohar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1516632845-7087-1-git-send-email-zohar@linux.vnet.ibm.com>
evmctl "ima_verify" verifies file signatures stored as xattrs on the
local filesystem. This patch adds support for verifying the file hashes
stored as xattrs.
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
---
src/evmctl.c | 3 +++
src/imaevm.h | 1 +
src/libimaevm.c | 42 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/src/evmctl.c b/src/evmctl.c
index 5d1c6ea..9142ed4 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -794,6 +794,9 @@ static int verify_ima(const char *file)
}
}
+ if (sig[0] == IMA_XATTR_DIGEST_NG || sig[0] == IMA_XATTR_DIGEST)
+ return ima_verify_hash(file, sig, len);
+
return ima_verify_signature(file, sig, len, NULL, 0);
}
diff --git a/src/imaevm.h b/src/imaevm.h
index f5cee7d..d624571 100644
--- a/src/imaevm.h
+++ b/src/imaevm.h
@@ -205,6 +205,7 @@ int key2bin(RSA *key, unsigned char *pub);
int sign_hash(const char *algo, const unsigned char *hash, int size, const char *keyfile, const char *keypass, unsigned char *sig);
int verify_hash(const unsigned char *hash, int size, unsigned char *sig, int siglen);
int ima_verify_signature(const char *file, unsigned char *sig, int siglen, unsigned char *digest, int digestlen);
+int ima_verify_hash(const char *file, unsigned char *digest, int digestlen);
void init_public_keys(const char *keyfiles);
#endif
diff --git a/src/libimaevm.c b/src/libimaevm.c
index 247100f..bc9c496 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -49,6 +49,7 @@
#include <dirent.h>
#include <string.h>
#include <stdio.h>
+#include <linux/hash_info.h>
#include <openssl/pem.h>
#include <openssl/evp.h>
@@ -613,6 +614,47 @@ int ima_verify_signature(const char *file, unsigned char *sig, int siglen,
return verify_hash(hash, hashlen, sig + 1, siglen - 1);
}
+int ima_verify_hash(const char *file, unsigned char *digest, int digestlen)
+{
+ unsigned char hash[64];
+ int hashlen, hash_algo = HASH_ALGO_SHA1;
+
+ if (digest[0] == IMA_XATTR_DIGEST_NG)
+ hash_algo = digest[1];
+
+ if (hash_algo < 0 || hash_algo > HASH_ALGO__LAST) {
+ log_err("Invalid signature\n");
+ return -1;
+ }
+
+ /* Use hash algorithm as retrieved from xattr */
+ params.hash_algo = pkey_hash_algo[hash_algo];
+
+ hashlen = ima_calc_hash(file, hash);
+ if (hashlen <= 1)
+ return hashlen;
+
+ if (digest[0] == IMA_XATTR_DIGEST_NG) {
+ if (hashlen != digestlen - 2 ||
+ memcmp(digest + 2, hash, hashlen)) {
+ log_err("Hash ng verification failed\n");
+ return -1;
+ }
+ log_info("Hash verification is OK\n");
+ return 0;
+ } else if (digest[0] == IMA_XATTR_DIGEST) {
+ if (hashlen != digestlen - 1 ||
+ memcmp(digest + 1, hash, hashlen)) {
+ log_err("Hash verification failed\n");
+ return -1;
+ }
+ log_info("Hash verification is OK\n");
+ return 0;
+ }
+ log_err("Unknown security.ima format\n");
+ return -1;
+}
+
/*
* Create binary key representation suitable for kernel
*/
--
2.7.4
next prev parent reply other threads:[~2018-01-22 14:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-22 14:53 [PATCH 00/10] ima-evm-utils Mimi Zohar
2018-01-22 14:53 ` [PATCH 01/10] ima-evm-utils: fix "ima_measurement" template fields length Mimi Zohar
2018-01-22 14:53 ` [PATCH 02/10] ima-evm-utils: revert the change to use printf instead of log_info() Mimi Zohar
2018-01-22 14:53 ` [PATCH 03/10] ima-evm-utils: fix spelling error Mimi Zohar
2018-01-22 14:53 ` [PATCH 04/10] ima-evm-utils: remove the unnecessary display of the keyid Mimi Zohar
2018-01-22 14:54 ` [PATCH 05/10] ima-evm-utils: support verifying the measurement list using multiple keys Mimi Zohar
2018-01-22 14:54 ` [PATCH 06/10] ima-evm-utils: indicate measurement list signature verification failure Mimi Zohar
2018-01-22 14:54 ` [PATCH 07/10] ima-evm-utils: add support for specifying the pcr file location Mimi Zohar
2018-01-22 14:54 ` [PATCH 08/10] ima-evm-utils: verify the measurement list signature based on the list digest Mimi Zohar
2018-01-22 14:54 ` Mimi Zohar [this message]
2018-01-22 14:54 ` [PATCH 10/10] ima-evm-utils: add support for validating multiple pcrs Mimi Zohar
2018-01-28 19:01 ` [PATCH 00/10] ima-evm-utils Mimi Zohar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1516632845-7087-10-git-send-email-zohar@linux.vnet.ibm.com \
--to=zohar@linux.vnet.ibm.com \
--cc=brdeoliv@redhat.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=linux-integrity@vger.kernel.org \
--cc=roberto.sassu@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.