1
0
mirror of https://git.code.sf.net/p/linux-ima/ima-evm-utils synced 2025-04-27 22:32:31 +02:00

Make sure the key file is a regular file

Before attempting to use the key file, make sure it is a regular file.

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
Mimi Zohar 2022-09-11 14:51:52 -04:00
parent 297d01bdb6
commit c8b1757270

View File

@ -250,6 +250,7 @@ EVP_PKEY *read_pub_pkey(const char *keyfile, int x509)
{
FILE *fp;
EVP_PKEY *pkey = NULL;
struct stat st;
if (!keyfile)
return NULL;
@ -261,6 +262,17 @@ EVP_PKEY *read_pub_pkey(const char *keyfile, int x509)
return NULL;
}
if (fstat(fileno(fp), &st) == -1) {
log_err("Failed to fstat key file: %s\n", keyfile);
goto out;
}
if ((st.st_mode & S_IFMT) != S_IFREG) {
if (imaevm_params.verbose > LOG_INFO)
log_err("Key file is not regular file: %s\n", keyfile);
goto out;
}
if (x509) {
X509 *crt = d2i_X509_fp(fp, NULL);