1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
From 1808f0e65e2f672046470db2c1e682999360f92c Mon Sep 17 00:00:00 2001
From: Jakub Jelen <jjelen@redhat.com>
Date: Wed, 14 May 2025 14:07:58 +0200
Subject: [PATCH 8/8] CVE-2025-5372 libgcrypto: Simplify error checking and
handling of return codes in ssh_kdf()
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry-picked from commit a9d8a3d44829cf9182b)
---
src/libcrypto.c | 62 ++++++++++++++++++++++---------------------------
1 file changed, 28 insertions(+), 34 deletions(-)
diff --git a/src/libcrypto.c b/src/libcrypto.c
index 911b3630..69a850de 100644
--- a/src/libcrypto.c
+++ b/src/libcrypto.c
@@ -163,7 +163,7 @@ int ssh_kdf(struct ssh_crypto_struct *crypto,
uint8_t key_type, unsigned char *output,
size_t requested_len)
{
- int rc = -1;
+ int ret = SSH_ERROR, rv;
#if OPENSSL_VERSION_NUMBER < 0x30000000L
EVP_KDF_CTX *ctx = EVP_KDF_CTX_new_id(EVP_KDF_SSHKDF);
#else
@@ -185,81 +185,75 @@ int ssh_kdf(struct ssh_crypto_struct *crypto,
}
#if OPENSSL_VERSION_NUMBER < 0x30000000L
- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_MD,
+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_MD,
sshkdf_digest_to_md(crypto->digest_type));
- if (rc != 1) {
+ if (rv != 1) {
goto out;
}
- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_KEY, key, key_len);
- if (rc != 1) {
+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_KEY, key, key_len);
+ if (rv != 1) {
goto out;
}
- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_XCGHASH,
+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_XCGHASH,
crypto->secret_hash, crypto->digest_len);
- if (rc != 1) {
+ if (rv != 1) {
goto out;
}
- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_TYPE, key_type);
- if (rc != 1) {
+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_TYPE, key_type);
+ if (rv != 1) {
goto out;
}
- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_SESSION_ID,
+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_SESSION_ID,
crypto->session_id, crypto->session_id_len);
- if (rc != 1) {
+ if (rv != 1) {
goto out;
}
- rc = EVP_KDF_derive(ctx, output, requested_len);
- if (rc != 1) {
+ rv = EVP_KDF_derive(ctx, output, requested_len);
+ if (rv != 1) {
goto out;
}
#else
- rc = OSSL_PARAM_BLD_push_utf8_string(param_bld, OSSL_KDF_PARAM_DIGEST,
+ rv = OSSL_PARAM_BLD_push_utf8_string(param_bld, OSSL_KDF_PARAM_DIGEST,
md, strlen(md));
- if (rc != 1) {
- rc = -1;
+ if (rv != 1) {
goto out;
}
- rc = OSSL_PARAM_BLD_push_octet_string(param_bld, OSSL_KDF_PARAM_KEY,
+ rv = OSSL_PARAM_BLD_push_octet_string(param_bld, OSSL_KDF_PARAM_KEY,
key, key_len);
- if (rc != 1) {
- rc = -1;
+ if (rv != 1) {
goto out;
}
- rc = OSSL_PARAM_BLD_push_octet_string(param_bld,
+ rv = OSSL_PARAM_BLD_push_octet_string(param_bld,
OSSL_KDF_PARAM_SSHKDF_XCGHASH,
crypto->secret_hash,
crypto->digest_len);
- if (rc != 1) {
- rc = -1;
+ if (rv != 1) {
goto out;
}
- rc = OSSL_PARAM_BLD_push_octet_string(param_bld,
+ rv = OSSL_PARAM_BLD_push_octet_string(param_bld,
OSSL_KDF_PARAM_SSHKDF_SESSION_ID,
crypto->session_id,
crypto->session_id_len);
- if (rc != 1) {
- rc = -1;
+ if (rv != 1) {
goto out;
}
- rc = OSSL_PARAM_BLD_push_utf8_string(param_bld, OSSL_KDF_PARAM_SSHKDF_TYPE,
+ rv = OSSL_PARAM_BLD_push_utf8_string(param_bld, OSSL_KDF_PARAM_SSHKDF_TYPE,
(const char*)&key_type, 1);
- if (rc != 1) {
- rc = -1;
+ if (rv != 1) {
goto out;
}
params = OSSL_PARAM_BLD_to_param(param_bld);
if (params == NULL) {
- rc = -1;
goto out;
}
- rc = EVP_KDF_derive(ctx, output, requested_len, params);
- if (rc != 1) {
- rc = -1;
+ rv = EVP_KDF_derive(ctx, output, requested_len, params);
+ if (rv != 1) {
goto out;
}
#endif /* OPENSSL_VERSION_NUMBER */
+ ret = SSH_OK;
out:
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
@@ -267,8 +261,8 @@ out:
OSSL_PARAM_free(params);
#endif
EVP_KDF_CTX_free(ctx);
- if (rc < 0) {
- return rc;
+ if (ret < 0) {
+ return ret;
}
return 0;
}
--
2.50.0
|