mirror of
https://git.code.sf.net/p/linux-ima/ima-evm-utils
synced 2025-04-28 14:43:37 +02:00
ima-evm-utils: Fix hash buffer overflow in verify_evm and hmac_evm
Commit ae1319eeabd6 ("Remove hardcoding of SHA1 in EVM signatures") introduces overflow of 20 byte buffer on the stack while calculating hash. Also, invalid hash length is passed to the underlying verification function in verify_evm. This prevents any non-SHA1 hashes from being properly validated using evmctl. Fixes: ae1319eeabd6 ("Remove hardcoding of SHA1 in EVM signatures") Signed-off-by: Vitaly Chikunov <vt@altlinux.org> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
parent
15410695c7
commit
9643544701
16
src/evmctl.c
16
src/evmctl.c
@ -55,6 +55,7 @@
|
|||||||
#include <keyutils.h>
|
#include <keyutils.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
#include <openssl/pem.h>
|
#include <openssl/pem.h>
|
||||||
@ -760,13 +761,15 @@ static int cmd_sign_evm(struct command *cmd)
|
|||||||
|
|
||||||
static int verify_evm(const char *file)
|
static int verify_evm(const char *file)
|
||||||
{
|
{
|
||||||
unsigned char hash[20];
|
unsigned char hash[64];
|
||||||
unsigned char sig[1024];
|
unsigned char sig[1024];
|
||||||
|
int mdlen;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = calc_evm_hash(file, hash);
|
mdlen = calc_evm_hash(file, hash);
|
||||||
if (len <= 1)
|
assert(mdlen <= sizeof(hash));
|
||||||
return len;
|
if (mdlen <= 1)
|
||||||
|
return mdlen;
|
||||||
|
|
||||||
len = lgetxattr(file, "security.evm", sig, sizeof(sig));
|
len = lgetxattr(file, "security.evm", sig, sizeof(sig));
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
@ -779,7 +782,7 @@ static int verify_evm(const char *file)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return verify_hash(file, hash, sizeof(hash), sig + 1, len - 1);
|
return verify_hash(file, hash, mdlen, sig + 1, len - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_verify_evm(struct command *cmd)
|
static int cmd_verify_evm(struct command *cmd)
|
||||||
@ -1135,11 +1138,12 @@ out:
|
|||||||
|
|
||||||
static int hmac_evm(const char *file, const char *key)
|
static int hmac_evm(const char *file, const char *key)
|
||||||
{
|
{
|
||||||
unsigned char hash[20];
|
unsigned char hash[64];
|
||||||
unsigned char sig[1024];
|
unsigned char sig[1024];
|
||||||
int len, err;
|
int len, err;
|
||||||
|
|
||||||
len = calc_evm_hmac(file, key, hash);
|
len = calc_evm_hmac(file, key, hash);
|
||||||
|
assert(len <= sizeof(hash));
|
||||||
if (len <= 1)
|
if (len <= 1)
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user