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

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