Blame SOURCES/bz1896493-1-totemknet-Check-both-cipher-and-hash-for-crypto.patch

5fc8bb
From 4a2f48b17b06638d3d3adcae683aff1639351434 Mon Sep 17 00:00:00 2001
5fc8bb
From: Jan Friesse <jfriesse@redhat.com>
5fc8bb
Date: Tue, 10 Nov 2020 18:10:17 +0100
5fc8bb
Subject: [PATCH] totemknet: Check both cipher and hash for crypto
5fc8bb
5fc8bb
Previously only crypto cipher was used as a way to find out if crypto is
5fc8bb
enabled or disabled.
5fc8bb
5fc8bb
This usually works ok until cipher is set to none and hash to some other
5fc8bb
value (like sha1). Such config is perfectly valid and it was not
5fc8bb
supported correctly.
5fc8bb
5fc8bb
As a solution, check both cipher and hash.
5fc8bb
5fc8bb
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
5fc8bb
Reviewed-by: Fabio M. Di Nitto <fdinitto@redhat.com>
5fc8bb
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
5fc8bb
---
5fc8bb
 exec/totemknet.c | 18 +++++++++++++-----
5fc8bb
 1 file changed, 13 insertions(+), 5 deletions(-)
5fc8bb
5fc8bb
diff --git a/exec/totemknet.c b/exec/totemknet.c
5fc8bb
index c6a1649d..0834e8e4 100644
5fc8bb
--- a/exec/totemknet.c
5fc8bb
+++ b/exec/totemknet.c
5fc8bb
@@ -905,6 +905,14 @@ static void totemknet_add_config_notifications(struct totemknet_instance *instan
5fc8bb
 	LEAVE();
5fc8bb
 }
5fc8bb
 
5fc8bb
+static int totemknet_is_crypto_enabled(const struct totemknet_instance *instance)
5fc8bb
+{
5fc8bb
+
5fc8bb
+	return (!(strcmp(instance->totem_config->crypto_cipher_type, "none") == 0 &&
5fc8bb
+	    strcmp(instance->totem_config->crypto_hash_type, "none") == 0));
5fc8bb
+
5fc8bb
+}
5fc8bb
+
5fc8bb
 static int totemknet_set_knet_crypto(struct totemknet_instance *instance)
5fc8bb
 {
5fc8bb
 	struct knet_handle_crypto_cfg crypto_cfg;
5fc8bb
@@ -927,7 +935,7 @@ static int totemknet_set_knet_crypto(struct totemknet_instance *instance)
5fc8bb
 		);
5fc8bb
 
5fc8bb
 	/* If crypto is being disabled we need to explicitly allow cleartext traffic in knet */
5fc8bb
-	if (strcmp(instance->totem_config->crypto_cipher_type, "none") == 0) {
5fc8bb
+	if (!totemknet_is_crypto_enabled(instance)) {
5fc8bb
 		res = knet_handle_crypto_rx_clear_traffic(instance->knet_handle, KNET_CRYPTO_RX_ALLOW_CLEAR_TRAFFIC);
5fc8bb
 		if (res) {
5fc8bb
 			knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_rx_clear_traffic(ALLOW) failed %s", strerror(errno));
5fc8bb
@@ -1108,7 +1116,7 @@ int totemknet_initialize (
5fc8bb
 
5fc8bb
 	/* Enable crypto if requested */
5fc8bb
 #ifdef HAVE_KNET_CRYPTO_RECONF
5fc8bb
-	if (strcmp(instance->totem_config->crypto_cipher_type, "none") != 0) {
5fc8bb
+	if (totemknet_is_crypto_enabled(instance)) {
5fc8bb
 	        res = totemknet_set_knet_crypto(instance);
5fc8bb
 		if (res == 0) {
5fc8bb
 			res = knet_handle_crypto_use_config(instance->knet_handle, totem_config->crypto_index);
5fc8bb
@@ -1134,7 +1142,7 @@ int totemknet_initialize (
5fc8bb
 		}
5fc8bb
 	}
5fc8bb
 #else
5fc8bb
-	if (strcmp(instance->totem_config->crypto_cipher_type, "none") != 0) {
5fc8bb
+	if (totemknet_is_crypto_enabled(instance)) {
5fc8bb
 		res = totemknet_set_knet_crypto(instance);
5fc8bb
 		if (res) {
5fc8bb
 			knet_log_printf(LOG_DEBUG, "Failed to set up knet crypto");
5fc8bb
@@ -1616,7 +1624,7 @@ int totemknet_crypto_reconfigure_phase (
5fc8bb
 	switch (phase) {
5fc8bb
 		case CRYPTO_RECONFIG_PHASE_ACTIVATE:
5fc8bb
 			config_to_use = totem_config->crypto_index;
5fc8bb
-			if (strcmp(instance->totem_config->crypto_cipher_type, "none") == 0) {
5fc8bb
+			if (!totemknet_is_crypto_enabled(instance)) {
5fc8bb
 				config_to_use = 0; /* we are clearing it */
5fc8bb
 			}
5fc8bb
 
5fc8bb
@@ -1647,7 +1655,7 @@ int totemknet_crypto_reconfigure_phase (
5fc8bb
 			}
5fc8bb
 
5fc8bb
 			/* If crypto is enabled then disable all cleartext reception */
5fc8bb
-			if (strcmp(instance->totem_config->crypto_cipher_type, "none") != 0) {
5fc8bb
+			if (totemknet_is_crypto_enabled(instance)) {
5fc8bb
 				res = knet_handle_crypto_rx_clear_traffic(instance->knet_handle, KNET_CRYPTO_RX_DISALLOW_CLEAR_TRAFFIC);
5fc8bb
 				if (res) {
5fc8bb
 					knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_rx_clear_traffic(DISALLOW) failed %s", strerror(errno));
5fc8bb
-- 
5fc8bb
2.18.2
5fc8bb