|
| 1 | +From 79d560d64d50497717847bb2c12ede1f4a8ea7e9 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Sarah Larsen < [email protected]> |
| 3 | +Date: Wed, 25 Jun 2025 15:11:03 +0000 |
| 4 | +Subject: [PATCH] Fix off-by-one heap overflow in auth. |
| 5 | + |
| 6 | +Reported by Han Lee (Apple Information Security) |
| 7 | +CVE-2025-54349 |
| 8 | +--- |
| 9 | + src/iperf_auth.c | 18 +++++++++++++----- |
| 10 | + 1 file changed, 13 insertions(+), 5 deletions(-) |
| 11 | + |
| 12 | +diff --git a/src/iperf_auth.c b/src/iperf_auth.c |
| 13 | +index 72e85fc..86b4eba 100644 |
| 14 | +--- a/src/iperf_auth.c |
| 15 | ++++ b/src/iperf_auth.c |
| 16 | +@@ -288,6 +288,7 @@ int encrypt_rsa_message(const char *plaintext, EVP_PKEY *public_key, unsigned ch |
| 17 | + } |
| 18 | + |
| 19 | + int decrypt_rsa_message(const unsigned char *encryptedtext, const int encryptedtext_len, EVP_PKEY *private_key, unsigned char **plaintext, int use_pkcs1_padding) { |
| 20 | ++ int ret =0; |
| 21 | + #if OPENSSL_VERSION_MAJOR >= 3 |
| 22 | + EVP_PKEY_CTX *ctx; |
| 23 | + #else |
| 24 | +@@ -310,7 +311,8 @@ int decrypt_rsa_message(const unsigned char *encryptedtext, const int encryptedt |
| 25 | + keysize = RSA_size(rsa); |
| 26 | + #endif |
| 27 | + rsa_buffer = OPENSSL_malloc(keysize * 2); |
| 28 | +- *plaintext = (unsigned char*)OPENSSL_malloc(keysize); |
| 29 | ++ // Note: +1 for NULL |
| 30 | ++ *plaintext = (unsigned char*)OPENSSL_malloc(keysize + 1); |
| 31 | + |
| 32 | + BIO *bioBuff = BIO_new_mem_buf((void*)encryptedtext, encryptedtext_len); |
| 33 | + rsa_buffer_len = BIO_read(bioBuff, rsa_buffer, keysize * 2); |
| 34 | +@@ -320,13 +322,15 @@ int decrypt_rsa_message(const unsigned char *encryptedtext, const int encryptedt |
| 35 | + padding = RSA_PKCS1_PADDING; |
| 36 | + } |
| 37 | + #if OPENSSL_VERSION_MAJOR >= 3 |
| 38 | ++ |
| 39 | + plaintext_len = keysize; |
| 40 | + EVP_PKEY_decrypt_init(ctx); |
| 41 | +- int ret = EVP_PKEY_CTX_set_rsa_padding(ctx, padding); |
| 42 | ++ |
| 43 | ++ ret = EVP_PKEY_CTX_set_rsa_padding(ctx, padding); |
| 44 | + if (ret < 0){ |
| 45 | + goto errreturn; |
| 46 | + } |
| 47 | +- EVP_PKEY_decrypt(ctx, *plaintext, &plaintext_len, rsa_buffer, rsa_buffer_len); |
| 48 | ++ ret = EVP_PKEY_decrypt(ctx, *plaintext, &plaintext_len, rsa_buffer, rsa_buffer_len); |
| 49 | + EVP_PKEY_CTX_free(ctx); |
| 50 | + #else |
| 51 | + plaintext_len = RSA_private_decrypt(rsa_buffer_len, rsa_buffer, *plaintext, rsa, padding); |
| 52 | +@@ -337,7 +341,7 @@ int decrypt_rsa_message(const unsigned char *encryptedtext, const int encryptedt |
| 53 | + BIO_free(bioBuff); |
| 54 | + |
| 55 | + /* Treat a decryption error as an empty string. */ |
| 56 | +- if (plaintext_len < 0) { |
| 57 | ++ if (plaintext_len <= 0) { |
| 58 | + plaintext_len = 0; |
| 59 | + } |
| 60 | + |
| 61 | +@@ -386,24 +390,28 @@ int decode_auth_setting(int enable_debug, const char *authtoken, EVP_PKEY *priva |
| 62 | + int plaintext_len; |
| 63 | + plaintext_len = decrypt_rsa_message(encrypted_b64, encrypted_len_b64, private_key, &plaintext, use_pkcs1_padding); |
| 64 | + free(encrypted_b64); |
| 65 | +- if (plaintext_len < 0) { |
| 66 | ++ if (plaintext_len <= 0) { |
| 67 | + return -1; |
| 68 | + } |
| 69 | ++ |
| 70 | + plaintext[plaintext_len] = '\0'; |
| 71 | + |
| 72 | + char *s_username, *s_password; |
| 73 | + s_username = (char *) calloc(plaintext_len, sizeof(char)); |
| 74 | + if (s_username == NULL) { |
| 75 | ++ OPENSSL_free(plaintext); |
| 76 | + return -1; |
| 77 | + } |
| 78 | + s_password = (char *) calloc(plaintext_len, sizeof(char)); |
| 79 | + if (s_password == NULL) { |
| 80 | ++ OPENSSL_free(plaintext); |
| 81 | + free(s_username); |
| 82 | + return -1; |
| 83 | + } |
| 84 | + |
| 85 | + int rc = sscanf((char *) plaintext, auth_text_format, s_username, s_password, &utc_seconds); |
| 86 | + if (rc != 3) { |
| 87 | ++ OPENSSL_free(plaintext); |
| 88 | + free(s_password); |
| 89 | + free(s_username); |
| 90 | + return -1; |
| 91 | +-- |
| 92 | +2.45.4 |
| 93 | + |
0 commit comments