Blame SOURCES/0017-curl-7.76.1-CVE-2022-32206.patch

db89db
From 24dedf9b260eebb7feae6fc273208b551fe54a79 Mon Sep 17 00:00:00 2001
db89db
From: Daniel Stenberg <daniel@haxx.se>
db89db
Date: Mon, 16 May 2022 16:28:13 +0200
db89db
Subject: [PATCH 1/2] content_encoding: return error on too many compression
db89db
 steps
db89db
db89db
The max allowed steps is arbitrarily set to 5.
db89db
db89db
Bug: https://curl.se/docs/CVE-2022-32206.html
db89db
CVE-2022-32206
db89db
Reported-by: Harry Sintonen
db89db
Closes #9049
db89db
db89db
Upstream-commit: 3a09fbb7f264c67c438d01a30669ce325aa508e2
db89db
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
db89db
---
db89db
 lib/content_encoding.c | 9 +++++++++
db89db
 1 file changed, 9 insertions(+)
db89db
db89db
diff --git a/lib/content_encoding.c b/lib/content_encoding.c
db89db
index c03637a..6f994b3 100644
db89db
--- a/lib/content_encoding.c
db89db
+++ b/lib/content_encoding.c
db89db
@@ -1024,12 +1024,16 @@ static const struct content_encoding *find_encoding(const char *name,
db89db
   return NULL;
db89db
 }
db89db
 
db89db
+/* allow no more than 5 "chained" compression steps */
db89db
+#define MAX_ENCODE_STACK 5
db89db
+
db89db
 /* Set-up the unencoding stack from the Content-Encoding header value.
db89db
  * See RFC 7231 section 3.1.2.2. */
db89db
 CURLcode Curl_build_unencoding_stack(struct Curl_easy *data,
db89db
                                      const char *enclist, int maybechunked)
db89db
 {
db89db
   struct SingleRequest *k = &data->req;
db89db
+  int counter = 0;
db89db
 
db89db
   do {
db89db
     const char *name;
db89db
@@ -1064,6 +1068,11 @@ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data,
db89db
       if(!encoding)
db89db
         encoding = &error_encoding;  /* Defer error at stack use. */
db89db
 
db89db
+      if(++counter >= MAX_ENCODE_STACK) {
db89db
+        failf(data, "Reject response due to %u content encodings",
db89db
+              counter);
db89db
+        return CURLE_BAD_CONTENT_ENCODING;
db89db
+      }
db89db
       /* Stack the unencoding stage. */
db89db
       writer = new_unencoding_writer(data, encoding, k->writer_stack);
db89db
       if(!writer)
db89db
-- 
db89db
2.35.3
db89db
db89db
db89db
From b3cd74f01871281f0989860e04c546d896f0e72f Mon Sep 17 00:00:00 2001
db89db
From: Daniel Stenberg <daniel@haxx.se>
db89db
Date: Mon, 16 May 2022 16:29:07 +0200
db89db
Subject: [PATCH 2/2] test387: verify rejection of compression chain attack
db89db
db89db
Upstream-commit: 7230b19a2e17a164f61f82e4e409a9777ea2421a
db89db
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
db89db
---
db89db
 tests/data/Makefile.inc |  1 +
db89db
 tests/data/test387      | 53 +++++++++++++++++++++++++++++++++++++++++
db89db
 2 files changed, 54 insertions(+)
db89db
 create mode 100644 tests/data/test387
db89db
db89db
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
db89db
index 98d5516..9b5f4fb 100644
db89db
--- a/tests/data/Makefile.inc
db89db
+++ b/tests/data/Makefile.inc
db89db
@@ -62,6 +62,7 @@ test343 test344 test345 test346 test347 test348 test349 test350 test351 \
db89db
 test352 test353 test354 test355 test356 test357 test358 test359 test360 \
db89db
 test361 test362 \
db89db
 \
db89db
+test387 \
db89db
 test393 test394 test395 test396 test397 \
db89db
 \
db89db
 test400 test401 test402 test403 test404 test405 test406 test407 test408 \
db89db
diff --git a/tests/data/test387 b/tests/data/test387
db89db
new file mode 100644
db89db
index 0000000..015ec25
db89db
--- /dev/null
db89db
+++ b/tests/data/test387
db89db
@@ -0,0 +1,53 @@
db89db
+<testcase>
db89db
+<info>
db89db
+<keywords>
db89db
+HTTP
db89db
+gzip
db89db
+</keywords>
db89db
+</info>
db89db
+
db89db
+#
db89db
+# Server-side
db89db
+<reply>
db89db
+<data nocheck="yes">
db89db
+HTTP/1.1 200 OK
db89db
+Transfer-Encoding: gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip,gzip
db89db
+
db89db
+-foo-
db89db
+</data>
db89db
+</reply>
db89db
+
db89db
+#
db89db
+# Client-side
db89db
+<client>
db89db
+<server>
db89db
+http
db89db
+</server>
db89db
+ <name>
db89db
+Response with overly long compression chain
db89db
+ </name>
db89db
+ <command>
db89db
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER -sS
db89db
+</command>
db89db
+</client>
db89db
+
db89db
+#
db89db
+# Verify data after the test has been "shot"
db89db
+<verify>
db89db
+<protocol>
db89db
+GET /%TESTNUMBER HTTP/1.1
db89db
+Host: %HOSTIP:%HTTPPORT
db89db
+User-Agent: curl/%VERSION
db89db
+Accept: */*
db89db
+
db89db
+</protocol>
db89db
+
db89db
+# CURLE_BAD_CONTENT_ENCODING is 61
db89db
+<errorcode>
db89db
+61
db89db
+</errorcode>
db89db
+<stderr mode="text">
db89db
+curl: (61) Reject response due to 5 content encodings
db89db
+</stderr>
db89db
+</verify>
db89db
+</testcase>
db89db
-- 
db89db
2.35.3
db89db