Skip to content

Commit 36a63e0

Browse files
windmgcchronolawdndx
committed
fix(patches): apply Nginx patch for detecting HTTP/2 stream reset attacks early (CVE-2023-44487)
From nginx/nginx@6ceef19 --------- Signed-off-by: Aapo Talvensaari <[email protected]> Co-authored-by: chronolaw <[email protected]> Co-authored-by: Datong Sun <[email protected]> (cherry picked from commit c54eddd)
1 parent 0b47e24 commit 36a63e0

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
diff --git a/bundle/nginx-1.21.4/src/http/v2/ngx_http_v2.c b/bundle/nginx-1.21.4/src/http/v2/ngx_http_v2.c
2+
index 3afa8b6..228b060 100644
3+
--- a/bundle/nginx-1.21.4/src/http/v2/ngx_http_v2.c
4+
+++ b/bundle/nginx-1.21.4/src/http/v2/ngx_http_v2.c
5+
@@ -361,6 +361,7 @@ ngx_http_v2_read_handler(ngx_event_t *rev)
6+
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http2 read handler");
7+
8+
h2c->blocked = 1;
9+
+ h2c->new_streams = 0;
10+
11+
if (c->close) {
12+
c->close = 0;
13+
@@ -1321,6 +1322,14 @@ ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
14+
goto rst_stream;
15+
}
16+
17+
+ if (h2c->new_streams++ >= 2 * h2scf->concurrent_streams) {
18+
+ ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
19+
+ "client sent too many streams at once");
20+
+
21+
+ status = NGX_HTTP_V2_REFUSED_STREAM;
22+
+ goto rst_stream;
23+
+ }
24+
+
25+
if (!h2c->settings_ack
26+
&& !(h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG)
27+
&& h2scf->preread_size < NGX_HTTP_V2_DEFAULT_WINDOW)
28+
@@ -1386,6 +1395,12 @@ ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
29+
30+
rst_stream:
31+
32+
+ if (h2c->refused_streams++ > ngx_max(h2scf->concurrent_streams, 100)) {
33+
+ ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
34+
+ "client sent too many refused streams");
35+
+ return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_NO_ERROR);
36+
+ }
37+
+
38+
if (ngx_http_v2_send_rst_stream(h2c, h2c->state.sid, status) != NGX_OK) {
39+
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
40+
}
41+
diff --git a/bundle/nginx-1.21.4/src/http/v2/ngx_http_v2.h b/bundle/nginx-1.21.4/src/http/v2/ngx_http_v2.h
42+
index 0eceae3..aef40bb 100644
43+
--- a/bundle/nginx-1.21.4/src/http/v2/ngx_http_v2.h
44+
+++ b/bundle/nginx-1.21.4/src/http/v2/ngx_http_v2.h
45+
@@ -124,6 +124,8 @@ struct ngx_http_v2_connection_s {
46+
ngx_uint_t processing;
47+
ngx_uint_t frames;
48+
ngx_uint_t idle;
49+
+ ngx_uint_t new_streams;
50+
+ ngx_uint_t refused_streams;
51+
ngx_uint_t priority_limit;
52+
53+
ngx_uint_t pushing;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
message: Apply Nginx patch for detecting HTTP/2 stream reset attacks early (CVE-2023-44487)
2+
type: bugfix
3+
scope: Core

0 commit comments

Comments
 (0)