Skip to content

Commit 9f848fd

Browse files
[AUTO-CHERRYPICK] Fix CVE-2025-22869 for terraform [HIGH] - branch main (#12899)
Co-authored-by: Sudipta Pandit <sudpandit@microsoft.com>
1 parent 554f7b5 commit 9f848fd

2 files changed

Lines changed: 100 additions & 1 deletion

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
From 82e574ecb3fd33a4eb564742966f01704084692e Mon Sep 17 00:00:00 2001
2+
From: Sudipta Pandit <sudpandit@microsoft.com>
3+
Date: Tue, 11 Mar 2025 00:17:38 +0530
4+
Subject: [PATCH] Backport upstream patch for CVE-2025-22869.patch
5+
6+
---
7+
vendor/golang.org/x/crypto/ssh/handshake.go | 30 +++++++++++++++++----
8+
1 file changed, 25 insertions(+), 5 deletions(-)
9+
10+
diff --git a/vendor/golang.org/x/crypto/ssh/handshake.go b/vendor/golang.org/x/crypto/ssh/handshake.go
11+
index 653dc4d..a1e1536 100644
12+
--- a/vendor/golang.org/x/crypto/ssh/handshake.go
13+
+++ b/vendor/golang.org/x/crypto/ssh/handshake.go
14+
@@ -24,6 +24,11 @@ const debugHandshake = false
15+
// quickly.
16+
const chanSize = 16
17+
18+
+// maxPendingPackets sets the maximum number of packets to queue while waiting
19+
+// for KEX to complete. This limits the total pending data to maxPendingPackets
20+
+// * maxPacket bytes, which is ~16.8MB.
21+
+const maxPendingPackets = 64
22+
+
23+
// keyingTransport is a packet based transport that supports key
24+
// changes. It need not be thread-safe. It should pass through
25+
// msgNewKeys in both directions.
26+
@@ -59,6 +64,7 @@ type handshakeTransport struct {
27+
readError error
28+
29+
mu sync.Mutex
30+
+ writeCond *sync.Cond
31+
writeError error
32+
sentInitPacket []byte
33+
sentInitMsg *kexInitMsg
34+
@@ -112,6 +118,7 @@ func newHandshakeTransport(conn keyingTransport, config *Config, clientVersion,
35+
36+
config: config,
37+
}
38+
+ t.writeCond = sync.NewCond(&t.mu)
39+
t.resetReadThresholds()
40+
t.resetWriteThresholds()
41+
42+
@@ -234,6 +241,7 @@ func (t *handshakeTransport) recordWriteError(err error) {
43+
defer t.mu.Unlock()
44+
if t.writeError == nil && err != nil {
45+
t.writeError = err
46+
+ t.writeCond.Broadcast()
47+
}
48+
}
49+
50+
@@ -337,6 +345,8 @@ write:
51+
}
52+
}
53+
t.pendingPackets = t.pendingPackets[:0]
54+
+ // Unblock writePacket if waiting for KEX.
55+
+ t.writeCond.Broadcast()
56+
t.mu.Unlock()
57+
}
58+
59+
@@ -518,11 +528,20 @@ func (t *handshakeTransport) writePacket(p []byte) error {
60+
}
61+
62+
if t.sentInitMsg != nil {
63+
- // Copy the packet so the writer can reuse the buffer.
64+
- cp := make([]byte, len(p))
65+
- copy(cp, p)
66+
- t.pendingPackets = append(t.pendingPackets, cp)
67+
- return nil
68+
+ if len(t.pendingPackets) < maxPendingPackets {
69+
+ // Copy the packet so the writer can reuse the buffer.
70+
+ cp := make([]byte, len(p))
71+
+ copy(cp, p)
72+
+ t.pendingPackets = append(t.pendingPackets, cp)
73+
+ return nil
74+
+ }
75+
+ for t.sentInitMsg != nil {
76+
+ // Block and wait for KEX to complete or an error.
77+
+ t.writeCond.Wait()
78+
+ if t.writeError != nil {
79+
+ return t.writeError
80+
+ }
81+
+ }
82+
}
83+
84+
if t.writeBytesLeft > 0 {
85+
@@ -539,6 +558,7 @@ func (t *handshakeTransport) writePacket(p []byte) error {
86+
87+
if err := t.pushPacket(p); err != nil {
88+
t.writeError = err
89+
+ t.writeCond.Broadcast()
90+
}
91+
92+
return nil
93+
--
94+
2.34.1
95+

SPECS/terraform/terraform.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Summary: Infrastructure as code deployment management tool
22
Name: terraform
33
Version: 1.3.2
4-
Release: 22%{?dist}
4+
Release: 23%{?dist}
55
License: MPLv2.0
66
Vendor: Microsoft Corporation
77
Distribution: Mariner
@@ -36,6 +36,7 @@ Patch5: CVE-2023-4782.patch
3636
Patch6: CVE-2024-24786.patch
3737
Patch7: CVE-2024-45338.patch
3838
Patch8: CVE-2023-0475.patch
39+
Patch9: CVE-2025-22869.patch
3940

4041
%global debug_package %{nil}
4142
%define our_gopath %{_topdir}/.gopath
@@ -66,6 +67,9 @@ install -p -m 755 -t %{buildroot}%{_bindir} ./terraform
6667
%{_bindir}/terraform
6768

6869
%changelog
70+
* Mon Mar 10 2025 Sudipta Pandit <sudpandit@microsoft.com> - 1.3.2-23
71+
- Add patch for CVE-2025-22869
72+
6973
* Tue Jan 21 2025 Sandeep Karambelkar <skarambelkar@microsoft.com> - 1.3.2-22
7074
- Add Patch for CVE-2023-0475
7175

0 commit comments

Comments
 (0)