Skip to contentSkip to conversation

libimaevm: Remove digest calculations not supported by IMA

PATCH Superseded Stefan Berger 2 participants 5 messages Jun 30, 2021 – Jul 6, 2021 Keys-trusted

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/3 libimaevm: Remove calculation of a digest over a device file

In reply to Stefan Berger

Signature verification on device files is not supported by IMA in the kernel, so remove calculation of digests over devices files.

---
 src/libimaevm.c | 14 --------------
 1 file changed, 14 deletions(-)
src/libimaevm.c +0 -14
index 2856270..4d51901 100644
@@ -225,16 +225,6 @@ static int add_link_hash(const char *path, EVP_MD_CTX *ctx)
 	return !EVP_DigestUpdate(ctx, buf, len);
 }
 
-static int add_dev_hash(struct stat *st, EVP_MD_CTX *ctx)
-{
-	uint32_t dev = st->st_rdev;
-	unsigned major = (dev & 0xfff00) >> 8;
-	unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
-
-	log_info("device: %u:%u\n", major, minor);
-	return !EVP_DigestUpdate(ctx, &dev, sizeof(dev));
-}
-
 int ima_calc_hash(const char *file, uint8_t *hash)
 {
 	const EVP_MD *md;
@@ -281,10 +271,6 @@ int ima_calc_hash(const char *file, uint8_t *hash)
 	case S_IFLNK:
 		err = add_link_hash(file, pctx);
 		break;
-	case S_IFIFO: case S_IFSOCK:
-	case S_IFCHR: case S_IFBLK:
-		err = add_dev_hash(&st, pctx);
-		break;
 	default:
 		log_err("Unsupported file type (0x%x)", st.st_mode & S_IFMT);
 		err = -1;
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/3 libimaevm: Remove calculation of a digest over a directory

In reply to Stefan Berger

Signature verification on directories is not supported by IMA in the kernel, so remove the calculation of digests over directories.

---
 src/libimaevm.c | 37 -------------------------------------
 1 file changed, 37 deletions(-)
src/libimaevm.c +0 -37
index 4d51901..07a25c9 100644
@@ -177,40 +177,6 @@ out:
 	return err;
 }
 
-static int add_dir_hash(const char *file, EVP_MD_CTX *ctx)
-{
-	struct dirent *de;
-	DIR *dir;
-	unsigned long long ino;
-	unsigned int type;
-	int result = 0;
-
-	dir = opendir(file);
-	if (!dir) {
-		log_err("Failed to open: %s\n", file);
-		return -1;
-	}
-
-	while ((de = readdir(dir))) {
-		ino = de->d_ino;
-		type = de->d_type;
-		log_debug("entry: %s, ino: %llu, type: %u, reclen: %hu\n",
-			  de->d_name, ino, type, de->d_reclen);
-		if (EVP_DigestUpdate(ctx, de->d_name, strlen(de->d_name)) != 1 ||
-		    EVP_DigestUpdate(ctx, &ino, sizeof(ino)) != 1||
-		    EVP_DigestUpdate(ctx, &type, sizeof(type)) != 1) {
-			log_err("EVP_DigestUpdate() failed\n");
-			output_openssl_errors();
-			result = 1;
-			break;
-		}
-	}
-
-	closedir(dir);
-
-	return result;
-}
-
 static int add_link_hash(const char *path, EVP_MD_CTX *ctx)
 {
 	int len;
@@ -265,9 +231,6 @@ int ima_calc_hash(const char *file, uint8_t *hash)
 	case S_IFREG:
 		err = add_file_hash(file, pctx);
 		break;
-	case S_IFDIR:
-		err = add_dir_hash(file, pctx);
-		break;
 	case S_IFLNK:
 		err = add_link_hash(file, pctx);
 		break;
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/3 libimaevm: Remove calculation of a digest over a symbolic link

In reply to Stefan Berger

Signature verification on symbolic links is not supported by IMA in the kernel, so remove the calculation of digests over symbolic links.

---
 src/libimaevm.c | 17 -----------------
 1 file changed, 17 deletions(-)
src/libimaevm.c +0 -17
index 07a25c9..6591d20 100644
@@ -177,20 +177,6 @@ out:
 	return err;
 }
 
-static int add_link_hash(const char *path, EVP_MD_CTX *ctx)
-{
-	int len;
-	char buf[1024];
-
-	len = readlink(path, buf, sizeof(buf));
-	/* 0-length links are also an error */
-	if (len <= 0)
-		return -1;
-
-	log_info("link: %s -> %.*s\n", path, len, buf);
-	return !EVP_DigestUpdate(ctx, buf, len);
-}
-
 int ima_calc_hash(const char *file, uint8_t *hash)
 {
 	const EVP_MD *md;
@@ -231,9 +217,6 @@ int ima_calc_hash(const char *file, uint8_t *hash)
 	case S_IFREG:
 		err = add_file_hash(file, pctx);
 		break;
-	case S_IFLNK:
-		err = add_link_hash(file, pctx);
-		break;
 	default:
 		log_err("Unsupported file type (0x%x)", st.st_mode & S_IFMT);
 		err = -1;
Signature · 1 line
2.31.1
#0 lore raw

cover libimaevm: Remove digest calculations not supported by IMA

Remove digest calculations over directories, symbolic links, and device files since those and related signature verifications are not supported by IMA in the kernel.

Regards,
Stefan

Stefan Berger (3):
libimaevm: Remove calculation of a digest over a device file
libimaevm: Remove calculation of a digest over a directory
libimaevm: Remove calculation of a digest over a symbolic link

 src/libimaevm.c | 68 -------------------------------------------------
 1 file changed, 68 deletions(-)
Signature · 1 line
2.31.1
maintainer Reviewed-by on the v1 series
#4 lore raw

Hi Stefan,

Quoted 6 lines · Stefan Berger

Remove digest calculations over directories, symbolic links, and device files since those and related signature verifications are not supported by IMA in the kernel.

Regards,
Stefan

Thanks, Stefan. Other than removing the related features from the README, it looks good.

Quoted 8 lines

Stefan Berger (3):
libimaevm: Remove calculation of a digest over a device file
libimaevm: Remove calculation of a digest over a directory
libimaevm: Remove calculation of a digest over a symbolic link

 src/libimaevm.c | 68 -------------------------------------------------
 1 file changed, 68 deletions(-)