Blame SOURCES/gnutls-3.6.14-fips-mode-check.patch

e9c22b
From d1dc655cd2c8ae417381e5f966941c75cfe287ee Mon Sep 17 00:00:00 2001
e9c22b
From: Daiki Ueno <ueno@gnu.org>
e9c22b
Date: Thu, 4 Jun 2020 16:42:07 +0200
e9c22b
Subject: [PATCH] _gnutls_fips_mode_enabled: treat selftest failure as FIPS
e9c22b
 disabled
e9c22b
e9c22b
Previously gnutls_fips140_mode_enabled() returned true, even after
e9c22b
selftests have failed and the library state has switched to error.
e9c22b
While later calls to crypto operations fails, it would be more
e9c22b
convenient to have a function to detect that state.
e9c22b
e9c22b
Signed-off-by: Daiki Ueno <ueno@gnu.org>
e9c22b
---
e9c22b
 lib/fips.c | 11 ++++++++++-
e9c22b
 1 file changed, 10 insertions(+), 1 deletion(-)
e9c22b
e9c22b
diff --git a/lib/fips.c b/lib/fips.c
e9c22b
index acdd2ec23..f8b10f750 100644
e9c22b
--- a/lib/fips.c
e9c22b
+++ b/lib/fips.c
e9c22b
@@ -491,8 +491,17 @@ unsigned gnutls_fips140_mode_enabled(void)
e9c22b
 #ifdef ENABLE_FIPS140
e9c22b
 	unsigned ret = _gnutls_fips_mode_enabled();
e9c22b
 
e9c22b
-	if (ret > GNUTLS_FIPS140_DISABLED)
e9c22b
+	if (ret > GNUTLS_FIPS140_DISABLED) {
e9c22b
+		/* If the previous run of selftests has failed, return as if
e9c22b
+		 * the FIPS mode is disabled. We could use HAVE_LIB_ERROR, if
e9c22b
+		 * we can assume that all the selftests run atomically from
e9c22b
+		 * the ELF constructor.
e9c22b
+		 */
e9c22b
+		if (_gnutls_get_lib_state() == LIB_STATE_ERROR)
e9c22b
+			return 0;
e9c22b
+
e9c22b
 		return ret;
e9c22b
+	}
e9c22b
 #endif
e9c22b
 	return 0;
e9c22b
 }
e9c22b
-- 
e9c22b
2.26.2
e9c22b