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

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