Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit e8dfbb8

Browse files
Norbert Pocscryptomilk
authored andcommitted
CVE-2023-2283:pki_crypto: Fix possible authentication bypass
The return value is changed by the call to pki_key_check_hash_compatible causing the possibility of returning SSH_OK if memory allocation error happens later in the function. The assignment of SSH_ERROR if the verification fails is no longer needed, because the value of the variable is already SSH_ERROR. Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
1 parent dc1254d commit e8dfbb8

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

src/pki_crypto.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,8 +3175,12 @@ int pki_verify_data_signature(ssh_signature signature,
31753175
unsigned char *raw_sig_data = NULL;
31763176
unsigned int raw_sig_len;
31773177

3178+
/* Function return code
3179+
* Do not change this variable throughout the function until the signature
3180+
* is successfully verified!
3181+
*/
31783182
int rc = SSH_ERROR;
3179-
int evp_rc;
3183+
int ok;
31803184

31813185
if (pubkey == NULL || ssh_key_is_private(pubkey) || input == NULL ||
31823186
signature == NULL || (signature->raw_sig == NULL
@@ -3191,8 +3195,8 @@ int pki_verify_data_signature(ssh_signature signature,
31913195
}
31923196

31933197
/* Check if public key and hash type are compatible */
3194-
rc = pki_key_check_hash_compatible(pubkey, signature->hash_type);
3195-
if (rc != SSH_OK) {
3198+
ok = pki_key_check_hash_compatible(pubkey, signature->hash_type);
3199+
if (ok != SSH_OK) {
31963200
return SSH_ERROR;
31973201
}
31983202

@@ -3237,37 +3241,37 @@ int pki_verify_data_signature(ssh_signature signature,
32373241
}
32383242

32393243
/* Verify the signature */
3240-
evp_rc = EVP_DigestVerifyInit(ctx, NULL, md, NULL, pkey);
3241-
if (evp_rc != 1){
3244+
ok = EVP_DigestVerifyInit(ctx, NULL, md, NULL, pkey);
3245+
if (ok != 1){
32423246
SSH_LOG(SSH_LOG_TRACE,
32433247
"EVP_DigestVerifyInit() failed: %s",
32443248
ERR_error_string(ERR_get_error(), NULL));
32453249
goto out;
32463250
}
32473251

32483252
#ifdef HAVE_OPENSSL_EVP_DIGESTVERIFY
3249-
evp_rc = EVP_DigestVerify(ctx, raw_sig_data, raw_sig_len, input, input_len);
3253+
ok = EVP_DigestVerify(ctx, raw_sig_data, raw_sig_len, input, input_len);
32503254
#else
3251-
evp_rc = EVP_DigestVerifyUpdate(ctx, input, input_len);
3252-
if (evp_rc != 1) {
3255+
ok = EVP_DigestVerifyUpdate(ctx, input, input_len);
3256+
if (ok != 1) {
32533257
SSH_LOG(SSH_LOG_TRACE,
32543258
"EVP_DigestVerifyUpdate() failed: %s",
32553259
ERR_error_string(ERR_get_error(), NULL));
32563260
goto out;
32573261
}
32583262

3259-
evp_rc = EVP_DigestVerifyFinal(ctx, raw_sig_data, raw_sig_len);
3263+
ok = EVP_DigestVerifyFinal(ctx, raw_sig_data, raw_sig_len);
32603264
#endif
3261-
if (evp_rc == 1) {
3262-
SSH_LOG(SSH_LOG_TRACE, "Signature valid");
3263-
rc = SSH_OK;
3264-
} else {
3265+
if (ok != 1) {
32653266
SSH_LOG(SSH_LOG_TRACE,
32663267
"Signature invalid: %s",
32673268
ERR_error_string(ERR_get_error(), NULL));
3268-
rc = SSH_ERROR;
3269+
goto out;
32693270
}
32703271

3272+
SSH_LOG(SSH_LOG_TRACE, "Signature valid");
3273+
rc = SSH_OK;
3274+
32713275
out:
32723276
if (ctx != NULL) {
32733277
EVP_MD_CTX_free(ctx);

0 commit comments

Comments
 (0)