]> git.kaiwu.me - nginx.git/log
nginx.git
7 years agoSSL: fixed potential leak on memory allocation errors.
Maxim Dounin [Sun, 3 Mar 2019 13:48:39 +0000 (16:48 +0300)]
SSL: fixed potential leak on memory allocation errors.

If ngx_pool_cleanup_add() fails, we have to clean just created SSL context
manually, thus appropriate call added.

Additionally, ngx_pool_cleanup_add() moved closer to ngx_ssl_create() in
the ngx_http_ssl_module, to make sure there are no leaks due to intermediate
code.

7 years agoSSL: server name callback changed to return fatal errors.
Maxim Dounin [Sun, 3 Mar 2019 13:48:06 +0000 (16:48 +0300)]
SSL: server name callback changed to return fatal errors.

Notably this affects various allocation errors, and should generally
improve things if an allocation error actually happens during a callback.

Depending on the OpenSSL version, returning an error can result in
either SSL_R_CALLBACK_FAILED or SSL_R_CLIENTHELLO_TLSEXT error from
SSL_do_handshake(), so both errors were switched to the "info" level.

7 years agoSSL: server name callback changed to return SSL_TLSEXT_ERR_OK.
Maxim Dounin [Sun, 3 Mar 2019 13:47:44 +0000 (16:47 +0300)]
SSL: server name callback changed to return SSL_TLSEXT_ERR_OK.

OpenSSL 1.1.1 does not save server name to the session if server name
callback returns anything but SSL_TLSEXT_ERR_OK, thus breaking
the $ssl_server_name variable in resumed sessions.

Since $ssl_server_name can be used even if we've selected the default
server and there are no other servers, it looks like the only viable
solution is to always return SSL_TLSEXT_ERR_OK regardless of the actual
result.

To fix things in the stream module as well, added a dummy server name
callback which always returns SSL_TLSEXT_ERR_OK.

7 years agoVersion bump.
Maxim Dounin [Sun, 3 Mar 2019 13:47:41 +0000 (16:47 +0300)]
Version bump.

7 years agorelease-1.15.9 tag
Maxim Dounin [Tue, 26 Feb 2019 15:29:22 +0000 (18:29 +0300)]
release-1.15.9 tag

7 years agonginx-1.15.9-RELEASE release-1.15.9
Maxim Dounin [Tue, 26 Feb 2019 15:29:22 +0000 (18:29 +0300)]
nginx-1.15.9-RELEASE

7 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 26 Feb 2019 15:01:30 +0000 (18:01 +0300)]
Updated OpenSSL used for win32 builds.

7 years agoSSL: fixed possible segfault with dynamic certificates.
Maxim Dounin [Mon, 25 Feb 2019 18:16:26 +0000 (21:16 +0300)]
SSL: fixed possible segfault with dynamic certificates.

A virtual server may have no SSL context if it does not have certificates
defined, so we have to use config of the ngx_http_ssl_module from the
SSL context in the certificate callback.  To do so, it is now passed as
the argument of the callback.

The stream module doesn't really need any changes, but was modified as
well to match http code.

7 years agoSSL: adjusted session id context with dynamic certificates.
Maxim Dounin [Mon, 25 Feb 2019 13:42:54 +0000 (16:42 +0300)]
SSL: adjusted session id context with dynamic certificates.

Dynamic certificates re-introduce problem with incorrect session
reuse (AKA "virtual host confusion", CVE-2014-3616), since there are
no server certificates to generate session id context from.

To prevent this, session id context is now generated from ssl_certificate
directives as specified in the configuration.  This approach prevents
incorrect session reuse in most cases, while still allowing sharing
sessions across multiple machines with ssl_session_ticket_key set as
long as configurations are identical.

7 years agoSSL: dynamic certificate loading in the stream module.
Maxim Dounin [Mon, 25 Feb 2019 13:42:43 +0000 (16:42 +0300)]
SSL: dynamic certificate loading in the stream module.

7 years agoSSL: passwords support for dynamic certificate loading.
Maxim Dounin [Mon, 25 Feb 2019 13:42:23 +0000 (16:42 +0300)]
SSL: passwords support for dynamic certificate loading.

Passwords have to be copied to the configuration pool to be used
at runtime.  Also, to prevent blocking on stdin (with "daemon off;")
an empty password list is provided.

To make things simpler, password handling was modified to allow
an empty array (with 0 elements and elts set to NULL) as an equivalent
of an array with 1 empty password.

7 years agoSSL: variables support in ssl_certificate and ssl_certificate_key.
Maxim Dounin [Mon, 25 Feb 2019 13:42:05 +0000 (16:42 +0300)]
SSL: variables support in ssl_certificate and ssl_certificate_key.

To evaluate variables, a request is created in the certificate callback,
and then freed.  To do this without side effects on the stub_status
counters and connection state, an additional function was introduced,
ngx_http_alloc_request().

Only works with OpenSSL 1.0.2+, since there is no SSL_CTX_set_cert_cb()
in older versions.

7 years agoSSL: loading of connection-specific certificates.
Maxim Dounin [Mon, 25 Feb 2019 13:41:44 +0000 (16:41 +0300)]
SSL: loading of connection-specific certificates.

7 years agoSSL: reworked ngx_ssl_certificate().
Maxim Dounin [Mon, 25 Feb 2019 13:41:28 +0000 (16:41 +0300)]
SSL: reworked ngx_ssl_certificate().

This makes it possible to reuse certificate loading at runtime,
as introduced in the following patches.

