Skip to contentSkip to conversation

make default hash algorithm dynamic

PATCH Superseded Bruno Meneguele 2 participants 5 messages Aug 20, 2021 – Aug 26, 2021 Keys-trusted

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover make default hash algorithm dynamic

In order to allow the distros and users to set their own security policies, this patch enable a option in configuration time to set the default hash algorithm to be used. Today, only SHA1 and SHA256 is supported by ima-evm-utils, but it'll change some day, enabling this dynamic mechanism facilitates distro maintainers' lives.

At the same time, move from SHA1 to SHA256 default hash algorithm, following the general movement of dropping SHA1 support in the major distros due to its weaknesses.

Changelog:
v3: remove wrong comment from m4 script
v2: add a config time option for setting DEFAULT_HASH_ALGO.

Bruno Meneguele (2):
set default hash algorithm in configuration time make SHA-256 the default hash algorithm

 README                  |  2 +-
 configure.ac            |  1 +
 m4/default-hash-algo.m4 | 46 +++++++++++++++++++++++++++++++++++++++++
 src/evmctl.c            |  4 ++--
 src/imaevm.h            |  4 ++++
 src/libimaevm.c         |  2 +-
 6 files changed, 55 insertions(+), 4 deletions(-)
 create mode 100644 m4/default-hash-algo.m4
Signature · 1 line
2.31.1
#1 lore raw

PATCH v4 1/2 set default hash algorithm in configuration time

The default hash algorithm for evmctl is today hardcoded libimaevm.c file. To facilitate different distributions and users to set their own default hash algorithm this patch adds the --with-default-hash=<algo> option to the configuration script.

The algorithm chosen by the user will then be checked if is available in the kernel, otherwise IMA won't be able to verify files hashed by the user. For that, the file exposed by the kernel crypto API (/proc/crypto) is filtered by an AWK script in order to check the algorithm's name and the module providing it. Initally, only "module: kernel" is accepted, following IMA's CONFIG_CRYPTO_SHA1/SHA256 dependency.

---
Changelog:
v3 - remove wrong m4 script comment

 README                  |  2 +-
 configure.ac            |  1 +
 m4/default-hash-algo.m4 | 46 +++++++++++++++++++++++++++++++++++++++++
 src/evmctl.c            |  4 ++--
 src/imaevm.h            |  4 ++++
 src/libimaevm.c         |  2 +-
 6 files changed, 55 insertions(+), 4 deletions(-)
 create mode 100644 m4/default-hash-algo.m4
README +1 -1
index 87cd3b5cd7da..4e35826cd982 100644
@@ -41,7 +41,7 @@ COMMANDS
 OPTIONS
 -------
 
-  -a, --hashalgo     sha1 (default), sha224, sha256, sha384, sha512
+  -a, --hashalgo     sha1, sha224, sha256, sha384, sha512
   -s, --imasig       make IMA signature
   -d, --imahash      make IMA hash
   -f, --sigfile      store IMA signature in .sig file instead of xattr
configure.ac +1 -0
index a2d91b3db202..1c45f7f757ea 100644
@@ -62,6 +62,7 @@ else
 fi
 
 EVMCTL_MANPAGE_DOCBOOK_XSL
+AX_DEFAULT_HASH_ALGO
 
 # for gcov
 #CFLAGS="$CFLAGS -Wall -fprofile-arcs -ftest-coverage"
m4/default-hash-algo.m4 new file +46 -0

46 lines not on this page · raw message

