Re: [PATCH ima-evm-utils v5 17/17] Make sure the key file is a regular file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 11/3/22 14:39, Mimi Zohar wrote:
Before attempting to use the key file, make sure it is a regular file.

Signed-off-by: Mimi Zohar <zohar@xxxxxxxxxxxxx>
---
  src/libimaevm.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)

diff --git a/src/libimaevm.c b/src/libimaevm.c
index 8070ffd61a2c..c09ed98fe508 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -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);

no errno reset needed here I guess...

+		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);

Reviewed-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux