Skip to content

Commit

Permalink
update nginx to v.1.23.2
Browse files Browse the repository at this point in the history
  • Loading branch information
pangpang@hi-nginx.com committed Oct 20, 2022
1 parent 3081172 commit faedea1
Show file tree
Hide file tree
Showing 16 changed files with 856 additions and 148 deletions.
35 changes: 35 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@

Changes with nginx 1.23.2 19 Oct 2022

*) Security: processing of a specially crafted mp4 file by the
ngx_http_mp4_module might cause a worker process crash, worker
process memory disclosure, or might have potential other impact
(CVE-2022-41741, CVE-2022-41742).

*) Feature: the "$proxy_protocol_tlv_..." variables.

*) Feature: TLS session tickets encryption keys are now automatically
rotated when using shared memory in the "ssl_session_cache"
directive.

*) Change: the logging level of the "bad record type" SSL errors has
been lowered from "crit" to "info".
Thanks to Murilo Andrade.

*) Change: now when using shared memory in the "ssl_session_cache"
directive the "could not allocate new session" errors are logged at
the "warn" level instead of "alert" and not more often than once per
second.

*) Bugfix: nginx/Windows could not be built with OpenSSL 3.0.x.

*) Bugfix: in logging of the PROXY protocol errors.
Thanks to Sergey Brester.

*) Workaround: shared memory from the "ssl_session_cache" directive was
spent on sessions using TLS session tickets when using TLSv1.3 with
OpenSSL.

*) Workaround: timeout specified with the "ssl_session_timeout"
directive did not work when using TLSv1.3 with OpenSSL or BoringSSL.


Changes with nginx 1.23.1 19 Jul 2022

*) Feature: memory usage optimization in configurations with SSL
Expand Down
35 changes: 35 additions & 0 deletions CHANGES.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@

Изменения в nginx 1.23.2 19.10.2022

*) Безопасность: обработка специально созданного mp4-файла модулем
ngx_http_mp4_module могла приводить к падению рабочего процесса,
отправке клиенту части содержимого памяти рабочего процесса, а также
потенциально могла иметь другие последствия (CVE-2022-41741,
CVE-2022-41742).

*) Добавление: переменные "$proxy_protocol_tlv_...".

*) Добавление: ключи шифрования TLS session tickets теперь автоматически
меняются при использовании разделяемой памяти в ssl_session_cache.

*) Изменение: уровень логгирования ошибок SSL "bad record type" понижен
с уровня crit до info.
Спасибо Murilo Andrade.

*) Изменение: теперь при использовании разделяемой памяти в
ssl_session_cache сообщения "could not allocate new session"
логгируются на уровне warn вместо alert и не чаще одного раза в
секунду.

*) Исправление: nginx/Windows не собирался с OpenSSL 3.0.x.

*) Исправление: в логгировании ошибок протокола PROXY.
Спасибо Сергею Брестеру.

*) Изменение: при использовании TLSv1.3 с OpenSSL разделяемая память из
ssl_session_cache расходовалась в том числе на сессии, использующие
TLS session tickets.

*) Изменение: таймаут, заданный с помощью директивы ssl_session_timeout,
не работал при использовании TLSv1.3 с OpenSSL или BoringSSL.


Изменения в nginx 1.23.1 19.07.2022

*) Добавление: оптимизация использования памяти в конфигурациях с
Expand Down
2 changes: 1 addition & 1 deletion auto/lib/openssl/makefile.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
all:
cd $(OPENSSL)

perl Configure VC-WIN32 no-shared \
perl Configure VC-WIN32 no-shared no-threads \
--prefix="%cd%/openssl" \
--openssldir="%cd%/openssl/ssl" \
$(OPENSSL_OPT)
Expand Down
4 changes: 2 additions & 2 deletions src/core/nginx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#define _NGINX_H_INCLUDED_


#define nginx_version 1023001
#define NGINX_VERSION "1.23.1"
#define nginx_version 1023002
#define NGINX_VERSION "1.23.2"
#define NGINX_VER "nginx/" NGINX_VERSION

#ifdef NGX_BUILD
Expand Down
198 changes: 194 additions & 4 deletions src/core/ngx_proxy_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
#define NGX_PROXY_PROTOCOL_AF_INET6 2


