]> git.kaiwu.me - nginx.git/log
nginx.git
3 years agoWin32: non-ASCII names in ngx_fs_bsize(), ngx_fs_available().
Maxim Dounin [Thu, 23 Feb 2023 17:50:03 +0000 (20:50 +0300)]
Win32: non-ASCII names in ngx_fs_bsize(), ngx_fs_available().

This fixes potentially incorrect cache size calculations and non-working
"min_free" when using cache in directories with non-ASCII names.

3 years agoWin32: removed attempt to use a drive letter in ngx_fs_bsize().
Maxim Dounin [Thu, 23 Feb 2023 17:50:00 +0000 (20:50 +0300)]
Win32: removed attempt to use a drive letter in ngx_fs_bsize().

Just a drive letter might not correctly represent file system being used,
notably when using symlinks (as created by "mklink /d").  As such, instead
of trying to call GetDiskFreeSpace() with just a drive letter, we now always
use GetDiskFreeSpace() with full path.

Further, it looks like the code to use just a drive letter never worked,
since it tried to test name[2] instead of name[1] to be ':'.

3 years agoWin32: non-ASCII names support in ngx_open_tempfile().
Maxim Dounin [Thu, 23 Feb 2023 17:49:57 +0000 (20:49 +0300)]
Win32: non-ASCII names support in ngx_open_tempfile().

This makes it possible to use temporary directories with non-ASCII characters,
either explicitly or via a prefix with non-ASCII characters in it.

3 years agoWin32: non-ASCII names support in ngx_rename_file().
Maxim Dounin [Thu, 23 Feb 2023 17:49:55 +0000 (20:49 +0300)]
Win32: non-ASCII names support in ngx_rename_file().

