Blame SOURCES/gnutls-3.7.8-rsa-kx-timing.patch

c3afe7
From c149dd0767f32789e391280cb1eb06b7eb7c6bce Mon Sep 17 00:00:00 2001
c3afe7
From: Alexander Sosedkin <asosedkin@redhat.com>
c3afe7
Date: Tue, 9 Aug 2022 16:05:53 +0200
c3afe7
Subject: [PATCH 1/2] auth/rsa: side-step potential side-channel
c3afe7
c3afe7
Remove branching that depends on secret data.
c3afe7
c3afe7
Signed-off-by: Alexander Sosedkin <asosedkin@redhat.com>
c3afe7
Signed-off-by: Hubert Kario <hkario@redhat.com>
c3afe7
Tested-by: Hubert Kario <hkario@redhat.com>
c3afe7
---
c3afe7
 lib/auth/rsa.c | 10 ----------
c3afe7
 1 file changed, 10 deletions(-)
c3afe7
c3afe7
diff --git a/lib/auth/rsa.c b/lib/auth/rsa.c
c3afe7
index 8108ee841d..6b158bacb2 100644
c3afe7
--- a/lib/auth/rsa.c
c3afe7
+++ b/lib/auth/rsa.c
c3afe7
@@ -155,7 +155,6 @@ static int
c3afe7
 proc_rsa_client_kx(gnutls_session_t session, uint8_t * data,
c3afe7
 		   size_t _data_size)
c3afe7
 {
c3afe7
-	const char attack_error[] = "auth_rsa: Possible PKCS #1 attack\n";
c3afe7
 	gnutls_datum_t ciphertext;
c3afe7
 	int ret, dsize;
c3afe7
 	ssize_t data_size = _data_size;
c3afe7
@@ -235,15 +234,6 @@ proc_rsa_client_kx(gnutls_session_t session, uint8_t * data,
c3afe7
 	ok &= CONSTCHECK_NOT_EQUAL(check_ver_min, 0) &
c3afe7
 	        CONSTCHECK_EQUAL(session->key.key.data[1], ver_min);
c3afe7
 
c3afe7
-	if (ok) {
c3afe7
-		/* call logging function unconditionally so all branches are
c3afe7
-		 * indistinguishable for timing and cache access when debug
c3afe7
-		 * logging is disabled */
c3afe7
-		_gnutls_no_log("%s", attack_error);
c3afe7
-	} else {
c3afe7
-		_gnutls_debug_log("%s", attack_error);
c3afe7
-	}
c3afe7
-
c3afe7
 	/* This is here to avoid the version check attack
c3afe7
 	 * discussed above.
c3afe7
 	 */
c3afe7
-- 
c3afe7
2.39.1
c3afe7
c3afe7
c3afe7
From 7c963102ec2119eecc1789b993aabe5edfd75f3b Mon Sep 17 00:00:00 2001
c3afe7
From: Hubert Kario <hkario@redhat.com>
c3afe7
Date: Wed, 8 Feb 2023 14:32:09 +0100
c3afe7
Subject: [PATCH 2/2] rsa: remove dead code
c3afe7
c3afe7
since the `ok` variable isn't used any more, we can remove all code
c3afe7
used to calculate it
c3afe7
c3afe7
Signed-off-by: Hubert Kario <hkario@redhat.com>
c3afe7
---
c3afe7
 lib/auth/rsa.c | 20 +++-----------------
c3afe7
 1 file changed, 3 insertions(+), 17 deletions(-)
c3afe7
c3afe7
diff --git a/lib/auth/rsa.c b/lib/auth/rsa.c
c3afe7
index 6b158bacb2..858701fe6e 100644
c3afe7
--- a/lib/auth/rsa.c
c3afe7
+++ b/lib/auth/rsa.c
c3afe7
@@ -159,8 +159,6 @@ proc_rsa_client_kx(gnutls_session_t session, uint8_t * data,
c3afe7
 	int ret, dsize;
c3afe7
 	ssize_t data_size = _data_size;
c3afe7
 	volatile uint8_t ver_maj, ver_min;
c3afe7
-	volatile uint8_t check_ver_min;
c3afe7
-	volatile uint32_t ok;
c3afe7
 
c3afe7
 #ifdef ENABLE_SSL3
c3afe7
 	if (get_num_version(session) == GNUTLS_SSL3) {
c3afe7
@@ -186,7 +184,6 @@ proc_rsa_client_kx(gnutls_session_t session, uint8_t * data,
c3afe7
 
c3afe7
 	ver_maj = _gnutls_get_adv_version_major(session);
c3afe7
 	ver_min = _gnutls_get_adv_version_minor(session);
c3afe7
-	check_ver_min = (session->internals.allow_wrong_pms == 0);
c3afe7
 
c3afe7
 	session->key.key.data = gnutls_malloc(GNUTLS_MASTER_SIZE);
c3afe7
 	if (session->key.key.data == NULL) {
c3afe7
@@ -205,10 +202,9 @@ proc_rsa_client_kx(gnutls_session_t session, uint8_t * data,
c3afe7
 		return ret;
c3afe7
 	}
c3afe7
 
c3afe7
-	ret =
c3afe7
-	    gnutls_privkey_decrypt_data2(session->internals.selected_key,
c3afe7
-					 0, &ciphertext, session->key.key.data,
c3afe7
-					 session->key.key.size);
c3afe7
+	gnutls_privkey_decrypt_data2(session->internals.selected_key,
c3afe7
+				     0, &ciphertext, session->key.key.data,
c3afe7
+				     session->key.key.size);
c3afe7
 	/* After this point, any conditional on failure that cause differences
c3afe7
 	 * in execution may create a timing or cache access pattern side
c3afe7
 	 * channel that can be used as an oracle, so treat very carefully */
c3afe7
@@ -224,16 +220,6 @@ proc_rsa_client_kx(gnutls_session_t session, uint8_t * data,
c3afe7
 	 * Vlastimil Klima, Ondej Pokorny and Tomas Rosa.
c3afe7
 	 */
c3afe7
 
c3afe7
-	/* ok is 0 in case of error and 1 in case of success. */
c3afe7
-
c3afe7
-	/* if ret < 0 */
c3afe7
-	ok = CONSTCHECK_EQUAL(ret, 0);
c3afe7
-	/* session->key.key.data[0] must equal ver_maj */
c3afe7
-	ok &= CONSTCHECK_EQUAL(session->key.key.data[0], ver_maj);
c3afe7
-	/* if check_ver_min then session->key.key.data[1] must equal ver_min */
c3afe7
-	ok &= CONSTCHECK_NOT_EQUAL(check_ver_min, 0) &
c3afe7
-	        CONSTCHECK_EQUAL(session->key.key.data[1], ver_min);
c3afe7
-
c3afe7
 	/* This is here to avoid the version check attack
c3afe7
 	 * discussed above.
c3afe7
 	 */
c3afe7
-- 
c3afe7
2.39.1
c3afe7