#define ngx_proxy_protocol_parse_uint16(p) ((p)[0] << 8 | (p)[1])
#define ngx_proxy_protocol_parse_uint16(p) \
( ((uint16_t) (p)[0] << 8) \
+ ( (p)[1]) )

#define ngx_proxy_protocol_parse_uint32(p) \
( ((uint32_t) (p)[0] << 24) \
+ ( (p)[1] << 16) \
+ ( (p)[2] << 8) \
+ ( (p)[3]) )


typedef struct {
Expand All @@ -40,12 +48,52 @@ typedef struct {
} ngx_proxy_protocol_inet6_addrs_t;


typedef struct {
u_char type;
u_char len[2];
} ngx_proxy_protocol_tlv_t;


typedef struct {
u_char client;
u_char verify[4];
} ngx_proxy_protocol_tlv_ssl_t;


typedef struct {
ngx_str_t name;
ngx_uint_t type;
} ngx_proxy_protocol_tlv_entry_t;


static u_char *ngx_proxy_protocol_read_addr(ngx_connection_t *c, u_char *p,
u_char *last, ngx_str_t *addr);
static u_char *ngx_proxy_protocol_read_port(u_char *p, u_char *last,
in_port_t *port, u_char sep);
static u_char *ngx_proxy_protocol_v2_read(ngx_connection_t *c, u_char *buf,
u_char *last);
static ngx_int_t ngx_proxy_protocol_lookup_tlv(ngx_connection_t *c,
ngx_str_t *tlvs, ngx_uint_t type, ngx_str_t *value);


static ngx_proxy_protocol_tlv_entry_t ngx_proxy_protocol_tlv_entries[] = {
{ ngx_string("alpn"), 0x01 },
{ ngx_string("authority"), 0x02 },
{ ngx_string("unique_id"), 0x05 },
{ ngx_string("ssl"), 0x20 },
{ ngx_string("netns"), 0x30 },
{ ngx_null_string, 0x00 }
};


static ngx_proxy_protocol_tlv_entry_t ngx_proxy_protocol_tlv_ssl_entries[] = {
{ ngx_string("version"), 0x21 },
{ ngx_string("cn"), 0x22 },
{ ngx_string("cipher"), 0x23 },
{ ngx_string("sig_alg"), 0x24 },
{ ngx_string("key_alg"), 0x25 },
{ ngx_null_string, 0x00 }
};


u_char *
Expand Down Expand Up @@ -139,8 +187,14 @@ ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last)

invalid:

for (p = buf; p < last; p++) {
if (*p == CR || *p == LF) {
break;
}
}

ngx_log_error(NGX_LOG_ERR, c->log, 0,
"broken header: \"%*s\"", (size_t) (last - buf), buf);
"broken header: \"%*s\"", (size_t) (p - buf), buf);

return NULL;
}
Expand Down Expand Up @@ -412,11 +466,147 @@ ngx_proxy_protocol_v2_read(ngx_connection_t *c, u_char *buf, u_char *last)
&pp->src_addr, pp->src_port, &pp->dst_addr, pp->dst_port);

if (buf < end) {
ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
"PROXY protocol v2 %z bytes of tlv ignored", end - buf);
pp->tlvs.data = ngx_pnalloc(c->pool, end - buf);
if (pp->tlvs.data == NULL) {
return NULL;
}

ngx_memcpy(pp->tlvs.data, buf, end - buf);
pp->tlvs.len = end - buf;
}

c->proxy_protocol = pp;

return end;
}


ngx_int_t
ngx_proxy_protocol_get_tlv(ngx_connection_t *c, ngx_str_t *name,
ngx_str_t *value)
{
u_char *p;
size_t n;
uint32_t verify;
ngx_str_t ssl, *tlvs;
ngx_int_t rc, type;
ngx_proxy_protocol_tlv_ssl_t *tlv_ssl;
ngx_proxy_protocol_tlv_entry_t *te;

if (c->proxy_protocol == NULL) {
return NGX_DECLINED;
}

ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
"PROXY protocol v2 get tlv \"%V\"", name);

te = ngx_proxy_protocol_tlv_entries;
tlvs = &c->proxy_protocol->tlvs;

p = name->data;
n = name->len;