src/evmctl.c +2 -2
index c999589943aa..d9385a225e88 100644
@@ -2500,7 +2500,7 @@ static void usage(void)
 
 	printf(
 		"\n"
-		"  -a, --hashalgo     sha1 (default), sha224, sha256, sha384, sha512, streebog256, streebog512\n"
+		"  -a, --hashalgo     sha1, sha224, sha256, sha384, sha512, streebog256, streebog512 (default: %s)\n"
 		"  -s, --imasig       make IMA signature\n"
 		"  -d, --imahash      make IMA hash\n"
 		"  -f, --sigfile      store IMA signature in .sig file instead of xattr\n"
@@ -2534,7 +2534,7 @@ static void usage(void)
 		"      --ignore-violations ignore ToMToU measurement violations\n"
 		"  -v                 increase verbosity level\n"
 		"  -h, --help         display this help and exit\n"
-		"\n");
+		"\n", DEFAULT_HASH_ALGO);
 }
 
 struct command cmds[] = {
src/imaevm.h +4 -0
index 491f136c105f..cc3dfd2e9163 100644
@@ -74,6 +74,10 @@
 #define log_err(fmt, args...)		do_log(LOG_ERR, fmt, ##args)
 #define log_errno(fmt, args...)		do_log(LOG_ERR, fmt ": errno: %s (%d)\n", ##args, strerror(errno), errno)
 
+#ifndef DEFAULT_HASH_ALGO
+#define DEFAULT_HASH_ALGO "sha1"
+#endif
+
 #define	DATA_SIZE	4096
 #define SHA1_HASH_LEN   20
 
src/libimaevm.c +1 -1
index 8e9615796153..2555e58a873b 100644
@@ -88,7 +88,7 @@ static const char *const pkey_hash_algo_kern[PKEY_HASH__LAST] = {
 struct libimaevm_params imaevm_params = {
 	.verbose = LOG_INFO,
 	.x509 = 1,
-	.hash_algo = "sha1",
+	.hash_algo = DEFAULT_HASH_ALGO,
 };
 
 static void __attribute__ ((constructor)) libinit(void);
Signature · 1 line
2.31.1
maintainer
#2 lore raw

Re: [PATCH v4 ima-evm-utils 1/2] set default hash algorithm in configuration time

Hi Bruno,

Quoted 11 lines · Bruno Meneguele

The default hash algorithm for evmctl is today hardcoded libimaevm.c file. To facilitate different distributions and users to set their own default hash algorithm this patch adds the --with-default-hash=<algo> option to the configuration script.

The algorithm chosen by the user will then be checked if is available in the kernel, otherwise IMA won't be able to verify files hashed by the user. For that, the file exposed by the kernel crypto API (/proc/crypto) is filtered by an AWK script in order to check the algorithm's name and the module providing it. Initally, only "module: kernel" is accepted, following IMA's CONFIG_CRYPTO_SHA1/SHA256 dependency.

There's a difference between preventing an evmctl user from unintentionally using an unsupported algorithm and the distro, or whoever is building the package, defining the wrong default hash algorithm.

My preference would be to allow any hash algorithm defined in hash_info.h (kernel_headers package) as the default.

thanks,

Mimi

#3 lore raw

Re: [PATCH v4 ima-evm-utils 1/2] set default hash algorithm in configuration time

Quoted 15 lines · Mimi Zohar

Hi Bruno,

Quoted 11 lines · Bruno Meneguele

The default hash algorithm for evmctl is today hardcoded libimaevm.c file. To facilitate different distributions and users to set their own default hash algorithm this patch adds the --with-default-hash=<algo> option to the configuration script.

The algorithm chosen by the user will then be checked if is available in the kernel, otherwise IMA won't be able to verify files hashed by the user. For that, the file exposed by the kernel crypto API (/proc/crypto) is filtered by an AWK script in order to check the algorithm's name and the module providing it. Initally, only "module: kernel" is accepted, following IMA's CONFIG_CRYPTO_SHA1/SHA256 dependency.

Quoted 8 lines

There's a difference between preventing an evmctl user from unintentionally using an unsupported algorithm and the distro, or whoever is building the package, defining the wrong default hash algorithm.

My preference would be to allow any hash algorithm defined in hash_info.h (kernel_headers package) as the default.

Good point. Considering we already depend on the kernel-headers pkg and we also allow the user to specify a custom path for headers, it's indeed better to keep the consistency.

I'll prepare a v5 using the kernel-headers instead of /proc/crypto.

Quoted 4 lines

thanks,

Mimi

Signature · 2 lines
bmeneg 
PGP Key: http://bmeneg.com/pubkey.txt
#4 lore raw

PATCH v4 2/2 make SHA-256 the default hash algorithm

In reply to Bruno Meneguele

The SHA-1 algorithm is considered a weak hash algorithm and there has been some movement within certain distros to drop its support completely or at least drop it from the default behavior. ima-evm-utils uses it as the default algorithm in case the user doesn't explicitly ask for another through the --with-default-hash configuration time option or --hashalgo/-a runtime option. With that, make SHA-256 the default hash algorithm instead.

---
 m4/default-hash-algo.m4 | 2 +-
 src/imaevm.h            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
m4/default-hash-algo.m4 +1 -1
index a0b98e645fb1..f23bbf7ab3f8 100644
@@ -7,7 +7,7 @@ AC_DEFUN([AX_DEFAULT_HASH_ALGO], [
 	AC_ARG_WITH([default_hash],
 		AS_HELP_STRING([--with-default-hash=ALGORITHM], [specifies the default hash algorithm to be used]),
 		[HASH_ALGO=$withval],
-		[HASH_ALGO=sha1])
+		[HASH_ALGO=sha256])
 
 	AC_CHECK_FILE([$CRYPTO_FILE],
 		[HAVE_CRYPTO_FILE=yes],
src/imaevm.h +1 -1
index cc3dfd2e9163..ba7b23907669 100644
@@ -75,7 +75,7 @@
 #define log_errno(fmt, args...)		do_log(LOG_ERR, fmt ": errno: %s (%d)\n", ##args, strerror(errno), errno)
 
 #ifndef DEFAULT_HASH_ALGO
-#define DEFAULT_HASH_ALGO "sha1"
+#define DEFAULT_HASH_ALGO "sha256"
 #endif
 
 #define	DATA_SIZE	4096
Signature · 1 line
2.31.1