This makes it possible to upload files with non-ASCII characters
when using the dav module (ticket #1433).

3 years agoWin32: non-ASCII names support in ngx_delete_file().
Maxim Dounin [Thu, 23 Feb 2023 17:49:54 +0000 (20:49 +0300)]
Win32: non-ASCII names support in ngx_delete_file().

This makes it possible to delete files with non-ASCII characters
when using the dav module (ticket #1433).

3 years agoWin32: reworked ngx_win32_rename_file() to use nginx wrappers.
Maxim Dounin [Thu, 23 Feb 2023 17:49:52 +0000 (20:49 +0300)]
Win32: reworked ngx_win32_rename_file() to use nginx wrappers.

This ensures that ngx_win32_rename_file() will support non-ASCII names
when supported by the wrappers.

Notably, this is used by PUT requests in the dav module when overwriting
existing files with non-ASCII names (ticket #1433).

3 years agoWin32: reworked ngx_win32_rename_file() to check errors.
Maxim Dounin [Thu, 23 Feb 2023 17:49:50 +0000 (20:49 +0300)]
Win32: reworked ngx_win32_rename_file() to check errors.

Previously, ngx_win32_rename_file() retried on all errors returned by
MoveFile() to a temporary name.  It only make sense, however, to retry
when the destination file already exists, similarly to the condition
when ngx_win32_rename_file() is called.  Retrying on other errors is
meaningless and might result in an infinite loop.

3 years agoWin32: non-ASCII directory names support in ngx_delete_dir().
Maxim Dounin [Thu, 23 Feb 2023 17:49:47 +0000 (20:49 +0300)]
Win32: non-ASCII directory names support in ngx_delete_dir().

This makes it possible to delete directories with non-ASCII characters
when using the dav module (ticket #1433).

3 years agoWin32: non-ASCII directory names support in ngx_create_dir().
Maxim Dounin [Thu, 23 Feb 2023 17:49:45 +0000 (20:49 +0300)]
Win32: non-ASCII directory names support in ngx_create_dir().

This makes it possible to create directories under prefix with non-ASCII
characters, as well as makes it possible to create directories with non-ASCII
characters when using the dav module (ticket #1433).

To ensure that the dav module operations are restricted similarly to
other file operations (in particular, short names are not allowed), the
ngx_win32_check_filename() function is used.  It improved to support
checking of just dirname, and now can be used to check paths when creating
files or directories.

3 years agoWin32: non-ASCII directory names support in ngx_getcwd().
Maxim Dounin [Thu, 23 Feb 2023 17:49:44 +0000 (20:49 +0300)]
Win32: non-ASCII directory names support in ngx_getcwd().

This makes it possible to start nginx without a prefix explicitly set
in a directory with non-ASCII characters in it.

3 years agoWin32: non-ASCII names support in "include" with wildcards.
Maxim Dounin [Thu, 23 Feb 2023 17:49:41 +0000 (20:49 +0300)]
Win32: non-ASCII names support in "include" with wildcards.

Notably, ngx_open_glob() now supports opening directories with non-ASCII
characters, and pathnames returned by ngx_read_glob() are converted to UTF-8.

3 years agoWin32: non-ASCII names support in autoindex (ticket #458).
Maxim Dounin [Thu, 23 Feb 2023 17:49:39 +0000 (20:49 +0300)]
Win32: non-ASCII names support in autoindex (ticket #458).

Notably, ngx_open_dir() now supports opening directories with non-ASCII
characters, and directory entries returned by ngx_read_dir() are properly
converted to UTF-8.

3 years agoWin32: OpenSSL compilation for x64 targets with MSVC.
Maxim Dounin [Thu, 23 Feb 2023 15:16:08 +0000 (18:16 +0300)]
Win32: OpenSSL compilation for x64 targets with MSVC.

To ensure proper target selection the NGX_MACHINE variable is now set
based on the MSVC compiler output, and the OpenSSL target is set based
on it.

This is not important as long as "no-asm" is used (as in misc/GNUmakefile
and win32 build instructions), but might be beneficial if someone is trying
to build OpenSSL with assembler code.

3 years agoWin32: i386 now assumed when crossbuilding (ticket #2416).
Maxim Dounin [Thu, 23 Feb 2023 15:15:59 +0000 (18:15 +0300)]
Win32: i386 now assumed when crossbuilding (ticket #2416).

Previously, NGX_MACHINE was not set when crossbuilding, resulting in
NGX_ALIGNMENT=16 being used in 32-bit builds (if not explicitly set to a
correct value).  This in turn might result in memory corruption in
ngx_palloc() (as there are no usable aligned allocator on Windows, and
normal malloc() is used instead, which provides 8 byte alignment on
32-bit platforms).

To fix this, now i386 machine is set when crossbuilding, so nginx won't
assume strict alignment requirements.

3 years agoWin32: handling of localized MSVC cl output.
Maxim Dounin [Thu, 23 Feb 2023 15:15:57 +0000 (18:15 +0300)]
Win32: handling of localized MSVC cl output.

Output examples in English, Russian, and Spanish:

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Оптимизирующий 32-разрядный компилятор Microsoft (R) C/C++ версии 16.00.30319.01 для 80x86
Compilador de optimización de C/C++ de Microsoft (R) versión 16.00.30319.01 para x64

Since most of the words are translated, instead of looking for the words
"Compiler Version" we now search for "C/C++" and the version number.

3 years agoWin32: removed unneeded wildcard in NGX_CC_NAME test for msvc.
Maxim Dounin [Thu, 23 Feb 2023 15:15:53 +0000 (18:15 +0300)]
Win32: removed unneeded wildcard in NGX_CC_NAME test for msvc.

Wildcards for msvc in NGX_CC_NAME tests are not needed since 78f8ac479735.

3 years agoLingering close for connections with pipelined requests.
Maxim Dounin [Thu, 2 Feb 2023 20:38:48 +0000 (23:38 +0300)]
Lingering close for connections with pipelined requests.

This is expected to help with clients using pipelining with some constant
depth, such as apt[1][2].

When downloading many resources, apt uses pipelining with some constant
depth, a number of requests in flight.  This essentially means that after
receiving a response it sends an additional request to the server, and
this can result in requests arriving to the server at any time.  Further,
additional requests are sent one-by-one, and can be easily seen as such
(neither as pipelined, nor followed by pipelined requests).

The only safe approach to close such connections (for example, when
keepalive_requests is reached) is with lingering.  To do so, now nginx
monitors if pipelining was used on the connection, and if it was, closes
the connection with lingering.

[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=973861#10
[2] https://mailman.nginx.org/pipermail/nginx-devel/2023-January/ZA2SP5SJU55LHEBCJMFDB2AZVELRLTHI.html

3 years agoFixed "zero size buf" alerts with subrequests.
Maxim Dounin [Sat, 28 Jan 2023 02:23:33 +0000 (05:23 +0300)]
Fixed "zero size buf" alerts with subrequests.

Since 4611:2b6cb7528409 responses from the gzip static, flv, and mp4 modules
can be used with subrequests, though empty files were not properly handled.
Empty gzipped, flv, and mp4 files thus resulted in "zero size buf in output"
alerts.  While valid corresponding files are not expected to be empty, such
files shouldn't result in alerts.

Fix is to set b->sync on such empty subrequest responses, similarly to what
ngx_http_send_special() does.

Additionally, the static module, the ngx_http_send_response() function, and
file cache are modified to do the same instead of not sending the response
body at all in such cases, since not sending the response body at all is
believed to be at least questionable, and might break various filters
which do not expect such behaviour.

3 years agoStyle.
Maxim Dounin [Sat, 28 Jan 2023 02:20:23 +0000 (05:20 +0300)]
Style.

3 years agoAdded warning about redefinition of listen socket protocol options.
Maxim Dounin [Fri, 27 Jan 2023 22:29:45 +0000 (01:29 +0300)]
Added warning about redefinition of listen socket protocol options.

The "listen" directive in the http module can be used multiple times
in different server blocks.  Originally, it was supposed to be specified
once with various socket options, and without any parameters in virtual
server blocks.  For example:

    server { listen 80 backlog=1024; server_name foo; ... }
    server { listen 80; server_name bar; ... }
    server { listen 80; server_name bazz; ... }

The address part of the syntax ("address[:port]" / "port" / "unix:path")
uniquely identifies the listening socket, and therefore is enough for
name-based virtual servers (to let nginx know that the virtual server
accepts requests on the listening socket in question).

To ensure that listening options do not conflict between virtual servers,
they were allowed only once.  For example, the following configuration
will be rejected ("duplicate listen options for 0.0.0.0:80 in ..."):

    server { listen 80 backlog=1024; server_name foo; ... }
    server { listen 80 backlog=512; server_name bar; ... }

At some point it was, however, noticed, that it is sometimes convenient
to repeat some options for clarity.  In nginx 0.8.51 the "ssl" parameter
was allowed to be specified multiple times, e.g.:

    server { listen 443 ssl backlog=1024; server_name foo; ... }
    server { listen 443 ssl; server_name bar; ... }
    server { listen 443 ssl; server_name bazz; ... }

This approach makes configuration more readable, since SSL sockets are
immediately visible in the configuration.  If this is not needed, just the
address can still be used.

Later, additional protocol-specific options similar to "ssl" were
introduced, notably "http2" and "proxy_protocol".  With these options,
one can write:

    server { listen 443 ssl backlog=1024; server_name foo; ... }
    server { listen 443 http2; server_name bar; ... }
    server { listen 443 proxy_protocol; server_name bazz; ... }

The resulting socket will use ssl, http2, and proxy_protocol, but this
is not really obvious from the configuration.

To emphasize such misleading configurations are discouraged, nginx now
warns as long as the "listen" directive is used with options different
from the options previously used if this is potentially confusing.

In particular, the following configurations are allowed:

    server { listen 8401 ssl backlog=1024; server_name foo; }
    server { listen 8401 ssl; server_name bar; }
    server { listen 8401 ssl; server_name bazz; }

    server { listen 8402 ssl http2 backlog=1024; server_name foo; }
    server { listen 8402 ssl; server_name bar; }
    server { listen 8402 ssl; server_name bazz; }

    server { listen 8403 ssl; server_name bar; }
    server { listen 8403 ssl; server_name bazz; }
    server { listen 8403 ssl http2; server_name foo; }

    server { listen 8404 ssl http2 backlog=1024; server_name foo; }
    server { listen 8404 http2; server_name bar; }
    server { listen 8404 http2; server_name bazz; }

    server { listen 8405 ssl http2 backlog=1024; server_name foo; }
    server { listen 8405 ssl http2; server_name bar; }
    server { listen 8405 ssl http2; server_name bazz; }

    server { listen 8406 ssl; server_name foo; }
    server { listen 8406; server_name bar; }
    server { listen 8406; server_name bazz; }

And the following configurations will generate warnings:

    server { listen 8501 ssl http2 backlog=1024; server_name foo; }
    server { listen 8501 http2; server_name bar; }
    server { listen 8501 ssl; server_name bazz; }

    server { listen 8502 backlog=1024; server_name foo; }
    server { listen 8502 ssl; server_name bar; }

    server { listen 8503 ssl; server_name foo; }
    server { listen 8503 http2; server_name bar; }

    server { listen 8504 ssl; server_name foo; }
    server { listen 8504 http2; server_name bar; }
    server { listen 8504 proxy_protocol; server_name bazz; }

    server { listen 8505 ssl http2 proxy_protocol; server_name foo; }
    server { listen 8505 ssl http2; server_name bar; }
    server { listen 8505 ssl; server_name bazz; }

    server { listen 8506 ssl http2; server_name foo; }
    server { listen 8506 ssl; server_name bar; }
    server { listen 8506; server_name bazz; }

    server { listen 8507 ssl; server_name bar; }
    server { listen 8507; server_name bazz; }
    server { listen 8507 ssl http2; server_name foo; }

    server { listen 8508 ssl; server_name bar; }
    server { listen 8508; server_name bazz; }
    server { listen 8508 ssl backlog=1024; server_name foo; }

    server { listen 8509; server_name bazz; }
    server { listen 8509 ssl; server_name bar; }
    server { listen 8509 ssl backlog=1024; server_name foo; }

The basic idea is that at most two sets of protocol options are allowed:
the main one (with socket options, if any), and a shorter one, with options
being a subset of the main options, repeated for clarity.  As long as the
shorter set of protocol options is used, all listen directives except the
main one should use it.

3 years agoFixed handling of very long locations (ticket #2435).
Maxim Dounin [Thu, 26 Jan 2023 00:34:44 +0000 (03:34 +0300)]
Fixed handling of very long locations (ticket #2435).

Previously, location prefix length in ngx_http_location_tree_node_t was
stored as "u_char", and therefore location prefixes longer than 255 bytes
were handled incorrectly.

Fix is to use "u_short" instead.  With "u_short", prefixes up to 65535 bytes
can be safely used, and this isn't reachable due to NGX_CONF_BUFFER, which
is 4096 bytes.

3 years agoGzip static: ranges support (ticket #2349).
Maxim Dounin [Tue, 24 Jan 2023 00:01:51 +0000 (03:01 +0300)]
Gzip static: ranges support (ticket #2349).

In contrast to on-the-fly gzipping with gzip filter, static gzipped
representation as returned by gzip_static is persistent, and therefore
the same binary representation is available for future requests, making
it possible to use range requests.

Further, if a gzipped representation is re-generated with different
compression settings, it is expected to result in different ETag and
different size reported in the Content-Range header, making it possible
to safely use range requests anyway.

As such, ranges are now allowed for files returned by gzip_static.

3 years agoConfigure: removed unneeded header from UDP_SEGMENT test.
Maxim Dounin [Mon, 23 Jan 2023 02:01:01 +0000 (05:01 +0300)]
Configure: removed unneeded header from UDP_SEGMENT test.

3 years agoUpdated link to OpenVZ suspend/resume bug.
Maxim Dounin [Wed, 21 Dec 2022 11:53:27 +0000 (14:53 +0300)]
Updated link to OpenVZ suspend/resume bug.

3 years agoFixed port ranges support in the listen directive.
Valentin Bartenev [Sun, 18 Dec 2022 18:29:02 +0000 (21:29 +0300)]
Fixed port ranges support in the listen directive.

Ports difference must be respected when checking addresses for duplicates,
otherwise configurations like this are broken:

  listen 127.0.0.1:6000-6005

It was broken by 4cc2bfeff46c (nginx 1.23.3).

3 years agoStyle.
BullerDu [Thu, 15 Dec 2022 21:15:15 +0000 (01:15 +0400)]
Style.

3 years agoVersion bump.
Sergey Kandaurov [Thu, 15 Dec 2022 21:15:13 +0000 (01:15 +0400)]
Version bump.

3 years agorelease-1.23.3 tag
Maxim Dounin [Tue, 13 Dec 2022 15:53:53 +0000 (18:53 +0300)]
release-1.23.3 tag

3 years agonginx-1.23.3-RELEASE release-1.23.3
Maxim Dounin [Tue, 13 Dec 2022 15:53:53 +0000 (18:53 +0300)]
nginx-1.23.3-RELEASE

3 years agoUpdated OpenSSL and zlib used for win32 builds.
Maxim Dounin [Tue, 13 Dec 2022 00:32:57 +0000 (03:32 +0300)]
Updated OpenSSL and zlib used for win32 builds.

3 years agoWin32: event flags handling edge cases in ngx_wsarecv().
Maxim Dounin [Thu, 1 Dec 2022 01:22:36 +0000 (04:22 +0300)]
Win32: event flags handling edge cases in ngx_wsarecv().

Fixed event flags handling edge cases in ngx_wsarecv() and ngx_wsarecv_chain(),
notably to always reset rev->ready in case of errors (which wasn't the case
after ngx_socket_nread() errors), and after EOF (rev->ready was not cleared
if due to a misconfiguration a zero-sized buffer was used for reading).

3 years agoSSL: fixed ngx_ssl_recv() to reset c->read->ready after errors.
Maxim Dounin [Thu, 1 Dec 2022 01:22:31 +0000 (04:22 +0300)]
SSL: fixed ngx_ssl_recv() to reset c->read->ready after errors.

With this change, behaviour of ngx_ssl_recv() now matches ngx_unix_recv(),
which used to always reset c->read->ready to 0 when returning errors.

This fixes an infinite loop in unbuffered SSL proxying if writing to the
client is blocked and an SSL error happens (ticket #2418).

With this change, the fix for a similar issue in the stream module
(6868:ee3645078759), which used a different approach of explicitly
testing c->read->error instead, is no longer needed and was reverted.

3 years agoRemoved casts from ngx_memcmp() macro.
Maxim Dounin [Wed, 30 Nov 2022 15:01:53 +0000 (18:01 +0300)]
Removed casts from ngx_memcmp() macro.

Casts are believed to be not needed, since memcmp() has "const void *"
arguments since introduction of the "void" type in C89.  And on pre-C89
platforms nginx is unlikely to compile without warnings anyway, as there
are no casts in memcpy() and memmove() calls.

These casts were added in 1648:89a47f19b9ec without any details on why they
were added, and Igor does not remember details either.  The most plausible
explanation is that they were copied from ngx_strcmp() and were not really
needed even at that time.

Prodded by Alejandro Colomar.

3 years agoFixed alignment of ngx_memmove()/ngx_movemem() macro definitions.
Maxim Dounin [Wed, 30 Nov 2022 15:01:43 +0000 (18:01 +0300)]
Fixed alignment of ngx_memmove()/ngx_movemem() macro definitions.

3 years agoSSL: fixed debug logging of SSL_sendfile() return value.
Sergey Kandaurov [Thu, 24 Nov 2022 19:08:30 +0000 (23:08 +0400)]
SSL: fixed debug logging of SSL_sendfile() return value.

3 years agoFixed segfault when switching off master process during upgrade.
Maxim Dounin [Wed, 23 Nov 2022 20:48:53 +0000 (23:48 +0300)]
Fixed segfault when switching off master process during upgrade.

Binary upgrades are not supported without master process, but it is,
however, possible, that nginx running with master process is asked
to upgrade binary, and the configuration file as available on disk
at this time includes "master_process off;".

If this happens, listening sockets inherited from the previous binary
will have ls[i].previous set.  But the old cycle on initial process
startup, including startup after binary upgrade, is destroyed by
ngx_init_cycle() once configuration parsing is complete.  As a result,
an attempt to dereference ls[i].previous in ngx_event_process_init()
accesses already freed memory.

Fix is to avoid looking into ls[i].previous if the old cycle is already
freed.

With this change it is also no longer needed to clear ls[i].previous in
worker processes, so the relevant code was removed.

3 years agoDisabled cloning of sockets without master process (ticket #2403).
Maxim Dounin [Wed, 23 Nov 2022 20:12:04 +0000 (23:12 +0300)]
Disabled cloning of sockets without master process (ticket #2403).

Cloning of listening sockets for each worker process does not make sense
when working without master process, and causes some of the connections
not to be accepted if worker_processes is set to more than one and there
are listening sockets configured with the reuseport flag.  Fix is to
disable cloning when master process is disabled.

3 years agoFiltering duplicate addresses in listen (ticket #2400).
Maxim Dounin [Wed, 23 Nov 2022 14:30:08 +0000 (17:30 +0300)]
Filtering duplicate addresses in listen (ticket #2400).

Due to the glibc bug[1], getaddrinfo("localhost") with AI_ADDRCONFIG
on a typical host with glibc and without IPv6 returns two 127.0.0.1
addresses, and therefore "listen localhost:80;" used to result in
"duplicate ... address and port pair" after 4f9b72a229c1.

Fix is to explicitly filter out duplicate addresses returned during
resolution of a name.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=14969

3 years agoProcess events posted by ngx_close_idle_connections() immediately.
Roman Arutyunyan [Fri, 18 Nov 2022 15:31:38 +0000 (19:31 +0400)]
Process events posted by ngx_close_idle_connections() immediately.

Previously, if an event was posted by a read event handler, called by
ngx_close_idle_connections(), that event was not processed until the next
event loop iteration, which could happen after a timeout.

3 years agoSSI: handling of subrequests from other modules (ticket #1263).
Ciel Zhao [Mon, 21 Nov 2022 14:01:34 +0000 (17:01 +0300)]
SSI: handling of subrequests from other modules (ticket #1263).

As the SSI parser always uses the context from the main request for storing
variables and blocks, that context should always exist for subrequests using
SSI, even though the main request does not necessarily have SSI enabled.

However, `ngx_http_get_module_ctx(r->main, ...)` is getting NULL in such cases,
resulting in the worker crashing SIGSEGV when accessing its attributes.

This patch links the first initialized context to the main request, and
upgrades it only when main context is initialized.

3 years agoFixed PROXY protocol to use ngx_memcpy()/ngx_memcmp().
Maxim Dounin [Tue, 8 Nov 2022 09:48:21 +0000 (12:48 +0300)]
Fixed PROXY protocol to use ngx_memcpy()/ngx_memcmp().

3 years agoAdded logging to PROXY protocol write buffer check.
Maxim Dounin [Tue, 8 Nov 2022 09:48:19 +0000 (12:48 +0300)]
Added logging to PROXY protocol write buffer check.

The check is not expected to fail unless there is a bug in the calling
code.  But given the check is here, it should log an alert if it fails
instead of silently closing the connection.

3 years agoIncreased maximum read PROXY protocol header size.
Roman Arutyunyan [Wed, 2 Nov 2022 09:46:16 +0000 (13:46 +0400)]
Increased maximum read PROXY protocol header size.

Maximum size for reading the PROXY protocol header is increased to 4096 to
accommodate a bigger number of TLVs, which are supported since cca4c8a715de.

Maximum size for writing the PROXY protocol header is not changed since only
version 1 is currently supported.

3 years agoVersion bump.
Roman Arutyunyan [Thu, 3 Nov 2022 11:52:55 +0000 (15:52 +0400)]
Version bump.

3 years agorelease-1.23.2 tag
Maxim Dounin [Wed, 19 Oct 2022 07:56:21 +0000 (10:56 +0300)]
release-1.23.2 tag

3 years agonginx-1.23.2-RELEASE release-1.23.2
Maxim Dounin [Wed, 19 Oct 2022 07:56:20 +0000 (10:56 +0300)]
nginx-1.23.2-RELEASE

3 years agoMp4: disabled duplicate atoms.
Roman Arutyunyan [Wed, 19 Oct 2022 07:53:17 +0000 (10:53 +0300)]
Mp4: disabled duplicate atoms.

Most atoms should not appear more than once in a container.  Previously,
this was not enforced by the module, which could result in worker process
crash, memory corruption and disclosure.

3 years agoSSL: improved validation of ssl_session_cache and ssl_ocsp_cache.
Sergey Kandaurov [Mon, 17 Oct 2022 12:24:53 +0000 (16:24 +0400)]
SSL: improved validation of ssl_session_cache and ssl_ocsp_cache.

Now it properly detects invalid shared zone configuration with omitted size.
Previously it used to read outside of the buffer boundary.

Found with AddressSanitizer.

3 years agoSSL: removed cast not needed after 5ffd76a9ccf3.
Sergey Kandaurov [Thu, 13 Oct 2022 12:18:56 +0000 (16:18 +0400)]
SSL: removed cast not needed after 5ffd76a9ccf3.

3 years agoSSL: workaround for session timeout handling with TLSv1.3.
Maxim Dounin [Wed, 12 Oct 2022 17:14:57 +0000 (20:14 +0300)]
SSL: workaround for session timeout handling with TLSv1.3.

OpenSSL with TLSv1.3 updates the session creation time on session
resumption and keeps the session timeout unmodified, making it possible
to maintain the session forever, bypassing client certificate expiration
and revocation.  To make sure session timeouts are actually used, we
now update the session creation time and reduce the session timeout
accordingly.

BoringSSL with TLSv1.3 ignores configured session timeouts and uses a
hardcoded timeout instead, 7 days.  So we update session timeout to
the configured value as soon as a session is created.

3 years agoSSL: optimized rotation of session ticket keys.
Maxim Dounin [Wed, 12 Oct 2022 17:14:55 +0000 (20:14 +0300)]
SSL: optimized rotation of session ticket keys.

Instead of syncing keys with shared memory on each ticket operation,
the code now does this only when the worker is going to change expiration
of the current key, or going to switch to a new key: that is, usually
at most once per second.

To do so without races, the code maintains 3 keys: current, previous,
and next.  If a worker will switch to the next key earlier, other workers
will still be able to decrypt new tickets, since they will be encrypted
with the next key.

3 years agoSSL: automatic rotation of session ticket keys.
Maxim Dounin [Wed, 12 Oct 2022 17:14:53 +0000 (20:14 +0300)]
SSL: automatic rotation of session ticket keys.

As long as ssl_session_cache in shared memory is configured, session ticket
keys are now automatically generated in shared memory, and rotated
periodically.  This can be beneficial from forward secrecy point of view,
and also avoids increased CPU usage after configuration reloads.

This also helps BoringSSL to properly resume sessions in configurations
with multiple worker processes and no ssl_session_ticket_key directives,
as BoringSSL tries to automatically rotate session ticket keys and does
this independently in different worker processes, thus breaking session
resumption between worker processes.

3 years agoSSL: shorter debug messages about session tickets.
Maxim Dounin [Wed, 12 Oct 2022 17:14:51 +0000 (20:14 +0300)]
SSL: shorter debug messages about session tickets.

3 years agoSSL: renamed session ticket key functions and data index.
Maxim Dounin [Wed, 12 Oct 2022 17:14:49 +0000 (20:14 +0300)]
SSL: renamed session ticket key functions and data index.

Previously used names are way too long, renamed to simplify writing code.

3 years agoSSL: renamed session ticket key type.
Maxim Dounin [Wed, 12 Oct 2022 17:14:47 +0000 (20:14 +0300)]
SSL: renamed session ticket key type.

The ngx_ssl_session_ticket_key_t is way too long, renamed to
ngx_ssl_ticket_key_t to simplify writing code.

3 years agoSSL: style.
Maxim Dounin [Wed, 12 Oct 2022 17:14:45 +0000 (20:14 +0300)]
SSL: style.

Runtime OCSP functions separated from configuration ones.

3 years agoSSL: explicit clearing of expired sessions.
Maxim Dounin [Wed, 12 Oct 2022 17:14:43 +0000 (20:14 +0300)]
SSL: explicit clearing of expired sessions.

This reduces lifetime of session keying material in server's memory, and
therefore can be beneficial from forward secrecy point of view.

3 years agoSSL: single allocation in session cache on 32-bit platforms.
Maxim Dounin [Wed, 12 Oct 2022 17:14:40 +0000 (20:14 +0300)]
SSL: single allocation in session cache on 32-bit platforms.

Given the present typical SSL session sizes, on 32-bit platforms it is
now beneficial to store all data in a single allocation, since rbtree
node + session id + ASN1 representation of a session takes 256 bytes of
shared memory (36 + 32 + 150 = about 218 bytes plus SNI server name).

Storing all data in a single allocation is beneficial for SNI names up to
about 40 characters long and makes it possible to store about 4000 sessions
in one megabyte (instead of about 3000 sessions now).  This also slightly
simplifies the code.

3 years agoSSL: explicit session id length checking.
Maxim Dounin [Wed, 12 Oct 2022 17:14:39 +0000 (20:14 +0300)]
SSL: explicit session id length checking.

Session ids are not expected to be longer than 32 bytes, but this is
theoretically possible with TLSv1.3, where session ids are essentially
arbitrary and sent as session tickets.  Since on 64-bit platforms we
use fixed 32-byte buffer for session ids, added an explicit length check
to make sure the buffer is large enough.

3 years agoSSL: updated comment about session sizes.
Maxim Dounin [Wed, 12 Oct 2022 17:14:37 +0000 (20:14 +0300)]
SSL: updated comment about session sizes.

Previous numbers are somewhat outdated, typical ASN1 representations of
sessions are slightly bigger now.

3 years agoSSL: reduced logging of session cache failures (ticket #621).
Maxim Dounin [Wed, 12 Oct 2022 17:14:36 +0000 (20:14 +0300)]
SSL: reduced logging of session cache failures (ticket #621).

Session cache allocations might fail as long as the new session is different
in size from the one least recently used (and freed when the first allocation
fails).  In particular, it might not be possible to allocate space for
sessions with client certificates, since they are noticeably bigger than
normal sessions.

To ensure such allocation failures won't clutter logs, logging level changed
to "warn", and logging is now limited to at most one warning per second.

3 years agoSSL: disabled saving tickets to session cache.
Maxim Dounin [Wed, 12 Oct 2022 17:14:34 +0000 (20:14 +0300)]
SSL: disabled saving tickets to session cache.

OpenSSL tries to save TLSv1.3 sessions into session cache even when using
tickets for stateless session resumption, "because some applications just
want to know about the creation of a session".  To avoid trashing session
cache with useless data, we do not save such sessions now.

3 years agoAdded type cast to ngx_proxy_protocol_parse_uint16().
Roman Arutyunyan [Tue, 27 Sep 2022 07:31:16 +0000 (11:31 +0400)]
Added type cast to ngx_proxy_protocol_parse_uint16().

The cast is added to make ngx_proxy_protocol_parse_uint16() similar to
ngx_proxy_protocol_parse_uint32().

3 years agoPROXY protocol v2 TLV variables.
Roman Arutyunyan [Wed, 12 Oct 2022 12:58:16 +0000 (16:58 +0400)]
PROXY protocol v2 TLV variables.

The variables have prefix $proxy_protocol_tlv_ and are accessible by name
and by type.  Examples are: $proxy_protocol_tlv_0x01, $proxy_protocol_tlv_alpn.

3 years agoLog only the first line of user input on PROXY protocol v1 error.
Roman Arutyunyan [Mon, 10 Oct 2022 09:57:31 +0000 (13:57 +0400)]
Log only the first line of user input on PROXY protocol v1 error.

Previously, all received user input was logged.  If a multi-line text was
received from client and logged, it could reduce log readability and also make
it harder to parse nginx log by scripts.  The change brings to PROXY protocol
the same behavior that exists for HTTP request line in
ngx_http_log_error_handler().

3 years agoSSL: silenced GCC warnings when building with BoringSSL.
Sergey Kandaurov [Thu, 8 Sep 2022 09:53:49 +0000 (13:53 +0400)]
SSL: silenced GCC warnings when building with BoringSSL.

BoringSSL uses macro stub for SSL_CTX_set_ecdh_auto that expands to 1,
which triggers -Wunused-value "statement with no effect" warnings.

3 years agoWin32: disabled threads support in OpenSSL builds.
Maxim Dounin [Tue, 6 Sep 2022 21:47:31 +0000 (00:47 +0300)]
Win32: disabled threads support in OpenSSL builds.

Threads are disabled during UNIX builds (see b329c0ab1a48), and also not
needed for Windows builds.

This used to be the default before OpenSSL 1.1.0.

3 years agoWin32: fixed build on Windows with OpenSSL 3.0.x (ticket #2379).
Maxim Dounin [Tue, 6 Sep 2022 21:47:17 +0000 (00:47 +0300)]
Win32: fixed build on Windows with OpenSSL 3.0.x (ticket #2379).

SSL_sendfile() expects integer file descriptor as an argument, but nginx
uses OS file handles (HANDLE) to work with files on Windows, and passing
HANDLE instead of an integer correctly results in build failure.  Since
SSL_sendfile() is not expected to work on Windows anyway, the code is now
disabled on Windows with appropriate compile-time checks.

3 years agoWin32: disabled C4306 warnings with MSVC.
Maxim Dounin [Tue, 6 Sep 2022 21:47:07 +0000 (00:47 +0300)]
Win32: disabled C4306 warnings with MSVC.

Multiple C4306 warnings (conversion from 'type1' to 'type2' of greater size)
appear during 64-bit compilation with MSVC 2010 (and older) due to extensively
used constructs like "(void *) -1", so they were disabled.

In newer MSVC versions C4306 warnings were replaced with C4312 ones, and
these are not generated for such trivial type casts.

3 years agoWin32: removed misleading comment about warnings being disabled.
Maxim Dounin [Tue, 6 Sep 2022 21:47:02 +0000 (00:47 +0300)]
Win32: removed misleading comment about warnings being disabled.

Warnings being disabled are not only from the "-W4" level since e4590dfd97ff.

3 years agoSSL: fixed incorrect usage of #if instead of #ifdef.
Maxim Dounin [Tue, 6 Sep 2022 21:44:10 +0000 (00:44 +0300)]
SSL: fixed incorrect usage of #if instead of #ifdef.

In 2014ed60f17f, "#if SSL_CTRL_SET_ECDH_AUTO" test was incorrectly used
instead of "#ifdef SSL_CTRL_SET_ECDH_AUTO".  There is no practical
difference, since SSL_CTRL_SET_ECDH_AUTO evaluates to a non-zero numeric
value when defined, but anyway it's better to correctly test if the value
is defined.

3 years agoEvents: fixed style and wrong error handling in the iocp module.
Maxim Dounin [Tue, 6 Sep 2022 21:43:51 +0000 (00:43 +0300)]
Events: fixed style and wrong error handling in the iocp module.

3 years agoSSL: logging level of "bad record type" errors.
Murilo Andrade [Tue, 9 Aug 2022 20:13:46 +0000 (17:13 -0300)]
SSL: logging level of "bad record type" errors.

The SSL_R_BAD_RECORD_TYPE ("bad record type") errors are reported by
OpenSSL 1.1.1 or newer when using TLSv1.3 if the client sends a record
with unknown or unexpected type.  These errors are now logged at the
"info" level.

3 years agoVersion bump.
Maxim Dounin [Mon, 29 Aug 2022 22:52:51 +0000 (01:52 +0300)]
Version bump.

3 years agorelease-1.23.1 tag
Maxim Dounin [Tue, 19 Jul 2022 14:05:27 +0000 (17:05 +0300)]
release-1.23.1 tag

3 years agonginx-1.23.1-RELEASE release-1.23.1
Maxim Dounin [Tue, 19 Jul 2022 14:05:27 +0000 (17:05 +0300)]
nginx-1.23.1-RELEASE

3 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 19 Jul 2022 14:03:30 +0000 (17:03 +0300)]
Updated OpenSSL used for win32 builds.

3 years agoEvents: fixed EPOLLRDHUP with FIONREAD (ticket #2367).
Maxim Dounin [Fri, 15 Jul 2022 12:19:32 +0000 (15:19 +0300)]
Events: fixed EPOLLRDHUP with FIONREAD (ticket #2367).

When reading exactly rev->available bytes, rev->available might become 0
after FIONREAD usage introduction in efd71d49bde0.  On the next call of
ngx_readv_chain() on systems with EPOLLRDHUP this resulted in return without
any actions, that is, with rev->ready set, and this in turn resulted in no
timers set in event pipe, leading to socket leaks.

Fix is to reset rev->ready in ngx_readv_chain() when returning due to
rev->available being 0 with EPOLLRDHUP, much like it is already done in
ngx_unix_recv().  This ensures that if rev->available will become 0, on
systems with EPOLLRDHUP support appropriate EPOLLRDHUP-specific handling
will happen on the next ngx_readv_chain() call.

While here, also synced ngx_readv_chain() to match ngx_unix_recv() and
reset rev->ready when returning due to rev->available being 0 with kqueue.
This is mostly cosmetic change, as rev->ready is anyway reset when
rev->available is set to 0.

3 years agoRange filter: clearing of pre-existing Content-Range headers.
Maxim Dounin [Fri, 15 Jul 2022 04:01:44 +0000 (07:01 +0300)]
Range filter: clearing of pre-existing Content-Range headers.

Some servers might emit Content-Range header on 200 responses, and this
does not seem to contradict RFC 9110: as per RFC 9110, the Content-Range
header has no meaning for status codes other than 206 and 416.  Previously
this resulted in duplicate Content-Range headers in nginx responses handled
by the range filter.  Fix is to clear pre-existing headers.

3 years agoResolver: fixed memory leak for the "ipv4=off" case.
Sergey Kandaurov [Thu, 14 Jul 2022 17:26:54 +0000 (21:26 +0400)]
Resolver: fixed memory leak for the "ipv4=off" case.

This change partially reverts 2a77754cd9fe to properly free rn->query.

Found by Coverity (CID 1507244).

3 years agoThe "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov [Tue, 12 Jul 2022 17:44:02 +0000 (21:44 +0400)]
The "ipv4=" parameter of the "resolver" directive.

When set to "off", only IPv6 addresses will be resolved, and no
A queries are ever sent (ticket #2196).

3 years agoSSL: logging levels of various errors added in OpenSSL 1.1.1.
Maxim Dounin [Tue, 12 Jul 2022 12:55:22 +0000 (15:55 +0300)]
SSL: logging levels of various errors added in OpenSSL 1.1.1.

Starting with OpenSSL 1.1.1, various additional errors can be reported
by OpenSSL in case of client-related issues, most notably during TLSv1.3
handshakes.  In particular, SSL_R_BAD_KEY_SHARE ("bad key share"),
SSL_R_BAD_EXTENSION ("bad extension"), SSL_R_BAD_CIPHER ("bad cipher"),
SSL_R_BAD_ECPOINT ("bad ecpoint").  These are now logged at the "info"
level.

3 years agoUpstream: optimized use of SSL contexts (ticket #1234).
Maxim Dounin [Tue, 28 Jun 2022 23:47:45 +0000 (02:47 +0300)]
Upstream: optimized use of SSL contexts (ticket #1234).

To ensure optimal use of memory, SSL contexts for proxying are now
inherited from previous levels as long as relevant proxy_ssl_* directives
are not redefined.

Further, when no proxy_ssl_* directives are redefined in a server block,
we now preserve plcf->upstream.ssl in the "http" section configuration
to inherit it to all servers.

Similar changes made in uwsgi, grpc, and stream proxy.

3 years agoVersion bump.
Maxim Dounin [Tue, 28 Jun 2022 23:47:38 +0000 (02:47 +0300)]
Version bump.

3 years agorelease-1.23.0 tag
Maxim Dounin [Tue, 21 Jun 2022 14:25:37 +0000 (17:25 +0300)]
release-1.23.0 tag

3 years agonginx-1.23.0-RELEASE release-1.23.0
Maxim Dounin [Tue, 21 Jun 2022 14:25:36 +0000 (17:25 +0300)]
nginx-1.23.0-RELEASE

3 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 21 Jun 2022 14:09:34 +0000 (17:09 +0300)]
Updated OpenSSL used for win32 builds.

3 years agoMisc: win32 sources now preserved in release tarballs.
Maxim Dounin [Mon, 20 Jun 2022 16:30:50 +0000 (19:30 +0300)]
Misc: win32 sources now preserved in release tarballs.

This makes it possible to build nginx under Windows from release tarballs
instead of using source code repository.

3 years agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Sat, 18 Jun 2022 12:54:40 +0000 (15:54 +0300)]
Contrib: vim syntax, update core and 3rd party module directives.

List of 3rd party modules github repositories are obtained from
https://github.com/freebsd/freebsd-ports/blob/main/www/nginx-devel/Makefile.extmod

3 years agoPerl: removed unused variables, forgotten in ef6a3a99a81a.
Sergey Kandaurov [Tue, 14 Jun 2022 06:39:58 +0000 (10:39 +0400)]
Perl: removed unused variables, forgotten in ef6a3a99a81a.

3 years agoResolver: make TCP write timer event cancelable.
Aleksei Bavshin [Thu, 2 Jun 2022 03:17:23 +0000 (20:17 -0700)]
Resolver: make TCP write timer event cancelable.

Similar to 70e65bf8dfd7, the change is made to ensure that the ability to
cancel resolver tasks is fully controlled by the caller.  As mentioned in the
referenced commit, it is safe to make this timer cancelable because resolve
tasks can have their own timeouts that are not cancelable.

The scenario where this may become a problem is a periodic background resolve
task (not tied to a specific request or a client connection), which receives a
response with short TTL, large enough to warrant fallback to a TCP query.
With each event loop wakeup, we either have a previously set write timer
instance or schedule a new one.  The non-cancelable write timer can delay or
block graceful shutdown of a worker even if the ngx_resolver_ctx_t->cancelable
flag is set by the API user, and there are no other tasks or connections.

We use the resolver API in this way to maintain the list of upstream server
addresses specified with the 'resolve' parameter, and there could be third-party
modules implementing similar logic.

3 years agoStream: don't flush empty buffers created for read errors.
Aleksei Bavshin [Mon, 23 May 2022 18:29:44 +0000 (11:29 -0700)]
Stream: don't flush empty buffers created for read errors.

When we generate the last_buf buffer for an UDP upstream recv error, it does
not contain any data from the wire. ngx_stream_write_filter attempts to forward
it anyways, which is incorrect (e.g., UDP upstream ECONNREFUSED will be
translated to an empty packet).

This happens because we mark the buffer as both 'flush' and 'last_buf', and
ngx_stream_write_filter has special handling for flush with certain types of
connections (see d127837c714f32b0ba4855a6).  The flags are meant to be
mutually exclusive, so the fix is to ensure that flush and last_buf are not set
at the same time.

Reproduction:

stream {
    upstream unreachable {
        server     127.0.0.1:8880;
    }
    server {
        listen     127.0.0.1:8998 udp;
        proxy_pass unreachable;
    }
}

1 0.000000000    127.0.0.1 → 127.0.0.1    UDP 47 45588 → 8998 Len=5
2 0.000166300    127.0.0.1 → 127.0.0.1    UDP 47 51149 → 8880 Len=5
3 0.000172600    127.0.0.1 → 127.0.0.1    ICMP 75 Destination unreachable (Port
unreachable)
4 0.000202400    127.0.0.1 → 127.0.0.1    UDP 42 8998 → 45588 Len=0

Fixes d127837c714f.

3 years agoMp4: fixed potential overflow in ngx_http_mp4_crop_stts_data().
Maxim Dounin [Tue, 7 Jun 2022 18:58:52 +0000 (21:58 +0300)]
Mp4: fixed potential overflow in ngx_http_mp4_crop_stts_data().

Both "count" and "duration" variables are 32-bit, so their product might
potentially overflow.  It is used to reduce 64-bit start_time variable,
and with very large start_time this can result in incorrect seeking.

Found by Coverity (CID 1499904).

3 years agoUpstream: handling of certificates specified as an empty string.
Sergey Kandaurov [Tue, 7 Jun 2022 16:08:57 +0000 (20:08 +0400)]
Upstream: handling of certificates specified as an empty string.

Now, if the directive is given an empty string, such configuration cancels
loading of certificates, in particular, if they would be otherwise inherited
from the previous level.  This restores previous behaviour, before variables
support in certificates was introduced (3ab8e1e2f0f7).

3 years agoUpstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin [Mon, 6 Jun 2022 21:07:12 +0000 (00:07 +0300)]
Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.

Previously, if caching was disabled due to Expires in the past, nginx
failed to cache the response even if it was cacheable as per subsequently
parsed Cache-Control header (ticket #964).

Similarly, if caching was disabled due to Expires in the past,
"Cache-Control: no-cache" or "Cache-Control: max-age=0", caching was not
used if it was cacheable as per subsequently parsed X-Accel-Expires header.

Fix is to avoid disabling caching immediately after parsing Expires in
the past or Cache-Control, but rather set flags which are later checked by
ngx_http_upstream_process_headers() (and cleared by "Cache-Control: max-age"
and X-Accel-Expires).

Additionally, now X-Accel-Expires does not prevent parsing of cache control
extensions, notably stale-while-revalidate and stale-if-error.  This
ensures that order of the X-Accel-Expires and Cache-Control headers is not
important.

Prodded by Vadim Fedorenko and Yugo Horie.

3 years agoUpstream: fixed build without http cache (broken by cd73509f21e2).
Maxim Dounin [Mon, 30 May 2022 21:14:11 +0000 (00:14 +0300)]
Upstream: fixed build without http cache (broken by cd73509f21e2).

3 years agoHeaders filter: improved memory allocation error handling.
Maxim Dounin [Mon, 30 May 2022 18:25:57 +0000 (21:25 +0300)]
Headers filter: improved memory allocation error handling.

3 years agoMultiple WWW-Authenticate headers with "satisfy any;".
Maxim Dounin [Mon, 30 May 2022 18:25:56 +0000 (21:25 +0300)]
Multiple WWW-Authenticate headers with "satisfy any;".

If a module adds multiple WWW-Authenticate headers (ticket #485) to the
response, linked in r->headers_out.www_authenticate, all headers are now
cleared if another module later allows access.

This change is a nop for standard modules, since the only access module which
can add multiple WWW-Authenticate headers is the auth request module, and
it is checked after other standard access modules.  Though this might
affect some third party access modules.

Note that if a 3rd party module adds a single WWW-Authenticate header
and not yet modified to set the header's next pointer to NULL, attempt to
clear such a header with this change will result in a segmentation fault.

3 years agoAuth request: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin [Mon, 30 May 2022 18:25:54 +0000 (21:25 +0300)]
Auth request: multiple WWW-Authenticate headers (ticket #485).

When using auth_request with an upstream server which returns 401
(Unauthorized), multiple WWW-Authenticate headers from the upstream server
response are now properly copied to the response.

3 years agoUpstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin [Mon, 30 May 2022 18:25:53 +0000 (21:25 +0300)]
Upstream: multiple WWW-Authenticate headers (ticket #485).

When using proxy_intercept_errors and an error page for error 401
(Unauthorized), multiple WWW-Authenticate headers from the upstream server
response are now properly copied to the response.