Browse code

nginx: Fix for CVE-2018-16843 and CVE-2018-16844

Added patch for each CVE fix

Change-Id: I856c4c50ceadbdb8a4d4b931b0b069f52eb738bf
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/6380
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Anish Swaminathan <anishs@vmware.com>

Ankit Jain authored on 2018/12/18 05:52:04
Showing 4 changed files
1 1
deleted file mode 100644
... ...
@@ -1,15 +0,0 @@
1
-+++ src/os/unix/ngx_files.c
2
-@@ -356,6 +356,11 @@
3
-     n = 0;
4
- 
5
-     for ( /* void */ ; cl; cl = cl->next) {
6
-+
7
-+        if (ngx_buf_special(cl->buf)) {
8
-+            continue;
9
-+        }
10
-+
11
-         size = cl->buf->last - cl->buf->pos;
12
- 
13
-         if (prev == cl->buf->pos) {
14
-
15 1
new file mode 100644
... ...
@@ -0,0 +1,61 @@
0
+
1
+# HG changeset patch
2
+# User Ruslan Ermilov <ru@nginx.com>
3
+# Date 1541510975 -10800
4
+# Node ID 1c6b6163c03945bcc65c252cc42b0af18744c085
5
+# Parent  fdc19a3289c1138bfe49ddbde310778ddc495729
6
+HTTP/2: flood detection.
7
+
8
+Fixed uncontrolled memory growth in case peer is flooding us with
9
+some frames (e.g., SETTINGS and PING) and doesn't read data.  Fix
10
+is to limit the number of allocated control frames.
11
+
12
+diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
13
+index 2c62190..b9943c9 100644
14
+--- a/src/http/v2/ngx_http_v2.c
15
+@@ -635,6 +635,7 @@ ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c)
16
+ 
17
+     h2c->pool = NULL;
18
+     h2c->free_frames = NULL;
19
++    h2c->frames = 0;
20
+     h2c->free_fake_connections = NULL;
21
+ 
22
+ #if (NGX_HTTP_SSL)
23
+@@ -2678,7 +2679,7 @@ ngx_http_v2_get_frame(ngx_http_v2_connection_t *h2c, size_t length,
24
+ 
25
+         frame->blocked = 0;
26
+ 
27
+-    } else {
28
++    } else if (h2c->frames < 10000) {
29
+         pool = h2c->pool ? h2c->pool : h2c->connection->pool;
30
+ 
31
+         frame = ngx_pcalloc(pool, sizeof(ngx_http_v2_out_frame_t));
32
+@@ -2702,6 +2703,15 @@ ngx_http_v2_get_frame(ngx_http_v2_connection_t *h2c, size_t length,
33
+         frame->last = frame->first;
34
+ 
35
+         frame->handler = ngx_http_v2_frame_handler;
36
++
37
++        h2c->frames++;
38
++
39
++    } else {
40
++        ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
41
++                      "http2 flood detected");
42
++
43
++        h2c->connection->error = 1;
44
++        return NULL;
45
+     }
46
+ 
47
+ #if (NGX_DEBUG)
48
+diff --git a/src/http/v2/ngx_http_v2.h b/src/http/v2/ngx_http_v2.h
49
+index 42e0eb1..11f774a 100644
50
+--- a/src/http/v2/ngx_http_v2.h
51
+@@ -115,6 +115,7 @@ struct ngx_http_v2_connection_s {
52
+     ngx_http_connection_t           *http_connection;
53
+ 
54
+     ngx_uint_t                       processing;
55
++    ngx_uint_t                       frames;
56
+ 
57
+     size_t                           send_window;
58
+     size_t                           recv_window;
0 59
new file mode 100644
... ...
@@ -0,0 +1,59 @@
0
+
1
+# HG changeset patch
2
+# User Ruslan Ermilov <ru@nginx.com>
3
+# Date 1541510989 -10800
4
+# Node ID 9200b41db765fbd6709765ba2d218e78ad8e9860
5
+# Parent  1c6b6163c03945bcc65c252cc42b0af18744c085
6
+HTTP/2: limit the number of idle state switches.
7
+
8
+An attack that continuously switches HTTP/2 connection between
9
+idle and active states can result in excessive CPU usage.
10
+This is because when a connection switches to the idle state,
11
+all of its memory pool caches are freed.
12
+
13
+This change limits the maximum allowed number of idle state
14
+switches to 10 * http2_max_requests (i.e., 10000 by default).
15
+This limits possible CPU usage in one connection, and also
16
+imposes a limit on the maximum lifetime of a connection.
17
+
18
+Initially reported by Gal Goldshtein from F5 Networks.
19
+
20
+diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
21
+index b9943c9..83f9c4a 100644
22
+--- a/src/http/v2/ngx_http_v2.c
23
+@@ -4237,12 +4237,19 @@ ngx_http_v2_idle_handler(ngx_event_t *rev)
24
+ 
25
+ #endif
26
+ 
27
+-    c->destroyed = 0;
28
+-    ngx_reusable_connection(c, 0);
29
+-
30
+     h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
31
+                                          ngx_http_v2_module);
32
+ 
33
++    if (h2c->idle++ > 10 * h2scf->max_requests) {
34
++        ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
35
++                      "http2 flood detected");
36
++        ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR);
37
++        return;
38
++    }
39
++
40
++    c->destroyed = 0;
41
++    ngx_reusable_connection(c, 0);
42
++
43
+     h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log);
44
+     if (h2c->pool == NULL) {
45
+         ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
46
+diff --git a/src/http/v2/ngx_http_v2.h b/src/http/v2/ngx_http_v2.h
47
+index 11f774a..83dbea3 100644
48
+--- a/src/http/v2/ngx_http_v2.h
49
+@@ -116,6 +116,7 @@ struct ngx_http_v2_connection_s {
50
+ 
51
+     ngx_uint_t                       processing;
52
+     ngx_uint_t                       frames;
53
++    ngx_uint_t                       idle;
54
+ 
55
+     size_t                           send_window;
56
+     size_t                           recv_window;
... ...
@@ -1,7 +1,7 @@
1 1
 Summary:        High-performance HTTP server and reverse proxy
2 2
 Name:           nginx
3 3
 Version:        1.13.8
4
-Release:        5%{?dist}
4
+Release:        6%{?dist}
5 5
 License:        BSD-2-Clause
6 6
 URL:            http://nginx.org/download/nginx-%{version}.tar.gz
7 7
 Group:          Applications/System
... ...
@@ -12,6 +12,8 @@ Source0:        %{name}-%{version}.tar.gz
12 12
 Source1:        nginx.service
13 13
 Source2:        nginx-njs-0.2.1.tar.gz
14 14
 %define sha1    nginx-njs=fd8c3f2d219f175be958796e3beaa17f3b465126
15
+Patch0:         nginx-CVE-2018-16843.patch
16
+Patch1:         nginx-CVE-2018-16844.patch
15 17
 BuildRequires:  openssl-devel
16 18
 BuildRequires:  pcre-devel
17 19
 BuildRequires:  which
... ...
@@ -20,6 +22,8 @@ NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as
20 20
 
21 21
 %prep
22 22
 %setup -q
23
+%patch0 -p1
24
+%patch1 -p1
23 25
 pushd ../
24 26
 mkdir nginx-njs
25 27
 tar -C nginx-njs -xf %{SOURCE2}
... ...
@@ -75,6 +79,8 @@ make -k check |& tee %{_specdir}/%{name}-check-log || %{nocheck}
75 75
 %dir %{_var}/log/nginx
76 76
 
77 77
 %changelog
78
+*   Mon Dec 17 2018 Ankit Jain <ankitja@vmware.com> 1.13.8-6
79
+-   Fix for CVE-2018-16843 and CVE-2018-16844
78 80
 *   Wed Nov 07 2018 Ajay Kaher <akaher@vmware.com> 1.13.8-5
79 81
 -   mark config files as non replaceable on upgrade.
80 82
 *   Mon Sep 10 2018 Keerthana K <keerthanak@vmware.com> 1.13.8-4