Skip to content

Commit 5512944

Browse files
authored
Fix CVE-2024-6104 in Packer by patching vendor gomodule (#9991)
1 parent 06b9340 commit 5512944

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

SPECS/packer/CVE-2024-6104.patch

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
From 900f7e0532332e4efbce65a3b35ce28c1fd89369 Mon Sep 17 00:00:00 2001
2+
From: Balakumaran Kannan <kumaran.4353@gmail.com>
3+
Date: Thu, 1 Aug 2024 12:27:25 +0000
4+
Subject: [PATCH] Patch CVE-2024-6104
5+
6+
---
7+
.../hashicorp/go-retryablehttp/client.go | 28 ++++++++++++++-----
8+
1 file changed, 21 insertions(+), 7 deletions(-)
9+
10+
diff --git a/vendor/github.com/hashicorp/go-retryablehttp/client.go b/vendor/github.com/hashicorp/go-retryablehttp/client.go
11+
index adbdd92..11d146a 100644
12+
--- a/vendor/github.com/hashicorp/go-retryablehttp/client.go
13+
+++ b/vendor/github.com/hashicorp/go-retryablehttp/client.go
14+
@@ -546,9 +546,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
15+
if logger != nil {
16+
switch v := logger.(type) {
17+
case LeveledLogger:
18+
- v.Debug("performing request", "method", req.Method, "url", req.URL)
19+
+ v.Debug("performing request", "method", req.Method, "url", redactURL(req.URL))
20+
case Logger:
21+
- v.Printf("[DEBUG] %s %s", req.Method, req.URL)
22+
+ v.Printf("[DEBUG] %s %s", req.Method, redactURL(req.URL))
23+
}
24+
}
25+
26+
@@ -599,9 +599,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
27+
if doErr != nil {
28+
switch v := logger.(type) {
29+
case LeveledLogger:
30+
- v.Error("request failed", "error", doErr, "method", req.Method, "url", req.URL)
31+
+ v.Error("request failed", "error", doErr, "method", req.Method, "url", redactURL(req.URL))
32+
case Logger:
33+
- v.Printf("[ERR] %s %s request failed: %v", req.Method, req.URL, doErr)
34+
+ v.Printf("[ERR] %s %s request failed: %v", req.Method, redactURL(req.URL), doErr)
35+
}
36+
} else {
37+
// Call this here to maintain the behavior of logging all requests,
38+
@@ -636,7 +636,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
39+
}
40+
41+
wait := c.Backoff(c.RetryWaitMin, c.RetryWaitMax, i, resp)
42+
- desc := fmt.Sprintf("%s %s", req.Method, req.URL)
43+
+ desc := fmt.Sprintf("%s %s", req.Method, redactURL(req.URL))
44+
if code > 0 {
45+
desc = fmt.Sprintf("%s (status: %d)", desc, code)
46+
}
47+
@@ -687,11 +687,11 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
48+
// communicate why
49+
if err == nil {
50+
return nil, fmt.Errorf("%s %s giving up after %d attempt(s)",
51+
- req.Method, req.URL, attempt)
52+
+ req.Method, redactURL(req.URL), attempt)
53+
}
54+
55+
return nil, fmt.Errorf("%s %s giving up after %d attempt(s): %w",
56+
- req.Method, req.URL, attempt, err)
57+
+ req.Method, redactURL(req.URL), attempt, err)
58+
}
59+
60+
// Try to read the response body so we can reuse this connection.
61+
@@ -772,3 +772,17 @@ func (c *Client) StandardClient() *http.Client {
62+
Transport: &RoundTripper{Client: c},
63+
}
64+
}
65+
+
66+
+
67+
+// Taken from url.URL#Redacted() which was introduced in go 1.15.
68+
+func redactURL(u *url.URL) string {
69+
+ if u == nil {
70+
+ return ""
71+
+ }
72+
+
73+
+ ru := *u
74+
+ if _, has := ru.User.Password(); has {
75+
+ ru.User = url.UserPassword(ru.User.Username(), "xxxxx")
76+
+ }
77+
+ return ru.String()
78+
+}
79+
--
80+
2.33.8
81+

SPECS/packer/packer.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Summary: Tool for creating identical machine images for multiple platform
55
Name: packer
66
Epoch: 1
77
Version: 1.9.5
8-
Release: 1%{?dist}
8+
Release: 2%{?dist}
99
License: MPLv2.0
1010
Vendor: Microsoft Corporation
1111
Distribution: Mariner
@@ -35,6 +35,7 @@ Source1: %{name}-%{version}-vendor.tar.gz
3535
Patch0: CVE-2023-45288.patch
3636
Patch1: CVE-2022-3064.patch
3737
Patch2: CVE-2023-49569.patch
38+
Patch3: CVE-2024-6104.patch
3839
BuildRequires: golang
3940
BuildRequires: kernel-headers
4041
BuildRequires: glibc-devel
@@ -68,6 +69,9 @@ go test -mod=vendor
6869
%{_bindir}/packer
6970

7071
%changelog
72+
* Thu Aug 01 2024 Bala <balakumaran.kannan@microsoft.com> - 1:1.9.5-2
73+
- Patch for CVE-2024-6104
74+
7175
* Mon Jul 01 2024 Pawel Winogrodzki <pawelwi@microsoft.com> - 1:1.9.5-1
7276
- Revert to version 1.9.5.
7377
- Added patches for CVE-2022-3064 and CVE-2023-49569.

0 commit comments

Comments
 (0)