if (n >= 4 && p[0] == 's' && p[1] == 's' && p[2] == 'l' && p[3] == '_') {

rc = ngx_proxy_protocol_lookup_tlv(c, tlvs, 0x20, &ssl);
if (rc != NGX_OK) {
return rc;
}

if (ssl.len < sizeof(ngx_proxy_protocol_tlv_ssl_t)) {
return NGX_ERROR;
}

p += 4;
n -= 4;

if (n == 6 && ngx_strncmp(p, "verify", 6) == 0) {

tlv_ssl = (ngx_proxy_protocol_tlv_ssl_t *) ssl.data;
verify = ngx_proxy_protocol_parse_uint32(tlv_ssl->verify);

value->data = ngx_pnalloc(c->pool, NGX_INT32_LEN);
if (value->data == NULL) {
return NGX_ERROR;
}

value->len = ngx_sprintf(value->data, "%uD", verify)
- value->data;
return NGX_OK;
}

ssl.data += sizeof(ngx_proxy_protocol_tlv_ssl_t);
ssl.len -= sizeof(ngx_proxy_protocol_tlv_ssl_t);

te = ngx_proxy_protocol_tlv_ssl_entries;
tlvs = &ssl;
}

if (n >= 2 && p[0] == '0' && p[1] == 'x') {

type = ngx_hextoi(p + 2, n - 2);
if (type == NGX_ERROR) {
ngx_log_error(NGX_LOG_ERR, c->log, 0,
"invalid PROXY protocol TLV \"%V\"", name);
return NGX_ERROR;
}

return ngx_proxy_protocol_lookup_tlv(c, tlvs, type, value);
}

for ( /* void */ ; te->type; te++) {
if (te->name.len == n && ngx_strncmp(te->name.data, p, n) == 0) {
return ngx_proxy_protocol_lookup_tlv(c, tlvs, te->type, value);
}
}

ngx_log_error(NGX_LOG_ERR, c->log, 0,
"unknown PROXY protocol TLV \"%V\"", name);

return NGX_DECLINED;
}


static ngx_int_t
ngx_proxy_protocol_lookup_tlv(ngx_connection_t *c, ngx_str_t *tlvs,
ngx_uint_t type, ngx_str_t *value)
{
u_char *p;
size_t n, len;
ngx_proxy_protocol_tlv_t *tlv;

ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
"PROXY protocol v2 lookup tlv:%02xi", type);

p = tlvs->data;
n = tlvs->len;

while (n) {
if (n < sizeof(ngx_proxy_protocol_tlv_t)) {
ngx_log_error(NGX_LOG_ERR, c->log, 0, "broken PROXY protocol TLV");
return NGX_ERROR;
}

tlv = (ngx_proxy_protocol_tlv_t *) p;
len = ngx_proxy_protocol_parse_uint16(tlv->len);

p += sizeof(ngx_proxy_protocol_tlv_t);
n -= sizeof(ngx_proxy_protocol_tlv_t);

if (n < len) {
ngx_log_error(NGX_LOG_ERR, c->log, 0, "broken PROXY protocol TLV");
return NGX_ERROR;
}

if (tlv->type == type) {
value->data = p;
value->len = len;
return NGX_OK;
}

p += len;
n -= len;
}

return NGX_DECLINED;
}
3 changes: 3 additions & 0 deletions src/core/ngx_proxy_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ struct ngx_proxy_protocol_s {
ngx_str_t dst_addr;
in_port_t src_port;
in_port_t dst_port;
ngx_str_t tlvs;
};


u_char *ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf,
u_char *last);
u_char *ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf,
u_char *last);
ngx_int_t ngx_proxy_protocol_get_tlv(ngx_connection_t *c, ngx_str_t *name,
ngx_str_t *value);


#endif /* _NGX_PROXY_PROTOCOL_H_INCLUDED_ */
7 changes: 3 additions & 4 deletions src/event/modules/ngx_iocp_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,8 @@ ngx_iocp_del_connection(ngx_connection_t *c, ngx_uint_t flags)
}


static
ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
ngx_uint_t flags)
static ngx_int_t
ngx_iocp_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
{
int rc;
u_int key;
Expand Down Expand Up @@ -356,7 +355,7 @@ ngx_iocp_create_conf(ngx_cycle_t *cycle)

cf = ngx_palloc(cycle->pool, sizeof(ngx_iocp_conf_t));
if (cf == NULL) {
return NGX_CONF_ERROR;
return NULL;
}

cf->threads = NGX_CONF_UNSET;
Expand Down

0 comments on commit faedea1

Please sign in to comment.