Skip to content

Commit 6f47c6b

Browse files
[AUTO-CHERRYPICK] Fixes CVE-2022-32149 by backporting the fix as a patch file - branch main (#10507)
Co-authored-by: Jiri Appl <jiria@microsoft.com>
1 parent 99c054a commit 6f47c6b

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

SPECS/cf-cli/CVE-2022-32149.patch

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
From 434eadcdbc3b0256971992e8c70027278364c72c Mon Sep 17 00:00:00 2001
2+
From: Roland Shoemaker <bracewell@google.com>
3+
Date: Fri, 2 Sep 2022 09:35:37 -0700
4+
Subject: [PATCH] language: reject excessively large Accept-Language strings
5+
6+
The BCP 47 tag parser has quadratic time complexity due to inherent
7+
aspects of its design. Since the parser is, by design, exposed to
8+
untrusted user input, this can be leveraged to force a program to
9+
consume significant time parsing Accept-Language headers.
10+
11+
The parser cannot be easily rewritten to fix this behavior for
12+
various reasons. Instead the solution implemented in this CL is to
13+
limit the total complexity of tags passed into ParseAcceptLanguage
14+
by limiting the number of dashes in the string to 1000. This should
15+
be more than enough for the majority of real world use cases, where
16+
the number of tags being sent is likely to be in the single digits.
17+
18+
Thanks to the OSS-Fuzz project for discovering this issue and to Adam
19+
Korczynski (ADA Logics) for writing the fuzz case and for reporting the
20+
issue.
21+
22+
Fixes CVE-2022-32149
23+
Fixes golang/go#56152
24+
25+
Change-Id: I7bda1d84cee2b945039c203f26869d58ee9374ae
26+
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1565112
27+
Reviewed-by: Damien Neil <dneil@google.com>
28+
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
29+
Reviewed-on: https://go-review.googlesource.com/c/text/+/442235
30+
TryBot-Result: Gopher Robot <gobot@golang.org>
31+
Auto-Submit: Roland Shoemaker <roland@golang.org>
32+
Run-TryBot: Roland Shoemaker <roland@golang.org>
33+
34+
Modified to apply to vendored code by: Jiri Appl <jiria@microsoft.com>
35+
- Adjusted paths
36+
- Removed reference to parse_test.go
37+
---
38+
vendor/golang.org/x/text/language/parse.go | 5 +++++
39+
1 files changed, 18 insertions(+)
40+
41+
diff --git a/vendor/golang.org/x/text/language/parse.go b/vendor/golang.org/x/text/language/parse.go
42+
index 59b0410..b982d9e 100644
43+
--- a/vendor/golang.org/x/text/language/parse.go
44+
+++ b/vendor/golang.org/x/text/language/parse.go
45+
@@ -147,6 +147,7 @@ func update(b *language.Builder, part ...interface{}) (err error) {
46+
}
47+
48+
var errInvalidWeight = errors.New("ParseAcceptLanguage: invalid weight")
49+
+var errTagListTooLarge = errors.New("tag list exceeds max length")
50+
51+
// ParseAcceptLanguage parses the contents of an Accept-Language header as
52+
// defined in http://www.ietf.org/rfc/rfc2616.txt and returns a list of Tags and
53+
@@ -164,6 +165,10 @@ func ParseAcceptLanguage(s string) (tag []Tag, q []float32, err error) {
54+
}
55+
}()
56+
57+
+ if strings.Count(s, "-") > 1000 {
58+
+ return nil, nil, errTagListTooLarge
59+
+ }
60+
+
61+
var entry string
62+
for s != "" {
63+
if entry, s = split(s, ','); entry == "" {
64+
--
65+
2.34.1
66+

SPECS/cf-cli/cf-cli.spec

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Summary: The official command line client for Cloud Foundry.
22
Name: cf-cli
33
Version: 8.4.0
4-
Release: 20%{?dist}
4+
Release: 21%{?dist}
55
License: Apache-2.0
66
Vendor: Microsoft Corporation
77
Distribution: Mariner
@@ -30,6 +30,9 @@ Source1: cli-%{version}-vendor.tar.gz
3030
Patch0: CVE-2023-44487.patch
3131
Patch1: CVE-2021-44716.patch
3232
Patch2: CVE-2021-43565.patch
33+
# Produced by git clone https://github.com/golang/text && cd text &&
34+
# git checkout 434eadcdbc3b0256971992e8c70027278364c72c && git format-patch -1 HEAD
35+
Patch3: CVE-2022-32149.patch
3336

3437
BuildRequires: golang
3538
%global debug_package %{nil}
@@ -64,6 +67,9 @@ install -p -m 755 -t %{buildroot}%{_bindir} ./out/cf
6467
%{_bindir}/cf
6568

6669
%changelog
70+
* Tue Sep 17 2024 Jiri Appl <jiria@microsoft.com> - 8.4.0-21
71+
- Patch CVE-2022-32149 bringing upstream patch over the vendored golang.org/x/text module
72+
6773
* Mon Sep 09 2024 CBL-Mariner Servicing Account <cblmargh@microsoft.com> - 8.4.0-20
6874
- Bump release to rebuild with go 1.22.7
6975

0 commit comments

Comments
 (0)