|
|
e9c22b |
From 9acc0f68320db4c7c6dadacb974e77c7fbca72a7 Mon Sep 17 00:00:00 2001
|
|
|
e9c22b |
From: Daiki Ueno <ueno@gnu.org>
|
|
|
e9c22b |
Date: Sun, 21 Jun 2020 16:03:54 +0200
|
|
|
e9c22b |
Subject: [PATCH] safe_memcmp: remove in favor of gnutls_memcmp
|
|
|
e9c22b |
|
|
|
e9c22b |
Signed-off-by: Daiki Ueno <ueno@gnu.org>
|
|
|
e9c22b |
---
|
|
|
e9c22b |
lib/accelerated/x86/aes-xts-x86-aesni.c | 2 +-
|
|
|
e9c22b |
lib/ext/pre_shared_key.c | 2 +-
|
|
|
e9c22b |
lib/mem.h | 9 ---------
|
|
|
e9c22b |
lib/nettle/cipher.c | 8 ++++----
|
|
|
e9c22b |
lib/tls13/finished.c | 2 +-
|
|
|
e9c22b |
lib/x509/x509.c | 3 ++-
|
|
|
e9c22b |
6 files changed, 9 insertions(+), 17 deletions(-)
|
|
|
e9c22b |
|
|
|
e9c22b |
diff --git a/lib/accelerated/x86/aes-xts-x86-aesni.c b/lib/accelerated/x86/aes-xts-x86-aesni.c
|
|
|
e9c22b |
index 3371d0812..b904cbf00 100644
|
|
|
e9c22b |
--- a/lib/accelerated/x86/aes-xts-x86-aesni.c
|
|
|
e9c22b |
+++ b/lib/accelerated/x86/aes-xts-x86-aesni.c
|
|
|
e9c22b |
@@ -72,7 +72,7 @@ x86_aes_xts_cipher_setkey(void *_ctx, const void *userkey, size_t keysize)
|
|
|
e9c22b |
|
|
|
e9c22b |
/* Check key block according to FIPS-140-2 IG A.9 */
|
|
|
e9c22b |
if (_gnutls_fips_mode_enabled()){
|
|
|
e9c22b |
- if (safe_memcmp(key, key + (keysize / 2), keysize / 2) == 0) {
|
|
|
e9c22b |
+ if (gnutls_memcmp(key, key + (keysize / 2), keysize / 2) == 0) {
|
|
|
e9c22b |
_gnutls_switch_lib_state(LIB_STATE_ERROR);
|
|
|
e9c22b |
return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
|
|
|
e9c22b |
}
|
|
|
e9c22b |
diff --git a/lib/ext/pre_shared_key.c b/lib/ext/pre_shared_key.c
|
|
|
e9c22b |
index fef67d341..240be2162 100644
|
|
|
e9c22b |
--- a/lib/ext/pre_shared_key.c
|
|
|
e9c22b |
+++ b/lib/ext/pre_shared_key.c
|
|
|
e9c22b |
@@ -650,7 +650,7 @@ static int server_recv_params(gnutls_session_t session,
|
|
|
e9c22b |
}
|
|
|
e9c22b |
|
|
|
e9c22b |
if (_gnutls_mac_get_algo_len(prf) != binder_recvd.size ||
|
|
|
e9c22b |
- safe_memcmp(binder_value, binder_recvd.data, binder_recvd.size)) {
|
|
|
e9c22b |
+ gnutls_memcmp(binder_value, binder_recvd.data, binder_recvd.size)) {
|
|
|
e9c22b |
gnutls_assert();
|
|
|
e9c22b |
ret = GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
|
|
|
e9c22b |
goto fail;
|
|
|
e9c22b |
diff --git a/lib/mem.h b/lib/mem.h
|
|
|
e9c22b |
index dc838a2b4..d3eea97a4 100644
|
|
|
e9c22b |
--- a/lib/mem.h
|
|
|
e9c22b |
+++ b/lib/mem.h
|
|
|
e9c22b |
@@ -35,15 +35,6 @@ char *_gnutls_strdup(const char *);
|
|
|
e9c22b |
|
|
|
e9c22b |
unsigned _gnutls_mem_is_zero(const uint8_t *ptr, unsigned size);
|
|
|
e9c22b |
|
|
|
e9c22b |
-/* To avoid undefined behavior when s1 or s2 are null and n = 0 */
|
|
|
e9c22b |
-inline static
|
|
|
e9c22b |
-int safe_memcmp(const void *s1, const void *s2, size_t n)
|
|
|
e9c22b |
-{
|
|
|
e9c22b |
- if (n == 0)
|
|
|
e9c22b |
- return 0;
|
|
|
e9c22b |
- return memcmp(s1, s2, n);
|
|
|
e9c22b |
-}
|
|
|
e9c22b |
-
|
|
|
e9c22b |
#define zrelease_mpi_key(mpi) if (*mpi!=NULL) { \
|
|
|
e9c22b |
_gnutls_mpi_clear(*mpi); \
|
|
|
e9c22b |
_gnutls_mpi_release(mpi); \
|
|
|
e9c22b |
diff --git a/lib/nettle/cipher.c b/lib/nettle/cipher.c
|
|
|
e9c22b |
index b0a52deb5..ec0c1ab04 100644
|
|
|
e9c22b |
--- a/lib/nettle/cipher.c
|
|
|
e9c22b |
+++ b/lib/nettle/cipher.c
|
|
|
e9c22b |
@@ -482,7 +482,7 @@ _xts_aes128_set_encrypt_key(struct xts_aes128_key *xts_key,
|
|
|
e9c22b |
const uint8_t *key)
|
|
|
e9c22b |
{
|
|
|
e9c22b |
if (_gnutls_fips_mode_enabled() &&
|
|
|
e9c22b |
- safe_memcmp(key, key + AES128_KEY_SIZE, AES128_KEY_SIZE) == 0)
|
|
|
e9c22b |
+ gnutls_memcmp(key, key + AES128_KEY_SIZE, AES128_KEY_SIZE) == 0)
|
|
|
e9c22b |
_gnutls_switch_lib_state(LIB_STATE_ERROR);
|
|
|
e9c22b |
|
|
|
e9c22b |
xts_aes128_set_encrypt_key(xts_key, key);
|
|
|
e9c22b |
@@ -493,7 +493,7 @@ _xts_aes128_set_decrypt_key(struct xts_aes128_key *xts_key,
|
|
|
e9c22b |
const uint8_t *key)
|
|
|
e9c22b |
{
|
|
|
e9c22b |
if (_gnutls_fips_mode_enabled() &&
|
|
|
e9c22b |
- safe_memcmp(key, key + AES128_KEY_SIZE, AES128_KEY_SIZE) == 0)
|
|
|
e9c22b |
+ gnutls_memcmp(key, key + AES128_KEY_SIZE, AES128_KEY_SIZE) == 0)
|
|
|
e9c22b |
_gnutls_switch_lib_state(LIB_STATE_ERROR);
|
|
|
e9c22b |
|
|
|
e9c22b |
xts_aes128_set_decrypt_key(xts_key, key);
|
|
|
e9c22b |
@@ -504,7 +504,7 @@ _xts_aes256_set_encrypt_key(struct xts_aes256_key *xts_key,
|
|
|
e9c22b |
const uint8_t *key)
|
|
|
e9c22b |
{
|
|
|
e9c22b |
if (_gnutls_fips_mode_enabled() &&
|
|
|
e9c22b |
- safe_memcmp(key, key + AES256_KEY_SIZE, AES256_KEY_SIZE) == 0)
|
|
|
e9c22b |
+ gnutls_memcmp(key, key + AES256_KEY_SIZE, AES256_KEY_SIZE) == 0)
|
|
|
e9c22b |
_gnutls_switch_lib_state(LIB_STATE_ERROR);
|
|
|
e9c22b |
|
|
|
e9c22b |
xts_aes256_set_encrypt_key(xts_key, key);
|
|
|
e9c22b |
@@ -515,7 +515,7 @@ _xts_aes256_set_decrypt_key(struct xts_aes256_key *xts_key,
|
|
|
e9c22b |
const uint8_t *key)
|
|
|
e9c22b |
{
|
|
|
e9c22b |
if (_gnutls_fips_mode_enabled() &&
|
|
|
e9c22b |
- safe_memcmp(key, key + AES256_KEY_SIZE, AES256_KEY_SIZE) == 0)
|
|
|
e9c22b |
+ gnutls_memcmp(key, key + AES256_KEY_SIZE, AES256_KEY_SIZE) == 0)
|
|
|
e9c22b |
_gnutls_switch_lib_state(LIB_STATE_ERROR);
|
|
|
e9c22b |
|
|
|
e9c22b |
xts_aes256_set_decrypt_key(xts_key, key);
|
|
|
e9c22b |
diff --git a/lib/tls13/finished.c b/lib/tls13/finished.c
|
|
|
e9c22b |
index 68eab993e..ec646e673 100644
|
|
|
e9c22b |
--- a/lib/tls13/finished.c
|
|
|
e9c22b |
+++ b/lib/tls13/finished.c
|
|
|
e9c22b |
@@ -112,7 +112,7 @@ int _gnutls13_recv_finished(gnutls_session_t session)
|
|
|
e9c22b |
#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
|
|
e9c22b |
# warning This is unsafe for production builds
|
|
|
e9c22b |
#else
|
|
|
e9c22b |
- if (safe_memcmp(verifier, buf.data, buf.length) != 0) {
|
|
|
e9c22b |
+ if (gnutls_memcmp(verifier, buf.data, buf.length) != 0) {
|
|
|
e9c22b |
gnutls_assert();
|
|
|
e9c22b |
ret = GNUTLS_E_ERROR_IN_FINISHED_PACKET;
|
|
|
e9c22b |
goto cleanup;
|
|
|
e9c22b |
diff --git a/lib/x509/x509.c b/lib/x509/x509.c
|
|
|
e9c22b |
index 2091f3ae6..2b68fe440 100644
|
|
|
e9c22b |
--- a/lib/x509/x509.c
|
|
|
e9c22b |
+++ b/lib/x509/x509.c
|
|
|
e9c22b |
@@ -360,7 +360,8 @@ static int compare_sig_algorithm(gnutls_x509_crt_t cert)
|
|
|
e9c22b |
}
|
|
|
e9c22b |
|
|
|
e9c22b |
if (empty1 != empty2 ||
|
|
|
e9c22b |
- sp1.size != sp2.size || safe_memcmp(sp1.data, sp2.data, sp1.size) != 0) {
|
|
|
e9c22b |
+ sp1.size != sp2.size ||
|
|
|
e9c22b |
+ (sp1.size > 0 && memcmp(sp1.data, sp2.data, sp1.size) != 0)) {
|
|
|
e9c22b |
gnutls_assert();
|
|
|
e9c22b |
ret = GNUTLS_E_CERTIFICATE_ERROR;
|
|
|
e9c22b |
goto cleanup;
|
|
|
e9c22b |
--
|
|
|
e9c22b |
2.26.2
|
|
|
e9c22b |
|