From: Vitaly Chikunov <vt@altlinux.org>
To: Mimi Zohar <zohar@linux.vnet.ibm.com>,
Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
linux-integrity@vger.kernel.org
Subject: [PATCH v2 2/5] ima-evm-utils: Fix possible xattr_value overflows in calc_evm_hash
Date: Mon, 15 Jul 2019 23:05:50 +0300 [thread overview]
Message-ID: <20190715200553.22403-2-vt@altlinux.org> (raw)
In-Reply-To: <20190715200553.22403-1-vt@altlinux.org>
`selinux_str',`caps_str', and `ima_str' are passed from the command line
but copied into the fixed-size buffer.
Yes, length of `selinux_str' is calculated differently than of `caps_str'.
Fixes: CID 229895.
---
src/evmctl.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/evmctl.c b/src/evmctl.c
index d6e0b2c..04dc546 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -401,16 +401,31 @@ static int calc_evm_hash(const char *file, unsigned char *hash)
for (xattrname = evm_config_xattrnames; *xattrname != NULL; xattrname++) {
if (!strcmp(*xattrname, XATTR_NAME_SELINUX) && selinux_str) {
- strcpy(xattr_value, selinux_str);
err = strlen(selinux_str) + 1;
+ if (err > sizeof(xattr_value)) {
+ log_err("selinux[%u] value is too long to fit into xattr[%zu]\n",
+ err, sizeof(xattr_value));
+ return -1;
+ }
+ strcpy(xattr_value, selinux_str);
} else if (!strcmp(*xattrname, XATTR_NAME_IMA) && ima_str) {
- hex2bin(xattr_value, ima_str, strlen(ima_str) / 2);
err = strlen(ima_str) / 2;
+ if (err > sizeof(xattr_value)) {
+ log_err("ima[%u] value is too long to fit into xattr[%zu]\n",
+ err, sizeof(xattr_value));
+ return -1;
+ }
+ hex2bin(xattr_value, ima_str, err);
} else if (!strcmp(*xattrname, XATTR_NAME_CAPS) && (hmac_flags & HMAC_FLAG_CAPS_SET)) {
if (!caps_str)
continue;
- strcpy(xattr_value, caps_str);
err = strlen(caps_str);
+ if (err >= sizeof(xattr_value)) {
+ log_err("caps[%u] value is too long to fit into xattr[%zu]\n",
+ err + 1, sizeof(xattr_value));
+ return -1;
+ }
+ strcpy(xattr_value, caps_str);
} else {
err = lgetxattr(file, *xattrname, xattr_value, sizeof(xattr_value));
if (err < 0) {
--
2.11.0
next prev parent reply other threads:[~2019-07-15 20:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-15 20:05 [PATCH v2 1/5] ima-evm-utils: Fix null dereference from file2bin to memcpy Vitaly Chikunov
2019-07-15 20:05 ` Vitaly Chikunov [this message]
2019-07-15 20:05 ` [PATCH v2 3/5] ima-evm-utils: Fix memory leak in get_password Vitaly Chikunov
2019-07-15 20:05 ` [PATCH v2 4/5] ima-evm-utils: Fix file2bin stat and fopen relations Vitaly Chikunov
2019-07-15 20:05 ` [PATCH v2 5/5] ima-evm-utils: Add more error checking in add_file_hash Vitaly Chikunov
2019-07-16 14:46 ` [PATCH v2 1/5] ima-evm-utils: Fix null dereference from file2bin to memcpy Mimi Zohar
2019-07-16 14:59 ` Vitaly Chikunov
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=20190715200553.22403-2-vt@altlinux.org \
--to=vt@altlinux.org \
--cc=dmitry.kasatkin@gmail.com \
--cc=linux-integrity@vger.kernel.org \
--cc=zohar@linux.vnet.ibm.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.