Browse code

[PR 2139730] Fix for CVE-2018-1000168 in nghttp2 to avoid NULL pointer dereference of ALTSVC frame.

Change-Id: If108bfad9eea74a5dd0b11086ca61dec6af4823c
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5271
Reviewed-by: Sharath George
Tested-by: Sharath George

dweepadvani authored on 2018/06/19 10:54:42
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,80 @@
0
+--- a/tests/nghttp2_session_test.c	2017-05-30 20:42:01.000000000 +0530
1
+@@ -81,8 +81,10 @@
2
+ } my_user_data;
3
+ 
4
+ static const nghttp2_nv reqnv[] = {
5
+-    MAKE_NV(":method", "GET"), MAKE_NV(":path", "/"),
6
+-    MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "localhost"),
7
++    MAKE_NV(":method", "GET"),
8
++    MAKE_NV(":path", "/"),
9
++    MAKE_NV(":scheme", "https"),
10
++    MAKE_NV(":authority", "localhost"),
11
+ };
12
+ 
13
+ static const nghttp2_nv resnv[] = {
14
+@@ -938,7 +940,7 @@
15
+   stream = open_sent_stream2(session, 1, NGHTTP2_STREAM_CLOSING);
16
+ 
17
+   /* Set initial window size 16383 to check stream flow control,
18
+-     isolating it from the conneciton flow control */
19
++     isolating it from the connection flow control */
20
+   stream->local_window_size = 16383;
21
+ 
22
+   ud.data_chunk_recv_cb_called = 0;
23
+@@ -2295,6 +2297,31 @@
24
+ 
25
+   nghttp2_session_del(session);
26
+ 
27
++  /* send too large frame */
28
++  nghttp2_buf_reset(&buf);
29
++
30
++  nghttp2_session_client_new2(&session, &callbacks, &ud, option);
31
++
32
++  session->local_settings.max_frame_size = NGHTTP2_MAX_FRAME_SIZE_MIN - 1;
33
++
34
++  nghttp2_frame_hd_init(&hd, NGHTTP2_MAX_FRAME_SIZE_MIN + 1, NGHTTP2_ALTSVC,
35
++                        NGHTTP2_FLAG_NONE, 0);
36
++  nghttp2_frame_pack_frame_hd(buf.last, &hd);
37
++  buf.last += NGHTTP2_FRAME_HDLEN;
38
++  nghttp2_put_uint16be(buf.last, sizeof(origin) - 1);
39
++  buf.last += 2;
40
++  buf.last = nghttp2_cpymem(buf.last, origin, sizeof(origin) - 1);
41
++  memset(buf.last, 0, nghttp2_buf_avail(&buf));
42
++  buf.last += nghttp2_buf_avail(&buf);
43
++
44
++  ud.frame_recv_cb_called = 0;
45
++  rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf));
46
++
47
++  CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv);
48
++  CU_ASSERT(0 == ud.frame_recv_cb_called);
49
++
50
++  nghttp2_session_del(session);
51
++
52
+   /* received by server */
53
+   nghttp2_buf_reset(&buf);
54
+ 
55
+@@ -5876,9 +5903,8 @@
56
+ 
57
+   len = nghttp2_session_mem_send(session, &data);
58
+ 
59
+-  CU_ASSERT(len ==
60
+-            NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1 + sizeof(field_value) -
61
+-                1);
62
++  CU_ASSERT(len == NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1 +
63
++                       sizeof(field_value) - 1);
64
+ 
65
+   nghttp2_frame_unpack_frame_hd(&hd, data);
66
+ 
67
+--- a/lib/nghttp2_frame.c	2017-05-30 20:42:01.000000000 +0530
68
+@@ -215,6 +215,9 @@
69
+   nghttp2_ext_altsvc *altsvc;
70
+ 
71
+   altsvc = frame->payload;
72
++  if (altsvc == NULL) {
73
++    return;
74
++  }
75
+   /* We use the same buffer for altsvc->origin and
76
+      altsvc->field_value. */
77
+   nghttp2_mem_free(mem, altsvc->origin);
... ...
@@ -1,7 +1,7 @@
1 1
 Summary:    nghttp2 is an implementation of HTTP/2 and its header compression algorithm, HPACK.
2 2
 Name:       nghttp2
3 3
 Version:    1.23.1
4
-Release:    1%{?dist}
4
+Release:    2%{?dist}
5 5
 License:    MIT
6 6
 URL:        https://nghttp2.org
7 7
 Group:      Applications/System
... ...
@@ -10,6 +10,8 @@ Distribution: Photon
10 10
 Source0:        https://github.com/nghttp2/nghttp2/releases/download/v1.23.1/%{name}-%{version}.tar.xz
11 11
 %define sha1 nghttp2=80758c07d20fcde717243c1a0baf99da78693fca
12 12
 
13
+Patch0:        CVE-2018-1000168.patch
14
+
13 15
 BuildRequires: c-ares-devel
14 16
 BuildRequires: openssl-devel
15 17
 BuildRequires: systemd
... ...
@@ -31,6 +33,7 @@ These are the header files of nghttp2.
31 31
 
32 32
 %prep
33 33
 %setup -q
34
+%patch0 -p1
34 35
 
35 36
 %build
36 37
 ./configure --prefix=%{_prefix}        \
... ...
@@ -58,5 +61,7 @@ rm %{buildroot}/%{_libdir}/*.la
58 58
 %{_libdir}/pkgconfig/*.pc
59 59
 
60 60
 %changelog
61
+*   Tue Jun 18 2018 Dweep Advani <dadvani@vmware.com> 1.23.1-2
62
+-   Fix of CVE-2018-1000168.
61 63
 *   Tue Jun 13 2017 Dheeraj Shetty <dheerajs@vmware.com> 1.23.1-1
62 64
 -   First version