Additionally, this improves error logging, so nginx will now log
human-friendly messages "cannot load certificate" instead of only
referring to sometimes cryptic names of OpenSSL functions.

7 years agoSSL: removed logging of empty "(SSL:)" in ngx_ssl_error().
Maxim Dounin [Mon, 25 Feb 2019 13:41:15 +0000 (16:41 +0300)]
SSL: removed logging of empty "(SSL:)" in ngx_ssl_error().

The "(SSL:)" snippet currently appears in logs when nginx code uses
ngx_ssl_error() to log an error, but OpenSSL's error queue is empty.
This can happen either because the error wasn't in fact from OpenSSL,
or because OpenSSL did not indicate the error in the error queue
for some reason.

In particular, currently "(SSL:)" can be seen in errors at least in
the following cases:

- When SSL_write() fails due to a syscall error,
  "[info] ... SSL_write() failed (SSL:) (32: Broken pipe)...".

- When loading a certificate with no data in it,
  "[emerg] PEM_read_bio_X509_AUX(...) failed (SSL:)".
  This can easily happen due to an additional empty line before
  the end line, so all lines of the certificate are interpreted
  as header lines.

- When trying to configure an unknown curve,
  "[emerg] SSL_CTX_set1_curves_list("foo") failed (SSL:)".

Likely there are other cases as well.

With this change, "(SSL:...)" will be only added to the error message
if there is something in the error queue.  This is expected to make
logs more readable in the above cases.  Additionally, with this change
it is now possible to use ngx_ssl_error() to log errors when some
of the possible errors are not from OpenSSL and not expected to have
anything in the error queue.

7 years agoStyle.
Maxim Dounin [Mon, 25 Feb 2019 13:41:08 +0000 (16:41 +0300)]
Style.

7 years agoSlab: removed redundant page calculation (ticket #1721).
Maxim Dounin [Tue, 12 Feb 2019 18:51:15 +0000 (21:51 +0300)]
Slab: removed redundant page calculation (ticket #1721).

7 years agoUpstream: fixed logging of required buffer size (ticket #1722).
Chanhun Jeong [Mon, 11 Feb 2019 04:36:53 +0000 (13:36 +0900)]
Upstream: fixed logging of required buffer size (ticket #1722).

7 years agoSSL: fixed EVP_DigestFinal_ex() error message.
Sergey Kandaurov [Thu, 7 Feb 2019 16:39:35 +0000 (19:39 +0300)]
SSL: fixed EVP_DigestFinal_ex() error message.

7 years agoSSL: separate checks for errors in ngx_ssl_read_password_file().
Maxim Dounin [Thu, 31 Jan 2019 16:36:51 +0000 (19:36 +0300)]
SSL: separate checks for errors in ngx_ssl_read_password_file().

Checking multiple errors at once is a bad practice, as in general
it is not guaranteed that an object can be used after the error.
In this particular case, checking errors after multiple allocations
can result in excessive errors being logged when there is no memory
available.

7 years agoSSL: explicitly zero out session ticket keys.
Ruslan Ermilov [Thu, 31 Jan 2019 16:28:07 +0000 (19:28 +0300)]
SSL: explicitly zero out session ticket keys.

7 years agoModules compatibility: down flag in ngx_peer_connection_t.
Roman Arutyunyan [Thu, 31 Jan 2019 14:25:03 +0000 (17:25 +0300)]
Modules compatibility: down flag in ngx_peer_connection_t.

7 years agoUse %s for errors returned from configuration parsing handlers.
Ruslan Ermilov [Tue, 25 Dec 2018 12:26:58 +0000 (15:26 +0300)]
Use %s for errors returned from configuration parsing handlers.

7 years agoConfigure: added explicit ngx_binext to the linker output argument.
Sergey Kandaurov [Wed, 30 Jan 2019 16:28:27 +0000 (19:28 +0300)]
Configure: added explicit ngx_binext to the linker output argument.

Unlike with GCC or MSVC, Clang linker doesn't auto-append ".exe" to the name
of the output binary when building on win32.

7 years agoRemoved --test-build-eventport workaround for old FreeBSD versions.
Sergey Kandaurov [Mon, 28 Jan 2019 14:34:02 +0000 (14:34 +0000)]
Removed --test-build-eventport workaround for old FreeBSD versions.

7 years agoFixed portability issues with union sigval.
Sergey Kandaurov [Mon, 28 Jan 2019 14:33:31 +0000 (14:33 +0000)]
Fixed portability issues with union sigval.

AIO support in nginx was originally developed against FreeBSD versions 4-6,
where the sival_ptr field was named as sigval_ptr (seemingly by mistake[1]),
which made nginx use the only name available then.  The standard-complaint
name was restored in 2005 (first appeared in FreeBSD 7.0, 2008), retaining
compatibility with previous versions[2][3].  In DragonFly, similar changes
were committed in 2009[4], with backward compatibility recently removed[5].

The change switches to the standard name, retaining compatibility with old
FreeBSD versions.

[1] https://svnweb.freebsd.org/changeset/base/48621
[2] https://svnweb.freebsd.org/changeset/base/152029
[3] https://svnweb.freebsd.org/changeset/base/174003
[4] https://gitweb.dragonflybsd.org/dragonfly.git/commit/3693401
[5] https://gitweb.dragonflybsd.org/dragonfly.git/commit/7875042

7 years agoYear 2019.
Maxim Konovalov [Mon, 28 Jan 2019 10:23:37 +0000 (13:23 +0300)]
Year 2019.

7 years agoWin32: detection of connect() errors in select().
Maxim Dounin [Thu, 24 Jan 2019 19:00:44 +0000 (22:00 +0300)]
Win32: detection of connect() errors in select().

On Windows, connect() errors are only reported via exceptfds descriptor set
from select().  Previously exceptfds was set to NULL, and connect() errors
were not detected at all, so connects to closed ports were waiting till
a timeout occurred.

Since ongoing connect() means that there will be a write event active,
except descriptor set is copied from the write one.  While it is possible
to construct except descriptor set as a concatenation of both read and write
descriptor sets, this looks unneeded.

With this change, connect() errors are properly detected now when using
select().  Note well that it is not possible to detect connect() errors with
WSAPoll() (see https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/).

7 years agoWin32: enabled both select and poll on Windows by default.
Maxim Dounin [Thu, 24 Jan 2019 19:00:13 +0000 (22:00 +0300)]
Win32: enabled both select and poll on Windows by default.

Since we now have both select and poll on Windows, it is enough to
do not set EVENT_FOUND, auto/modules will enable both automatically.

7 years agoWin32: added WSAPoll() support.
Maxim Dounin [Thu, 24 Jan 2019 18:51:21 +0000 (21:51 +0300)]
Win32: added WSAPoll() support.

WSAPoll() is only available with Windows Vista and newer (and only
available during compilation if _WIN32_WINNT >= 0x0600).  To make
sure the code works with Windows XP, we do not redefine _WIN32_WINNT,
but instead load WSAPoll() dynamically if it is not available during
compilation.

Also, sockets are not guaranteed to be small integers on Windows.
So an index array is used instead of NGX_USE_FD_EVENT to map
events to connections.

7 years agoWin32: properly enabled select on Windows.
Maxim Dounin [Thu, 24 Jan 2019 18:51:00 +0000 (21:51 +0300)]
Win32: properly enabled select on Windows.

Previously, select was compiled in by default, but the NGX_HAVE_SELECT
macro was not set, resulting in iocp being used by default unless
the "--with-select_module" configure option was explicitly specified.
Since the iocp module is not finished and does not work properly, this
effectively meant that the "--with-select_module" option was mandatory.

With the change NGX_HAVE_SELECT is properly set, making "--with-select_module"
optional.  Accordingly, it is removed from misc/GNUmakefile win32 target.

7 years agoEvents: fixed copying of old events in poll init.
Maxim Dounin [Thu, 24 Jan 2019 18:50:37 +0000 (21:50 +0300)]
Events: fixed copying of old events in poll init.

Previously, the code incorrectly assumed "ngx_event_t *" elements
instead of "struct pollfd".

This is mostly cosmetic change, as this code is never called now.

7 years agoStream: do not split datagrams when limiting proxy rate.
Roman Arutyunyan [Thu, 27 Dec 2018 16:37:34 +0000 (19:37 +0300)]
Stream: do not split datagrams when limiting proxy rate.

Previously, when using proxy_upload_rate and proxy_download_rate, the buffer
size for reading from a socket could be reduced as a result of rate limiting.
For connection-oriented protocols this behavior is normal since unread data will
normally be read at the next iteration.  But for datagram-oriented protocols
this is not the case, and unread part of the datagram is lost.

Now buffer size is not limited for datagrams.  Rate limiting still works in this
case by delaying the next reading event.

7 years agoPrevented scheduling events on a shared connection.
Roman Arutyunyan [Mon, 14 Jan 2019 17:36:23 +0000 (20:36 +0300)]
Prevented scheduling events on a shared connection.

A shared connection does not own its file descriptor, which means that
ngx_handle_read_event/ngx_handle_write_event calls should do nothing for it.
Currently the c->shared flag is checked in several places in the stream proxy
module prior to calling these functions.  However it was not done everywhere.
Missing checks could lead to calling
ngx_handle_read_event/ngx_handle_write_event on shared connections.

The problem manifested itself when using proxy_upload_rate and resulted in
either duplicate file descriptor error (e.g. with epoll) or incorrect further
udp packet processing (e.g. with kqueue).

The fix is to set and reset the event active flag in a way that prevents
ngx_handle_read_event/ngx_handle_write_event from scheduling socket events.

7 years agoAdded the ngx_http_test_required_predicates() function.
Vladimir Homutov [Thu, 17 Jan 2019 11:31:04 +0000 (14:31 +0300)]
Added the ngx_http_test_required_predicates() function.

In contrast to ngx_http_test_predicates(), it requires all values to be
non-empty and not equal to "0".

7 years agoVersion bump.
Vladimir Homutov [Thu, 17 Jan 2019 11:31:01 +0000 (14:31 +0300)]
Version bump.

7 years agorelease-1.15.8 tag
Maxim Dounin [Tue, 25 Dec 2018 14:53:03 +0000 (17:53 +0300)]
release-1.15.8 tag

7 years agonginx-1.15.8-RELEASE release-1.15.8
Maxim Dounin [Tue, 25 Dec 2018 14:53:03 +0000 (17:53 +0300)]
nginx-1.15.8-RELEASE

7 years agoAutoindex: fixed possible integer overflow on 32-bit systems.
Vladimir Homutov [Tue, 25 Dec 2018 09:59:24 +0000 (12:59 +0300)]
Autoindex: fixed possible integer overflow on 32-bit systems.

7 years agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Mon, 24 Dec 2018 14:30:10 +0000 (16:30 +0200)]
Contrib: vim syntax, update core and 3rd party module directives.

7 years agoWin32: removed NGX_DIR_MASK concept.
Maxim Dounin [Mon, 24 Dec 2018 18:07:05 +0000 (21:07 +0300)]
Win32: removed NGX_DIR_MASK concept.

Previous interface of ngx_open_dir() assumed that passed directory name
has a room for NGX_DIR_MASK at the end (NGX_DIR_MASK_LEN bytes).  While all
direct users of ngx_dir_open() followed this interface, this also implied
similar requirements for indirect uses - in particular, via ngx_walk_tree().

Currently none of ngx_walk_tree() uses provides appropriate space, and
fixing this does not look like a right way to go.  Instead, ngx_dir_open()
interface was changed to not require any additional space and use
appropriate allocations instead.

7 years agoUserid: using stub for AF_UNIX addresses.
Sergey Kandaurov [Mon, 24 Dec 2018 16:55:00 +0000 (19:55 +0300)]
Userid: using stub for AF_UNIX addresses.

Previously, AF_UNIX addresses misbehaved as AF_INET, which typically resulted
in $uid_set composed from the middle of sun_path.

7 years agoSSL: avoid reading on pending SSL_write_early_data().
Sergey Kandaurov [Tue, 18 Dec 2018 12:15:15 +0000 (15:15 +0300)]
SSL: avoid reading on pending SSL_write_early_data().

If SSL_write_early_data() returned SSL_ERROR_WANT_WRITE, stop further reading
using a newly introduced c->ssl->write_blocked flag, as otherwise this would
result in SSL error "ssl3_write_bytes:bad length".  Eventually, normal reading
will be restored by read event posted from successful SSL_write_early_data().

While here, place "SSL_write_early_data: want write" debug on the path.

7 years agoGeo: fixed handling of AF_UNIX client addresses (ticket #1684).
Maxim Dounin [Fri, 14 Dec 2018 15:11:06 +0000 (18:11 +0300)]
Geo: fixed handling of AF_UNIX client addresses (ticket #1684).

Previously, AF_UNIX client addresses were handled as AF_INET, leading
to unexpected results.

7 years agoUpstream: implemented $upstream_bytes_sent.
Ruslan Ermilov [Thu, 13 Dec 2018 14:23:07 +0000 (17:23 +0300)]
Upstream: implemented $upstream_bytes_sent.

7 years agoResolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan [Tue, 11 Dec 2018 16:41:22 +0000 (19:41 +0300)]
Resolver: report SRV resolve failure if all A resolves failed.

Previously, if an SRV record was successfully resolved, but all of its A
records failed to resolve, NXDOMAIN was returned to the caller, which is
considered a successful resolve rather than an error.  This could result in
losing the result of a previous successful resolve by the caller.

Now NXDOMAIN is only returned if at least one A resolve completed with this
code.  Otherwise the error state of the first A resolve is returned.

7 years agoCopy regex unnamed captures to cloned subrequests.
Roman Arutyunyan [Tue, 11 Dec 2018 10:09:00 +0000 (13:09 +0300)]
Copy regex unnamed captures to cloned subrequests.

Previously, unnamed regex captures matched in the parent request, were not
available in a cloned subrequest.  Now 3 fields related to unnamed captures
are copied to a cloned subrequest: r->ncaptures, r->captures and
r->captures_data.  Since r->captures cannot be changed by either request after
creating a clone, a new flag r->realloc_captures is introduced to force
reallocation of r->captures.

The issue was reported as a proxy_cache_background_update misbehavior in
http://mailman.nginx.org/pipermail/nginx/2018-December/057251.html.

7 years agoVersion bump.
Roman Arutyunyan [Tue, 11 Dec 2018 10:12:35 +0000 (13:12 +0300)]
Version bump.

7 years agorelease-1.15.7 tag
Maxim Dounin [Tue, 27 Nov 2018 14:40:21 +0000 (17:40 +0300)]
release-1.15.7 tag

7 years agonginx-1.15.7-RELEASE release-1.15.7
Maxim Dounin [Tue, 27 Nov 2018 14:40:20 +0000 (17:40 +0300)]
nginx-1.15.7-RELEASE

7 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 27 Nov 2018 14:02:56 +0000 (17:02 +0300)]
Updated OpenSSL used for win32 builds.

7 years agoNegative size buffers detection.
Maxim Dounin [Mon, 26 Nov 2018 15:29:56 +0000 (18:29 +0300)]
Negative size buffers detection.

In the past, there were several security issues which resulted in
worker process memory disclosure due to buffers with negative size.
It looks reasonable to check for such buffers in various places,
much like we already check for zero size buffers.

While here, removed "#if 1 / #endif" around zero size buffer checks.
It looks highly unlikely that we'll disable these checks anytime soon.

7 years agoMp4: fixed possible pointer overflow on 32-bit platforms.
Maxim Dounin [Wed, 21 Nov 2018 17:23:16 +0000 (20:23 +0300)]
Mp4: fixed possible pointer overflow on 32-bit platforms.

On 32-bit platforms mp4->buffer_pos might overflow when a large
enough (close to 4 gigabytes) atom is being skipped, resulting in
incorrect memory addesses being read further in the code.  In most
cases this results in harmless errors being logged, though may also
result in a segmentation fault if hitting unmapped pages.

To address this, ngx_mp4_atom_next() now only increments mp4->buffer_pos
up to mp4->buffer_end.  This ensures that overflow cannot happen.

7 years agoLimit req: "delay=" parameter.
Maxim Dounin [Wed, 21 Nov 2018 15:56:50 +0000 (18:56 +0300)]
Limit req: "delay=" parameter.

This parameter specifies an additional "soft" burst limit at which requests
become delayed (but not yet rejected as it happens if "burst=" limit is
exceeded).  Defaults to 0, i.e., all excess requests are delayed.

Originally inspired by Vladislav Shabanov
(http://mailman.nginx.org/pipermail/nginx-devel/2016-April/008126.html).
Further improved based on a patch by Peter Shchuchkin
(http://mailman.nginx.org/pipermail/nginx-devel/2018-October/011522.html).

7 years agoLimit req: fixed error message wording.
Maxim Dounin [Wed, 21 Nov 2018 15:56:44 +0000 (18:56 +0300)]
Limit req: fixed error message wording.

7 years agoUpstream: revised upstream response time variables.
Vladimir Homutov [Wed, 21 Nov 2018 10:40:40 +0000 (13:40 +0300)]
Upstream: revised upstream response time variables.

Variables now do not depend on presence of the HTTP status code in response.
If the corresponding event occurred, variables contain time between request
creation and the event, and "-" otherwise.

Previously, intermediate value of the $upstream_response_time variable held
unix timestamp.

7 years agoUpstream: removed unused ngx_http_upstream_t.timeout field.
Vladimir Homutov [Wed, 21 Nov 2018 10:40:36 +0000 (13:40 +0300)]
Upstream: removed unused ngx_http_upstream_t.timeout field.

7 years agoCore: ngx_explicit_memzero().
Maxim Dounin [Thu, 15 Nov 2018 18:28:02 +0000 (21:28 +0300)]
Core: ngx_explicit_memzero().

7 years agoCore: free shared memory on cycle initialization failure.
Ruslan Ermilov [Thu, 15 Nov 2018 12:28:54 +0000 (15:28 +0300)]
Core: free shared memory on cycle initialization failure.

7 years agoStream: proxy_requests directive.
Vladimir Homutov [Mon, 12 Nov 2018 13:29:30 +0000 (16:29 +0300)]
Stream: proxy_requests directive.

The directive allows to drop binding between a client and existing UDP stream
session after receiving a specified number of packets.  First packet from the
same client address and port will start a new session.  Old session continues
to exist and will terminate at moment defined by configuration: either after
receiving the expected number of responses, or after timeout, as specified by
the "proxy_responses" and/or "proxy_timeout" directives.

By default, proxy_requests is zero (disabled).

7 years agoStream: session completion check code moved to a separate function.
Vladimir Homutov [Mon, 12 Nov 2018 09:05:03 +0000 (12:05 +0300)]
Stream: session completion check code moved to a separate function.

The code refactored to simplify the ngx_stream_proxy_process() function
and facilitate adding new session termination conditions.

7 years agoStream: fixed possible use of a freed connection.
Vladimir Homutov [Wed, 7 Nov 2018 10:22:14 +0000 (13:22 +0300)]
Stream: fixed possible use of a freed connection.

The session handler may result in session termination, thus a connection
pool (from which c->udp was allocated) may be destroyed.

7 years agoVersion bump.
Vladimir Homutov [Tue, 13 Nov 2018 11:42:47 +0000 (14:42 +0300)]
Version bump.

7 years agorelease-1.15.6 tag
Maxim Dounin [Tue, 6 Nov 2018 13:32:09 +0000 (16:32 +0300)]
release-1.15.6 tag

7 years agonginx-1.15.6-RELEASE release-1.15.6
Maxim Dounin [Tue, 6 Nov 2018 13:32:08 +0000 (16:32 +0300)]
nginx-1.15.6-RELEASE

7 years agogRPC: limited allocations due to ping and settings frames.
Maxim Dounin [Tue, 6 Nov 2018 13:29:59 +0000 (16:29 +0300)]
gRPC: limited allocations due to ping and settings frames.

7 years agoHTTP/2: limit the number of idle state switches.
Ruslan Ermilov [Tue, 6 Nov 2018 13:29:49 +0000 (16:29 +0300)]
HTTP/2: limit the number of idle state switches.

An attack that continuously switches HTTP/2 connection between
idle and active states can result in excessive CPU usage.
This is because when a connection switches to the idle state,
all of its memory pool caches are freed.

This change limits the maximum allowed number of idle state
switches to 10 * http2_max_requests (i.e., 10000 by default).
This limits possible CPU usage in one connection, and also
imposes a limit on the maximum lifetime of a connection.

Initially reported by Gal Goldshtein from F5 Networks.

7 years agoHTTP/2: flood detection.
Ruslan Ermilov [Tue, 6 Nov 2018 13:29:35 +0000 (16:29 +0300)]
HTTP/2: flood detection.

Fixed uncontrolled memory growth in case peer is flooding us with
some frames (e.g., SETTINGS and PING) and doesn't read data.  Fix
is to limit the number of allocated control frames.

7 years agoMp4: fixed reading 64-bit atoms.
Roman Arutyunyan [Tue, 6 Nov 2018 13:29:18 +0000 (16:29 +0300)]
Mp4: fixed reading 64-bit atoms.

Previously there was no validation for the size of a 64-bit atom
in an mp4 file.  This could lead to a CPU hog when the size is 0,
or various other problems due to integer underflow when calculating
atom data size, including segmentation fault or worker process
memory disclosure.

7 years agoCache: improved keys zone size error reporting.
Maxim Dounin [Wed, 31 Oct 2018 13:49:40 +0000 (16:49 +0300)]
Cache: improved keys zone size error reporting.

After this change, too small keys zones are explicitly reported as such,
much like in the other modules which use shared memory.

7 years agoCache: fixed minimum cache keys zone size limit.
Maxim Dounin [Wed, 31 Oct 2018 13:49:39 +0000 (16:49 +0300)]
Cache: fixed minimum cache keys zone size limit.

Size of a shared memory zones must be at least two pages - one page
for slab allocator internal data, and another page for actual allocations.
Using 8192 instead is wrong, as there are systems with page sizes other
than 4096.

Note well that two pages is usually too low as well.  In particular, cache
is likely to use two allocations of different sizes for global structures,
and at least four pages will be needed to properly allocate cache nodes.
Except in a few very special cases, with keys zone of just two pages nginx
won't be able to start.  Other uses of shared memory impose a limit
of 8 pages, which provides some room for global allocations.  This patch
doesn't try to address this though.

Inspired by ticket #1665.

7 years agoA minor code clean for macro ngx_event_get_conf in ngx_event.h.
chronolaw [Fri, 19 Oct 2018 05:50:36 +0000 (13:50 +0800)]
A minor code clean for macro ngx_event_get_conf in ngx_event.h.

7 years agoSSL: explicitly set maximum version (ticket #1654).
Maxim Dounin [Tue, 23 Oct 2018 19:11:48 +0000 (22:11 +0300)]
SSL: explicitly set maximum version (ticket #1654).

With maximum version explicitly set, TLSv1.3 will not be unexpectedly
enabled if nginx compiled with OpenSSL 1.1.0 (without TLSv1.3 support)
will be run with OpenSSL 1.1.1 (with TLSv1.3 support).

7 years agoUpstream: proxy_socket_keepalive and friends.
Vladimir Homutov [Wed, 3 Oct 2018 11:08:51 +0000 (14:08 +0300)]
Upstream: proxy_socket_keepalive and friends.

The directives enable the use of the SO_KEEPALIVE option on
upstream connections.  By default, the value is left unchanged.

7 years agoVersion bump.
Vladimir Homutov [Wed, 3 Oct 2018 14:02:44 +0000 (17:02 +0300)]
Version bump.

7 years agorelease-1.15.5 tag
Maxim Dounin [Tue, 2 Oct 2018 15:13:52 +0000 (18:13 +0300)]
release-1.15.5 tag

7 years agonginx-1.15.5-RELEASE release-1.15.5
Maxim Dounin [Tue, 2 Oct 2018 15:13:51 +0000 (18:13 +0300)]
nginx-1.15.5-RELEASE

7 years agoSSL: fixed segfault on renegotiation (ticket #1646).
Maxim Dounin [Tue, 2 Oct 2018 14:46:18 +0000 (17:46 +0300)]
SSL: fixed segfault on renegotiation (ticket #1646).

In e3ba4026c02d (1.15.4) nginx own renegotiation checks were disabled
if SSL_OP_NO_RENEGOTIATION is available.  But since SSL_OP_NO_RENEGOTIATION
is only set on a connection, not in an SSL context, SSL_clear_option()
removed it as long as a matching virtual server was found.  This resulted
in a segmentation fault similar to the one fixed in a6902a941279 (1.9.8),
affecting nginx built with OpenSSL 1.1.0h or higher.

To fix this, SSL_OP_NO_RENEGOTIATION is now explicitly set in
ngx_http_ssl_servername() after adjusting options.  Additionally, instead
of c->ssl->renegotiation we now check c->ssl->handshaked, which seems
to be a more correct flag to test, and will prevent the segmentation fault
from happening even if SSL_OP_NO_RENEGOTIATION is not working.

7 years agoFixed off-by-one error in shared zone initialization.
Ruslan Ermilov [Tue, 2 Oct 2018 10:32:52 +0000 (13:32 +0300)]
Fixed off-by-one error in shared zone initialization.

On systems without atomic ops, not enough space was allocated
for mutex's file name during shared zone initialization.

7 years agoSSL: fixed unlocked access to sess_id->len.
Ruslan Ermilov [Tue, 25 Sep 2018 11:07:59 +0000 (14:07 +0300)]
SSL: fixed unlocked access to sess_id->len.

7 years agoVersion bump.
Ruslan Ermilov [Thu, 27 Sep 2018 10:05:39 +0000 (13:05 +0300)]
Version bump.

7 years agorelease-1.15.4 tag
Maxim Dounin [Tue, 25 Sep 2018 15:11:39 +0000 (18:11 +0300)]
release-1.15.4 tag

7 years agonginx-1.15.4-RELEASE release-1.15.4
Maxim Dounin [Tue, 25 Sep 2018 15:11:39 +0000 (18:11 +0300)]
nginx-1.15.4-RELEASE

7 years agoSSL: logging level of "no suitable signature algorithm".
Maxim Dounin [Tue, 25 Sep 2018 11:00:04 +0000 (14:00 +0300)]
SSL: logging level of "no suitable signature algorithm".

The "no suitable signature algorithm" errors are reported by OpenSSL 1.1.1
when using TLSv1.3 if there are no shared signature algorithms.  In
particular, this can happen if the client limits available signature
algorithms to something we don't have a certificate for, or to an empty
list.  For example, the following command:

    openssl s_client -connect 127.0.0.1:8443 -sigalgs rsa_pkcs1_sha1

will always result in the "no suitable signature algorithm" error
as the "rsa_pkcs1_sha1" algorithm refers solely to signatures which
appear in certificates and not defined for use in TLS 1.3 handshake
messages.

The SSL_R_NO_COMMON_SIGNATURE_ALGORITHMS error is what BoringSSL returns
in the same situation.

7 years agoSSL: logging level of "no suitable key share".
Maxim Dounin [Tue, 25 Sep 2018 10:59:53 +0000 (13:59 +0300)]
SSL: logging level of "no suitable key share".

The "no suitable key share" errors are reported by OpenSSL 1.1.1 when
using TLSv1.3 if there are no shared groups (that is, elliptic curves).
In particular, it is easy enough to trigger by using only a single
curve in ssl_ecdh_curve:

    ssl_ecdh_curve secp384r1;

and using a different curve in the client:

    openssl s_client -connect 127.0.0.1:443 -curves prime256v1

On the client side it is seen as "sslv3 alert handshake failure",
"SSL alert number 40":

0:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:ssl/record/rec_layer_s3.c:1528:SSL alert number 40

It can be also triggered with default ssl_ecdh_curve by using a curve
which is not in the default list (X25519, prime256v1, X448, secp521r1,
secp384r1):

    openssl s_client -connect 127.0.0.1:8443 -curves brainpoolP512r1

Given that many clients hardcode prime256v1, these errors might become
a common problem with TLSv1.3 if ssl_ecdh_curve is redefined.  Previously
this resulted in not using ECDH with such clients, but with TLSv1.3 it
is no longer possible and will result in a handshake failure.

The SSL_R_NO_SHARED_GROUP error is what BoringSSL returns in the same
situation.

Seen at:

https://serverfault.com/questions/932102/nginx-ssl-handshake-error-no-suitable-key-share

7 years agoCache: status must be less then 599 in *_cache_valid directives.
Gena Makhomed [Mon, 24 Sep 2018 17:26:46 +0000 (20:26 +0300)]
Cache: status must be less then 599 in *_cache_valid directives.

Previously, configurations with typo, for example

    fastcgi_cache_valid 200301 302 5m;

successfully pass configuration test. Adding check for status
codes > 599, and such configurations are now properly rejected.

7 years agoRemoved bgcolor attribute on body in error pages and autoindex.
Nova DasSarma [Wed, 19 Sep 2018 14:26:47 +0000 (09:26 -0500)]
Removed bgcolor attribute on body in error pages and autoindex.

The bgcolor attribute overrides compatibility settings in browsers
and leads to undesirable behavior when the default font color is set
to white in the browser, since font-color is not also overridden.

7 years agoSSL: support for TLSv1.3 early data with OpenSSL.
Sergey Kandaurov [Fri, 21 Sep 2018 17:49:12 +0000 (20:49 +0300)]
SSL: support for TLSv1.3 early data with OpenSSL.

In collaboration with Maxim Dounin.

7 years agoSSL: disabled renegotiation checks with SSL_OP_NO_RENEGOTIATION.
Maxim Dounin [Fri, 21 Sep 2018 17:31:32 +0000 (20:31 +0300)]
SSL: disabled renegotiation checks with SSL_OP_NO_RENEGOTIATION.

Following 7319:dcab86115261, as long as SSL_OP_NO_RENEGOTIATION is
defined, it is OpenSSL library responsibility to prevent renegotiation,
so the checks are meaningless.

Additionally, with TLSv1.3 OpenSSL tends to report SSL_CB_HANDSHAKE_START
at various unexpected moments - notably, on KeyUpdate messages and
when sending tickets.  This change prevents unexpected connection
close on KeyUpdate messages and when finishing handshake with upcoming
early data changes.

7 years agoRewrite: removed r->err_status special handling (ticket #1634).
Maxim Dounin [Fri, 21 Sep 2018 12:59:33 +0000 (15:59 +0300)]
Rewrite: removed r->err_status special handling (ticket #1634).

Trying to look into r->err_status in the "return" directive
makes it behave differently than real errors generated in other
parts of the code, and is an endless source of various problems.
This behaviour was introduced in 726:7b71936d5299 (0.4.4) with
the comment "fix: "return" always overrode "error_page" response code".
It is not clear if there were any real cases this was expected to fix,
but there are several cases which are broken due to this change, some
previously fixed (4147:7f64de1cc2c0).

In ticket #1634, the problem is that when r->err_status is set to
a non-special status code, it is not possible to return a response
by simply returning r->err_status.  If this is the case, the only
option is to return script's e->status instead.  An example
configuration:

    location / {
        error_page 404 =200 /err502;
        return 404;
    }

    location = /err502 {
        return 502;
    }

After the change, such a configuration will properly return
standard 502 error, much like it happens when a 502 error is
generated by proxy_pass.

This also fixes the following configuration to properly close
connection as clearly requested by "return 444":

    location / {
        error_page 404 /close;
        return 404;
    }

    location = /close {
        return 444;
    }

Previously, this required "error_page 404 = /close;" to work
as intended.

7 years agoFixed socket leak with "return 444" in error_page (ticket #274).
Maxim Dounin [Fri, 21 Sep 2018 12:59:30 +0000 (15:59 +0300)]
Fixed socket leak with "return 444" in error_page (ticket #274).

Socket leak was observed in the following configuration:

    error_page 400 = /close;

    location = /close {
        return 444;
    }

The problem is that "return 444" triggers termination of the request,
and due to error_page termination thinks that it needs to use a posted
request to clear stack.  But at the early request processing where 400
errors are generated there are no ngx_http_run_posted_requests() calls,
so the request is only terminated after an external event.

Variants of the problem include "error_page 497" instead (ticket #695)
and various other errors generated during early request processing
(405, 414, 421, 494, 495, 496, 501, 505).

The same problem can be also triggered with "return 499" and "return 408"
as both codes trigger ngx_http_terminate_request(), much like "return 444".

To fix this, the patch adds ngx_http_run_posted_requests() calls to
ngx_http_process_request_line() and ngx_http_process_request_headers()
functions, and to ngx_http_v2_run_request() and ngx_http_v2_push_stream()
functions in HTTP/2.

Since the ngx_http_process_request() function is now only called via
other functions which call ngx_http_run_posted_requests(), the call
there is no longer needed and was removed.

7 years agoSSL: restore handlers after blocking.
Maxim Dounin [Mon, 10 Sep 2018 15:57:39 +0000 (18:57 +0300)]
SSL: restore handlers after blocking.

It is possible that after SSL_read() will return SSL_ERROR_WANT_WRITE,
further calls will return SSL_ERROR_WANT_READ without reading any
application data.  We have to call ngx_handle_write_event() and
switch back to normal write handling much like we do if there are some
application data, or the write there will be reported again and again.

Similarly, we have to switch back to normal read handling if there
is saved read handler and SSL_write() returns SSL_ERROR_WANT_WRITE.

7 years agoSSL: corrected SSL_ERROR_WANT_WRITE / SSL_ERROR_WANT_READ logging.
Maxim Dounin [Mon, 10 Sep 2018 15:57:19 +0000 (18:57 +0300)]
SSL: corrected SSL_ERROR_WANT_WRITE / SSL_ERROR_WANT_READ logging.

While SSL_read() most likely to return SSL_ERROR_WANT_WRITE (and SSL_write()
accordingly SSL_ERROR_WANT_READ) during an SSL renegotiation, it is
not necessary mean that a renegotiation was started.  In particular,
it can never happen during a renegotiation or can happen multiple times
during a renegotiation.

Because of the above, misleading "peer started SSL renegotiation" info
messages were replaced with "SSL_read: want write" and "SSL_write: want read"
debug ones.

Additionally, "SSL write handler" and "SSL read handler" are now logged
by the SSL write and read handlers, to make it easier to understand that
temporary SSL handlers are called instead of normal handlers.

7 years agoLingering close changed to handle NGX_AGAIN.
Maxim Dounin [Mon, 10 Sep 2018 15:57:13 +0000 (18:57 +0300)]
Lingering close changed to handle NGX_AGAIN.

The "do { c->recv() } while (c->read->ready)" form used in the
ngx_http_lingering_close_handler() is not really correct, as for
example with SSL c->read->ready may be still set when returning NGX_AGAIN
due to SSL_ERROR_WANT_WRITE.  Therefore the above might be an infinite loop.

This doesn't really matter in lingering close, as we shutdown write side
of the socket anyway and also disable renegotiation (and even without shutdown
and with renegotiation it requires using very large certificate chain and
tuning socket buffers to trigger SSL_ERROR_WANT_WRITE).  But for the sake of
correctness added an NGX_AGAIN check.

7 years agogRPC: disabled keepalive when sending control frames was blocked.
Maxim Dounin [Mon, 3 Sep 2018 16:34:02 +0000 (19:34 +0300)]
gRPC: disabled keepalive when sending control frames was blocked.

If sending request body was not completed (u->request_body_sent is not set),
the upstream keepalive module won't save such a connection.  However, it
is theoretically possible (though highly unlikely) that sending of some
control frames can be blocked after the request body was sent.  The
ctx->output_blocked flag introduced to disable keepalive in such cases.

7 years agogRPC: improved keepalive handling.
Maxim Dounin [Mon, 3 Sep 2018 16:34:01 +0000 (19:34 +0300)]
gRPC: improved keepalive handling.

The code is now able to parse additional control frames after
the response is received, and can send control frames as well.
This fixes keepalive problems as observed with grpc-c, which can
send window update and ping frames after the response, see
http://mailman.nginx.org/pipermail/nginx/2018-August/056620.html.

7 years agoUwsgi: added a check on maximum uwsgi request size.
Maxim Dounin [Mon, 3 Sep 2018 16:17:06 +0000 (19:17 +0300)]
Uwsgi: added a check on maximum uwsgi request size.

Requested by Chris Caputo.

7 years agoUwsgi: style.
Maxim Dounin [Mon, 3 Sep 2018 16:17:01 +0000 (19:17 +0300)]
Uwsgi: style.

7 years agoVersion bump.
Roman Arutyunyan [Thu, 30 Aug 2018 11:42:15 +0000 (14:42 +0300)]
Version bump.

7 years agoStream: avoid potential infinite loop at preread phase.
Roman Arutyunyan [Wed, 29 Aug 2018 12:56:42 +0000 (15:56 +0300)]
Stream: avoid potential infinite loop at preread phase.

Previously the preread phase code ignored NGX_AGAIN value returned from
c->recv() and relied only on c->read->ready.  But this flag is not reliable and
should only be checked for optimization purposes.  For example, when using
SSL, c->read->ready may be set when no input is available.  This can lead to
calling preread handler infinitely in a loop.