Blame SOURCES/0035-curl-7.61.1-CVE-2021-22947.patch

327345
From a1ec463c8207bde97b3575d12e396e999a55a8d0 Mon Sep 17 00:00:00 2001
327345
From: Patrick Monnerat <patrick@monnerat.net>
327345
Date: Tue, 7 Sep 2021 13:26:42 +0200
327345
Subject: [PATCH] ftp,imap,pop3,smtp: reject STARTTLS server response
327345
 pipelining
327345
327345
If a server pipelines future responses within the STARTTLS response, the
327345
former are preserved in the pingpong cache across TLS negotiation and
327345
used as responses to the encrypted commands.
327345
327345
This fix detects pipelined STARTTLS responses and rejects them with an
327345
error.
327345
327345
CVE-2021-22947
327345
327345
Bug: https://curl.se/docs/CVE-2021-22947.html
327345
327345
Upstream-commit: 8ef147c43646e91fdaad5d0e7b60351f842e5c68
327345
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
327345
---
327345
 lib/ftp.c               |  3 +++
327345
 lib/imap.c              |  4 +++
327345
 lib/pop3.c              |  4 +++
327345
 lib/smtp.c              |  4 +++
327345
 tests/data/Makefile.inc |  2 +-
327345
 tests/data/test980      | 52 ++++++++++++++++++++++++++++++++++++
327345
 tests/data/test981      | 59 +++++++++++++++++++++++++++++++++++++++++
327345
 tests/data/test982      | 57 +++++++++++++++++++++++++++++++++++++++
327345
 tests/data/test983      | 52 ++++++++++++++++++++++++++++++++++++
327345
 9 files changed, 236 insertions(+), 1 deletion(-)
327345
 create mode 100644 tests/data/test980
327345
 create mode 100644 tests/data/test981
327345
 create mode 100644 tests/data/test982
327345
 create mode 100644 tests/data/test983
327345
327345
diff --git a/lib/ftp.c b/lib/ftp.c
327345
index 71f998e..e920138 100644
327345
--- a/lib/ftp.c
327345
+++ b/lib/ftp.c
327345
@@ -2688,6 +2688,9 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
327345
     case FTP_AUTH:
327345
       /* we have gotten the response to a previous AUTH command */
327345
 
327345
+      if(pp->cache_size)
327345
+        return CURLE_WEIRD_SERVER_REPLY; /* Forbid pipelining in response. */
327345
+
327345
       /* RFC2228 (page 5) says:
327345
        *
327345
        * If the server is willing to accept the named security mechanism,
327345
diff --git a/lib/imap.c b/lib/imap.c
327345
index feb7445..09bc5d6 100644
327345
--- a/lib/imap.c
327345
+++ b/lib/imap.c
327345
@@ -939,6 +939,10 @@ static CURLcode imap_state_starttls_resp(struct connectdata *conn,
327345
 
327345
   (void)instate; /* no use for this yet */
327345
 
