Skip to content

Commit 1e446f1

Browse files
[AutoPR- Security] Patch libssh for CVE-2025-8277 [LOW] (microsoft#14656)
Co-authored-by: Archana Shettigar <[email protected]>
1 parent 8c41f3a commit 1e446f1

File tree

2 files changed

+172
-1
lines changed

2 files changed

+172
-1
lines changed

SPECS/libssh/CVE-2025-8277.patch

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
From b1207905f9194d5bfa17393e605987f158e9448b Mon Sep 17 00:00:00 2001
2+
From: AllSpark <[email protected]>
3+
Date: Thu, 11 Sep 2025 16:00:02 +0000
4+
Subject: [PATCH] CVE-2025-8277: Avoid leaking ECDH keys and free previous
5+
DH/ECDH contexts; adjust packet filter for DH-GEX guess; free previously
6+
allocated pubkeys
7+
8+
Signed-off-by: Azure Linux Security Servicing Account <[email protected]>
9+
Upstream-reference: AI Backport of https://git.libssh.org/projects/libssh.git/patch/?id=1c763e29d138db87665e98983f468d2dd0f286c1 https://git.libssh.org/projects/libssh.git/patch/?id=8e4d67aa9eda455bfad9ac610e54b7a548d0aa08 https://git.libssh.org/projects/libssh.git/patch/?id=266174a6d36687b65cf90174f06af90b8b27c65f https://git.libssh.org/projects/libssh.git/patch/?id=87db2659ec608a977a63eea529f17b9168388d73
10+
---
11+
src/dh_crypto.c | 5 +++++
12+
src/dh_key.c | 5 +++++
13+
src/ecdh_crypto.c | 11 +++++++++++
14+
src/ecdh_gcrypt.c | 8 ++++++++
15+
src/ecdh_mbedcrypto.c | 7 +++++++
16+
src/packet.c | 2 ++
17+
src/wrapper.c | 10 +++++++++-
18+
7 files changed, 47 insertions(+), 1 deletion(-)
19+
20+
diff --git a/src/dh_crypto.c b/src/dh_crypto.c
21+
index 9ff7ad3..325c568 100644
22+
--- a/src/dh_crypto.c
23+
+++ b/src/dh_crypto.c
24+
@@ -407,6 +407,11 @@ int ssh_dh_init_common(struct ssh_crypto_struct *crypto)
25+
struct dh_ctx *ctx = NULL;
26+
int rc;
27+
28+
+ /* Cleanup any previously allocated dh_ctx */
29+
+ if (crypto->dh_ctx != NULL) {
30+
+ ssh_dh_cleanup(crypto);
31+
+ }
32+
+
33+
ctx = calloc(1, sizeof(*ctx));
34+
if (ctx == NULL) {
35+
return SSH_ERROR;
36+
diff --git a/src/dh_key.c b/src/dh_key.c
37+
index 20d24a3..d9743ce 100644
38+
--- a/src/dh_key.c
39+
+++ b/src/dh_key.c
40+
@@ -237,6 +237,11 @@ int ssh_dh_init_common(struct ssh_crypto_struct *crypto)
41+
struct dh_ctx *ctx = NULL;
42+
int rc;
43+
44+
+ /* Cleanup any previously allocated dh_ctx */
45+
+ if (crypto->dh_ctx != NULL) {
46+
+ ssh_dh_cleanup(crypto);
47+
+ }
48+
+
49+
ctx = calloc(1, sizeof(*ctx));
50+
if (ctx == NULL) {
51+
return SSH_ERROR;
52+
diff --git a/src/ecdh_crypto.c b/src/ecdh_crypto.c
53+
index 069b137..8ad9bbf 100644
54+
--- a/src/ecdh_crypto.c
55+
+++ b/src/ecdh_crypto.c
56+
@@ -219,7 +219,19 @@ int ssh_client_ecdh_init(ssh_session session){
57+
return SSH_ERROR;
58+
}
59+
60+
+ /* Free any previously allocated privkey */
61+
+ if (session->next_crypto->ecdh_privkey != NULL) {
62+
+ /* Replacing "#if OPENSSL_VERSION_NUMBER < 0x30000000L" as follows since we do not use OPENSSL_VERSION_NUMBER defines" */
63+
+#if 1
64+
+ EC_KEY_free(session->next_crypto->ecdh_privkey);
65+
+#else
66+
+ EVP_PKEY_free(session->next_crypto->ecdh_privkey);
67+
+#endif
68+
+ session->next_crypto->ecdh_privkey = NULL;
69+
+ }
70+
+
71+
session->next_crypto->ecdh_privkey = key;
72+
+ ssh_string_free(session->next_crypto->ecdh_client_pubkey);
73+
session->next_crypto->ecdh_client_pubkey = client_pubkey;
74+
75+
/* register the packet callbacks */
76+
diff --git a/src/ecdh_gcrypt.c b/src/ecdh_gcrypt.c
77+
index 3d9d426..918b0f5 100644
78+
--- a/src/ecdh_gcrypt.c
79+
+++ b/src/ecdh_gcrypt.c
80+
@@ -101,8 +101,16 @@ int ssh_client_ecdh_init(ssh_session session)
81+
goto out;
82+
}
83+
84+
+ /* Free any previously allocated privkey */
85+
+ if (session->next_crypto->ecdh_privkey != NULL) {
86+
+ gcry_sexp_release(session->next_crypto->ecdh_privkey);
87+
+ session->next_crypto->ecdh_privkey = NULL;
88+
+ }
89+
+
90+
session->next_crypto->ecdh_privkey = key;
91+
key = NULL;
92+
+
93+
+ SSH_STRING_FREE(session->next_crypto->ecdh_client_pubkey);
94+
session->next_crypto->ecdh_client_pubkey = client_pubkey;
95+
client_pubkey = NULL;
96+
97+
diff --git a/src/ecdh_mbedcrypto.c b/src/ecdh_mbedcrypto.c
98+
index dda7392..351aa65 100644
99+
--- a/src/ecdh_mbedcrypto.c
100+
+++ b/src/ecdh_mbedcrypto.c
101+
@@ -70,6 +70,12 @@ int ssh_client_ecdh_init(ssh_session session)
102+
return SSH_ERROR;
103+
}
104+
105+
+ /* Free any previously allocated privkey */
106+
+ if (session->next_crypto->ecdh_privkey != NULL) {
107+
+ mbedtls_ecp_keypair_free(session->next_crypto->ecdh_privkey);
108+
+ SAFE_FREE(session->next_crypto->ecdh_privkey);
109+
+ }
110+
+
111+
session->next_crypto->ecdh_privkey = malloc(sizeof(mbedtls_ecp_keypair));
112+
if (session->next_crypto->ecdh_privkey == NULL) {
113+
return SSH_ERROR;
114+
@@ -110,6 +116,7 @@ int ssh_client_ecdh_init(ssh_session session)
115+
goto out;
116+
}
117+
118+
+ SSH_STRING_FREE(session->next_crypto->ecdh_client_pubkey);
119+
session->next_crypto->ecdh_client_pubkey = client_pubkey;
120+
client_pubkey = NULL;
121+
122+
diff --git a/src/packet.c b/src/packet.c
123+
index ea73f9a..dfb8b01 100644
124+
--- a/src/packet.c
125+
+++ b/src/packet.c
126+
@@ -294,6 +294,7 @@ static enum ssh_packet_filter_result_e ssh_packet_incoming_filter(ssh_session se
127+
* or session_state == SSH_SESSION_STATE_INITIAL_KEX
128+
* - dh_handshake_state == DH_STATE_INIT
129+
* or dh_handshake_state == DH_STATE_INIT_SENT (re-exchange)
130+
+ * or dh_handshake_state == DH_STATE_REQUEST_SENT (dh-gex)
131+
* or dh_handshake_state == DH_STATE_FINISHED (re-exchange)
132+
*
133+
* Transitions:
134+
@@ -313,6 +314,7 @@ static enum ssh_packet_filter_result_e ssh_packet_incoming_filter(ssh_session se
135+
136+
if ((session->dh_handshake_state != DH_STATE_INIT) &&
137+
(session->dh_handshake_state != DH_STATE_INIT_SENT) &&
138+
+ (session->dh_handshake_state != DH_STATE_REQUEST_SENT) &&
139+
(session->dh_handshake_state != DH_STATE_FINISHED))
140+
{
141+
rc = SSH_PACKET_DENIED;
142+
diff --git a/src/wrapper.c b/src/wrapper.c
143+
index d317dc4..1f8cf84 100644
144+
--- a/src/wrapper.c
145+
+++ b/src/wrapper.c
146+
@@ -190,9 +190,17 @@ void crypto_free(struct ssh_crypto_struct *crypto)
147+
#endif /* OPENSSL_VERSION_NUMBER */
148+
#elif defined HAVE_GCRYPT_ECC
149+
gcry_sexp_release(crypto->ecdh_privkey);
150+
-#endif
151+
+#elif defined HAVE_LIBMBEDCRYPTO
152+
+ mbedtls_ecp_keypair_free(crypto->ecdh_privkey);
153+
+ SAFE_FREE(crypto->ecdh_privkey);
154+
+#endif /* HAVE_LIBGCRYPT */
155+
crypto->ecdh_privkey = NULL;
156+
}
157+
+#endif
158+
+#ifdef HAVE_LIBCRYPTO
159+
+ EVP_PKEY_free(crypto->curve25519_privkey);
160+
+#elif defined(HAVE_GCRYPT_CURVE25519)
161+
+ gcry_sexp_release(crypto->curve25519_privkey);
162+
#endif
163+
SAFE_FREE(crypto->dh_server_signature);
164+
if (crypto->session_id != NULL) {
165+
--
166+
2.45.4
167+

SPECS/libssh/libssh.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Vendor: Microsoft Corporation
22
Distribution: Mariner
33
Name: libssh
44
Version: 0.10.6
5-
Release: 3%{?dist}
5+
Release: 4%{?dist}
66
Summary: A library implementing the SSH protocol
77
License: LGPLv2+
88
URL: http://www.libssh.org
@@ -17,6 +17,7 @@ Patch1: CVE-2025-5372.patch
1717
Patch2: CVE-2025-5351.patch
1818
Patch3: CVE-2025-5318.patch
1919
Patch4: CVE-2025-4878.patch
20+
Patch5: CVE-2025-8277.patch
2021

2122
BuildRequires: cmake
2223
BuildRequires: gcc-c++
@@ -150,6 +151,9 @@ popd
150151
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/libssh/libssh_server.config
151152

152153
%changelog
154+
* Thu Sep 11 2025 Azure Linux Security Servicing Account <[email protected]> - 0.10.6-4
155+
- Patch for CVE-2025-8277
156+
153157
* Fri Jul 25 2025 Jyoti Kanase <[email protected]> - 0.10.6-3
154158
- Patch for CVE-2025-4878
155159

0 commit comments

Comments
 (0)