Blame SOURCES/0041-curl-7.61.1-CVE-2022-32206.patch

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