327345
+  /* Pipelining in response is forbidden. */
327345
+  if(conn->proto.imapc.pp.cache_size)
327345
+    return CURLE_WEIRD_SERVER_REPLY;
327345
+
327345
   if(imapcode != IMAP_RESP_OK) {
327345
     if(data->set.use_ssl != CURLUSESSL_TRY) {
327345
       failf(data, "STARTTLS denied");
327345
diff --git a/lib/pop3.c b/lib/pop3.c
327345
index 7698d1c..dccfced 100644
327345
--- a/lib/pop3.c
327345
+++ b/lib/pop3.c
327345
@@ -750,6 +750,10 @@ static CURLcode pop3_state_starttls_resp(struct connectdata *conn,
327345
 
327345
   (void)instate; /* no use for this yet */
327345
 
327345
+  /* Pipelining in response is forbidden. */
327345
+  if(conn->proto.pop3c.pp.cache_size)
327345
+    return CURLE_WEIRD_SERVER_REPLY;
327345
+
327345
   if(pop3code != '+') {
327345
     if(data->set.use_ssl != CURLUSESSL_TRY) {
327345
       failf(data, "STARTTLS denied");
327345
diff --git a/lib/smtp.c b/lib/smtp.c
327345
index 1defb25..1f89777 100644
327345
--- a/lib/smtp.c
327345
+++ b/lib/smtp.c
327345
@@ -685,6 +685,10 @@ static CURLcode smtp_state_starttls_resp(struct connectdata *conn,
327345
 
327345
   (void)instate; /* no use for this yet */
327345
 
327345
+  /* Pipelining in response is forbidden. */
327345
+  if(conn->proto.smtpc.pp.cache_size)
327345
+    return CURLE_WEIRD_SERVER_REPLY;
327345
+
327345
   if(smtpcode != 220) {
327345
     if(data->set.use_ssl != CURLUSESSL_TRY) {
327345
       failf(data, "STARTTLS denied, code %d", smtpcode);
327345
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
327345
index 163ce59..42b0569 100644
327345
--- a/tests/data/Makefile.inc
327345
+++ b/tests/data/Makefile.inc
327345
@@ -108,7 +108,7 @@ test927 test928 test929 test930 test931 test932 test933 test934 test935 \
327345
 test936 test937 test938 test939 test940 test941 test942 test943 test944 \
327345
 test945 test946 test947 test948 test949 test950 test951 test952 \
327345
 \
327345
-test984 test985 test986 \
327345
+test980 test981 test982 test983 test984 test985 test986 \
327345
 \
327345
 test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 \
327345
 test1008 test1009 test1010 test1011 test1012 test1013 test1014 test1015 \
327345
diff --git a/tests/data/test980 b/tests/data/test980
327345
new file mode 100644
327345
index 0000000..97567f8
327345
--- /dev/null
327345
+++ b/tests/data/test980
327345
@@ -0,0 +1,52 @@
327345
+<testcase>
327345
+<info>
327345
+<keywords>
327345
+SMTP
327345
+STARTTLS
327345
+</keywords>
327345
+</info>
327345
+
327345
+#
327345
+# Server-side
327345
+<reply>
327345
+<servercmd>
327345
+CAPA STARTTLS
327345
+AUTH PLAIN
327345
+REPLY STARTTLS 454 currently unavailable\r\n235 Authenticated\r\n250 2.1.0 Sender ok\r\n250 2.1.5 Recipient ok\r\n354 Enter mail\r\n250 2.0.0 Accepted
327345
+REPLY AUTH 535 5.7.8 Authentication credentials invalid
327345
+</servercmd>
327345
+</reply>
327345
+
327345
+#
327345
+# Client-side
327345
+<client>
327345
+<features>
327345
+SSL
327345
+</features>
327345
+<server>
327345
+smtp
327345
+</server>
327345
+ <name>
327345
+SMTP STARTTLS pipelined server response
327345
+ </name>
327345
+<stdin>
327345
+mail body
327345
+</stdin>
327345
+ <command>
327345
+smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-from sender@example.com -u user:secret --ssl --sasl-ir -T -
327345
+</command>
327345
+</client>
327345
+
327345
+#
327345
+# Verify data after the test has been "shot"
327345
+<verify>
327345
+# 8 is CURLE_WEIRD_SERVER_REPLY
327345
+<errorcode>
327345
+8
327345
+</errorcode>
327345
+<protocol>
327345
+EHLO %TESTNUMBER
327345
+STARTTLS
327345
+</protocol>
327345
+</verify>
327345
+</testcase>
327345
diff --git a/tests/data/test981 b/tests/data/test981
327345
new file mode 100644
327345
index 0000000..2b98ce4
327345
--- /dev/null
327345
+++ b/tests/data/test981
327345
@@ -0,0 +1,59 @@
327345
+<testcase>
327345
+<info>
327345
+<keywords>
327345
+IMAP
327345
+STARTTLS
327345
+</keywords>
327345
+</info>
327345
+
327345
+#
327345
+# Server-side
327345
+<reply>
327345
+<servercmd>
327345
+CAPA STARTTLS
327345
+REPLY STARTTLS A002 BAD currently unavailable\r\nA003 OK Authenticated\r\nA004 OK Accepted
327345
+REPLY LOGIN A003 BAD Authentication credentials invalid
327345
+</servercmd>
327345
+</reply>
327345
+
327345
+#
327345
+# Client-side
327345
+<client>
327345
+<features>
327345
+SSL
327345
+</features>
327345
+<server>
327345
+imap
327345
+</server>
327345
+ <name>
327345
+IMAP STARTTLS pipelined server response
327345
+ </name>
327345
+ <command>
327345
+imap://%HOSTIP:%IMAPPORT/%TESTNUMBER -T log/upload%TESTNUMBER -u user:secret --ssl
327345
+</command>
327345
+<file name="log/upload%TESTNUMBER">
327345
+Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
327345
+From: Fred Foobar <foobar@example.COM>
327345
+Subject: afternoon meeting
327345
+To: joe@example.com
327345
+Message-Id: <B27397-0100000@example.COM>
327345
+MIME-Version: 1.0
327345
+Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
327345
+
327345
+Hello Joe, do you think we can meet at 3:30 tomorrow?
327345
+</file>
327345
+</client>
327345
+
327345
+#
327345
+# Verify data after the test has been "shot"
327345
+<verify>
327345
+# 8 is CURLE_WEIRD_SERVER_REPLY
327345
+<errorcode>
327345
+8
327345
+</errorcode>
327345
+<protocol>
327345
+A001 CAPABILITY
327345
+A002 STARTTLS
327345
+</protocol>
327345
+</verify>
327345
+</testcase>
327345
diff --git a/tests/data/test982 b/tests/data/test982
327345
new file mode 100644
327345
index 0000000..9e07cc0
327345
--- /dev/null
327345
+++ b/tests/data/test982
327345
@@ -0,0 +1,57 @@
327345
+<testcase>
327345
+<info>
327345
+<keywords>
327345
+POP3
327345
+STARTTLS
327345
+</keywords>
327345
+</info>
327345
+
327345
+#
327345
+# Server-side
327345
+<reply>
327345
+<servercmd>
327345
+CAPA STLS USER
327345
+REPLY STLS -ERR currently unavailable\r\n+OK user accepted\r\n+OK authenticated
327345
+REPLY PASS -ERR Authentication credentials invalid
327345
+</servercmd>
327345
+<data nocheck="yes">
327345
+From: me@somewhere
327345
+To: fake@nowhere
327345
+
327345
+body
327345
+
327345
+--
327345
+  yours sincerely
327345
+</data>
327345
+</reply>
327345
+
327345
+#
327345
+# Client-side
327345
+<client>
327345
+<features>
327345
+SSL
327345
+</features>
327345
+<server>
327345
+pop3
327345
+</server>
327345
+ <name>
327345
+POP3 STARTTLS pipelined server response
327345
+ </name>
327345
+ <command>
327345
+pop3://%HOSTIP:%POP3PORT/%TESTNUMBER -u user:secret --ssl
327345
+ </command>
327345
+</client>
327345
+
327345
+#
327345
+# Verify data after the test has been "shot"
327345
+<verify>
327345
+# 8 is CURLE_WEIRD_SERVER_REPLY
327345
+<errorcode>
327345
+8
327345
+</errorcode>
327345
+<protocol>
327345
+CAPA
327345
+STLS
327345
+</protocol>
327345
+</verify>
327345
+</testcase>
327345
diff --git a/tests/data/test983 b/tests/data/test983
327345
new file mode 100644
327345
index 0000000..300ec45
327345
--- /dev/null
327345
+++ b/tests/data/test983
327345
@@ -0,0 +1,52 @@
327345
+<testcase>
327345
+<info>
327345
+<keywords>
327345
+FTP
327345
+STARTTLS
327345
+</keywords>
327345
+</info>
327345
+
327345
+#
327345
+# Server-side
327345
+<reply>
327345
+<servercmd>
327345
+REPLY AUTH 500 unknown command\r\n500 unknown command\r\n331 give password\r\n230 Authenticated\r\n257 "/"\r\n200 OK\r\n200 OK\r\n200 OK\r\n226 Transfer complete
327345
+REPLY PASS 530 Login incorrect
327345
+</servercmd>
327345
+</reply>
327345
+
327345
+# Client-side
327345
+<client>
327345
+<features>
327345
+SSL
327345
+</features>
327345
+<server>
327345
+ftp
327345
+</server>
327345
+ <name>
327345
+FTP STARTTLS pipelined server response
327345
+ </name>
327345
+<file name="log/test%TESTNUMBER.txt">
327345
+data
327345
+    to
327345
+      see
327345
+that FTPS
327345
+works
327345
+  so does it?
327345
+</file>
327345
+ <command>
327345
+--ssl --ftp-ssl-control ftp://%HOSTIP:%FTPPORT/%TESTNUMBER -T log/test%TESTNUMBER.txt -u user:secret -P %CLIENTIP
327345
+</command>
327345
+</client>
327345
+
327345
+# Verify data after the test has been "shot"
327345
+<verify>
327345
+# 8 is CURLE_WEIRD_SERVER_REPLY
327345
+<errorcode>
327345
+8
327345
+</errorcode>
327345
+<protocol>
327345
+AUTH SSL
327345
+</protocol>
327345
+</verify>
327345
+</testcase>
327345
-- 
327345
2.31.1
327345