]> git.feebdaed.xyz Git - 0xmirror/nginx.git/log
0xmirror/nginx.git
5 months agoConfigure: set NGX_KQUEUE_UDATA_T at compile time.
Sergey Kandaurov [Thu, 10 Jul 2025 12:30:35 +0000 (16:30 +0400)]
Configure: set NGX_KQUEUE_UDATA_T at compile time.

The NGX_KQUEUE_UDATA_T macro is used to compensate the incompatible
kqueue() API in NetBSD, it doesn't really belong to feature tests.

The change limits the macro visibility to the kqueue event module.
Moving from autotests also simplifies testing a particular NetBSD
version as seen in a subsequent change.

5 months agoEvents: fixed -Wzero-as-null-pointer-constant warnings in kqueue.
Sergey Kandaurov [Tue, 8 Jul 2025 18:45:33 +0000 (22:45 +0400)]
Events: fixed -Wzero-as-null-pointer-constant warnings in kqueue.

The kevent udata field is special in that we maintain compatibility
with NetBSD versions that predate using the "void *" type.

The fix is to cast to intermediate uintptr_t that is casted back to
"void *" where appropriate.

5 months agoSSL: fixed testing OPENSSL_VERSION_NUMBER for OpenSSL 3.0+.
Sergey Kandaurov [Tue, 8 Jul 2025 14:07:04 +0000 (18:07 +0400)]
SSL: fixed testing OPENSSL_VERSION_NUMBER for OpenSSL 3.0+.

Prior to OpenSSL 3.0, OPENSSL_VERSION_NUMBER used the following format:

MNNFFPPS: major minor fix patch status

Where the status nibble (S) has 0+ for development and f for release.

The format was changed in OpenSSL 3.0.0, where it is always zero:

MNN00PP0: major minor patch

5 months agoSSL: SSL_group_to_name() compatibility macro.
Sergey Kandaurov [Tue, 8 Jul 2025 13:59:50 +0000 (17:59 +0400)]
SSL: SSL_group_to_name() compatibility macro.

No functional changes.

5 months agoQUIC: adjusted OpenSSL 3.5 QUIC API feature test.
Sergey Kandaurov [Sun, 22 Jun 2025 16:40:05 +0000 (20:40 +0400)]
QUIC: adjusted OpenSSL 3.5 QUIC API feature test.

A bug with the "quic_transport_parameters" extension and SNI described
in cedb855d7 is now fixed in the OpenSSL 3.5.1 release, as requested
in https://github.com/openssl/openssl/pull/27706.

6 months agoWin32: fixed PCRE license for nginx/Windows zip.
Sergey Kandaurov [Tue, 24 Jun 2025 18:46:00 +0000 (22:46 +0400)]
Win32: fixed PCRE license for nginx/Windows zip.

6 months agoVersion bump.
Sergey Kandaurov [Tue, 24 Jun 2025 18:45:32 +0000 (22:45 +0400)]
Version bump.

6 months agonginx-1.29.0-RELEASE
Sergey Kandaurov [Tue, 24 Jun 2025 12:40:21 +0000 (16:40 +0400)]
nginx-1.29.0-RELEASE

6 months agoUpdated OpenSSL and PCRE used for win32 builds.
Sergey Kandaurov [Tue, 24 Jun 2025 11:20:27 +0000 (15:20 +0400)]
Updated OpenSSL and PCRE used for win32 builds.

6 months agoWin32: skip OpenSSL dependency generation to conserve time.
Sergey Kandaurov [Tue, 24 Jun 2025 12:42:20 +0000 (16:42 +0400)]
Win32: skip OpenSSL dependency generation to conserve time.

Disabling the build dependency feature is safe assuming that
nginx/Windows release zip is always built from a clean tree.
This allows to speed up total build time by around 40%.

As it may not be suitable in general, the option resides here
and not in configure.

6 months agoQUIC: disabled OpenSSL 3.5 QUIC API support by default.
Sergey Kandaurov [Tue, 27 May 2025 17:56:40 +0000 (21:56 +0400)]
QUIC: disabled OpenSSL 3.5 QUIC API support by default.

In OpenSSL 3.5.0, the "quic_transport_parameters" extension set
internally by the QUIC API is cleared on the SSL context switch,
which disables sending QUIC transport parameters if switching to
a different server block on SNI.  See the initial report in [1].

This is fixed post OpenSSL 3.5.0 [2].  The fix is anticipated in
OpenSSL 3.5.1, which has not been released yet.  When building
with OpenSSL 3.5, OpenSSL compat layer is now used by default.
The OpenSSL 3.5 QUIC API support can be switched back using
--with-cc-opt='-DNGX_QUIC_OPENSSL_API=1'.

[1] https://github.com/nginx/nginx/issues/711
[2] https://github.com/openssl/openssl/commit/45bd3c3798

6 months agoUpstream: fixed reinit request with gRPC and Early Hints.
Sergey Kandaurov [Mon, 23 Jun 2025 10:55:32 +0000 (14:55 +0400)]
Upstream: fixed reinit request with gRPC and Early Hints.

The gRPC module context has connection specific state, which can be lost
after request reinitialization when it comes to processing early hints.

The fix is to do only a portion of u->reinit_request() implementation
required after processing early hints, now inlined in modules.

Now NGX_HTTP_UPSTREAM_EARLY_HINTS is returned from u->process_header()
for early hints.  When reading a cached response, this code is mapped
to NGX_HTTP_UPSTREAM_INVALID_HEADER to indicate invalid header format.

6 months agoUse NULL instead of 0 for null pointer constant.
Andrew Clayton [Wed, 21 May 2025 21:30:20 +0000 (22:30 +0100)]
Use NULL instead of 0 for null pointer constant.

There were a few random places where 0 was being used as a null pointer
constant.

We have a NULL macro for this very purpose, use it.

There is also some interest in actually deprecating the use of 0 as a
null pointer constant in C.

This was found with -Wzero-as-null-pointer-constant which was enabled
for C in GCC 15 (not enabled with Wall or Wextra... yet).

Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>

6 months agoUse NGX_CONF_OK in some function return checks.
Andrew Clayton [Wed, 21 May 2025 21:19:32 +0000 (22:19 +0100)]
Use NGX_CONF_OK in some function return checks.

The functions ngx_http_merge_types() & ngx_conf_merge_path_value()
return either NGX_CONF_OK aka NULL aka ((void *)0) (probably) or
NGX_CONF_ERROR aka ((void *)-1).

They don't return an integer constant which is what NGX_OK aka (0) is.

Lets use the right thing in the function return check.

This was found with -Wzero-as-null-pointer-constant which was enabled
for C in GCC 15 (not enabled with Wall or Wextra... yet).

Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>

6 months agoHTTP/3: indexed field line encoding for "103 Early Hints".
Sergey Kandaurov [Fri, 20 Jun 2025 14:46:17 +0000 (18:46 +0400)]
HTTP/3: indexed field line encoding for "103 Early Hints".

6 months agoUpstream: early hints support.
Roman Arutyunyan [Fri, 15 Nov 2024 04:23:53 +0000 (08:23 +0400)]
Upstream: early hints support.

The change implements processing upstream early hints response in
ngx_http_proxy_module and ngx_http_grpc_module.  A new directive
"early_hints" enables sending early hints to the client.  By default,
sending early hints is disabled.

Example:

    map $http_sec_fetch_mode $early_hints {
        navigate $http2$http3;
    }

    early_hints $early_hints;

    proxy_pass http://example.com;

6 months agoHTTP/2: added function declaration.
Roman Arutyunyan [Wed, 18 Jun 2025 15:48:19 +0000 (19:48 +0400)]
HTTP/2: added function declaration.

7 months agoCore: added support for TCP keepalive parameters on macOS.
Sergey Kandaurov [Mon, 26 May 2025 12:11:36 +0000 (16:11 +0400)]
Core: added support for TCP keepalive parameters on macOS.

The support first appeared in OS X Mavericks 10.9 and documented since
OS X Yosemite 10.10.

It has a subtle implementation difference from other operating systems
in that the TCP_KEEPALIVE socket option (used in place of TCP_KEEPIDLE)
isn't inherited from a listening socket to an accepted socket.

An apparent reason for this behaviour is that it might be preserved for
the sake of backward compatibility.  The TCP_KEEPALIVE socket option is
not inherited since appearance in OS X Panther 10.3, which long predates
two other TCP_KEEPINTVL and TCP_KEEPCNT socket options.

Thanks to Andy Pan for initial work.

7 months agoSSL: disabled UI console prompts from worker processes.
Aleksei Bavshin [Fri, 17 Jan 2025 20:24:08 +0000 (12:24 -0800)]
SSL: disabled UI console prompts from worker processes.

Certain providers may attempt to reload the key on the first use after a
fork.  Such attempt would require re-prompting the pin, and this time we
are not able to pass the password callback.

While it is addressable with configuration for a specific provider, it would
be prudent to ensure that no such prompts could block worker processes by
setting the default UI method.

UI_null() first appeared in 1.1.1 along with the OSSL_STORE, so it is safe
to assume the same set of guards.

7 months agoSSL: support loading keys via OSSL_STORE.
Aleksei Bavshin [Tue, 17 Dec 2024 01:56:45 +0000 (17:56 -0800)]
SSL: support loading keys via OSSL_STORE.

A new "store:..." prefix for the "ssl_certificate_key" directive allows
loading keys via the OSSL_STORE API.

The change is required to support hardware backed keys in OpenSSL 3.x using
the new "provider(7ossl)" modules, such as "pkcs11-provider".  While the
engine API is present in 3.x, some operating systems (notably, RHEL10)
have already disabled it in their builds of OpenSSL.

Related: https://trac.nginx.org/nginx/ticket/2449

7 months agoQUIC: using QUIC API introduced in OpenSSL 3.5.
Sergey Kandaurov [Thu, 13 Feb 2025 13:00:56 +0000 (17:00 +0400)]
QUIC: using QUIC API introduced in OpenSSL 3.5.

Similarly to the QUIC API originated in BoringSSL, this API allows
to register custom TLS callbacks for an external QUIC implementation.
See the SSL_set_quic_tls_cbs manual page for details.

Due to a different approach used in OpenSSL 3.5, handling of CRYPTO
frames was streamlined to always write an incoming CRYPTO buffer to
the crypto context.  Using SSL_provide_quic_data(), this results in
transient allocation of chain links and buffers for CRYPTO frames
received in order.  Testing didn't reveal performance degradation of
QUIC handshakes, https://github.com/nginx/nginx/pull/646 provides
specific results.

7 months agoQUIC: better approach for premature handshake completion.
Sergey Kandaurov [Thu, 15 May 2025 21:10:11 +0000 (01:10 +0400)]
QUIC: better approach for premature handshake completion.

Using SSL_in_init() to inspect a handshake state was replaced with
SSL_is_init_finished().  This represents a more complete fix to the
BoringSSL issue addressed in 22671b37e.

This provides awareness of the early data handshake state when using
OpenSSL 3.5 TLS callbacks in 0-RTT enabled configurations, which, in
particular, is used to avoid premature completion of the initial TLS
handshake, before required client handshake messages are received.

This is a non-functional change when using BoringSSL.  It supersedes
testing non-positive SSL_do_handshake() results in all supported SSL
libraries, hence simplified.

In preparation for using OpenSSL 3.5 TLS callbacks.

7 months agoQUIC: ssl_encryption_level_t abstraction layer.
Sergey Kandaurov [Tue, 6 May 2025 11:58:17 +0000 (15:58 +0400)]
QUIC: ssl_encryption_level_t abstraction layer.

Encryption level values are decoupled from ssl_encryption_level_t,
which is now limited to BoringSSL QUIC callbacks, with mappings
provided.  Although the values match, this provides a technically
safe approach, in particular, to access protection level sized arrays.

In preparation for using OpenSSL 3.5 TLS callbacks.

7 months agoQUIC: factored out SSL_provide_quic_data() to the helper function.
Sergey Kandaurov [Wed, 21 May 2025 16:32:48 +0000 (20:32 +0400)]
QUIC: factored out SSL_provide_quic_data() to the helper function.

It is now called from ngx_quic_handle_crypto_frame(), prior to proceeding
with the handshake.  With this logic removed, the handshake function is
renamed to ngx_quic_handshake() to better match ngx_ssl_handshake().

7 months agoQUIC: defined SSL API macros in a single place.
Sergey Kandaurov [Tue, 20 May 2025 23:54:45 +0000 (03:54 +0400)]
QUIC: defined SSL API macros in a single place.

All definitions now set in ngx_event_quic.h, this includes moving
NGX_QUIC_OPENSSL_COMPAT from autotests to compile time.  Further,
to improve code readability, a new NGX_QUIC_QUICTLS_API macro is
used for QuicTLS that provides old BoringSSL QUIC API.

7 months agoQUIC: logging missing mandatory TLS extensions only once.
Sergey Kandaurov [Tue, 6 May 2025 14:57:01 +0000 (18:57 +0400)]
QUIC: logging missing mandatory TLS extensions only once.

Previously, they might be logged on every add_handshake_data
callback invocation when using OpenSSL compat layer and processing
coalesced handshake messages.

Further, the ALPN error message is adjusted to signal the missing
extension.  Possible reasons were previously narrowed down with
ebb6f7d65 changes in the ALPN callback that is invoked earlier in
the handshake.

7 months agoQUIC: reset qc->error to zero again.
Sergey Kandaurov [Wed, 14 May 2025 19:33:00 +0000 (23:33 +0400)]
QUIC: reset qc->error to zero again.

Following the previous change that removed posting a close event
in OpenSSL compat layer, now ngx_quic_close_connection() is always
called on error path with either NGX_ERROR or qc->error set.

This allows to remove a special value -1 served as a missing error,
which simplifies the code.  Partially reverts d3fb12d77.

Also, this improves handling of the draining connection state, which
consists of posting a close event with NGX_OK and no qc->error set,
where it was previously converted to NGX_QUIC_ERR_INTERNAL_ERROR.
Notably, this is rather a cosmetic fix, because drained connections
do not send any packets including CONNECTION_CLOSE, and qc->error
is not otherwise used.

7 months agoQUIC: adjusted handling of callback errors.
Sergey Kandaurov [Tue, 13 May 2025 16:12:10 +0000 (20:12 +0400)]
QUIC: adjusted handling of callback errors.

Changed handshake callbacks to always return success.  This allows to avoid
logging SSL_do_handshake() errors with empty or cryptic "internal error"
OpenSSL error messages at the inappropriate "crit" log level.

Further, connections with failed callbacks are closed now right away when
using OpenSSL compat layer.  This change supersedes and reverts c37fdcdd1,
with the conditions to check callbacks invocation kept to slightly improve
code readability of control flow; they are optimized out in the resulting
assembly code.

7 months agoQUIC: logging of SSL library errors.
Sergey Kandaurov [Wed, 21 May 2025 15:55:31 +0000 (19:55 +0400)]
QUIC: logging of SSL library errors.

Logging level for such errors, which should not normally happen,
is changed to NGX_LOG_ALERT, and ngx_log_error() is replaced with
ngx_ssl_error() for consistency with the rest of the code.

7 months agoQUIC: logging level of handshake errors.
Sergey Kandaurov [Tue, 6 May 2025 11:09:28 +0000 (15:09 +0400)]
QUIC: logging level of handshake errors.

Various errors reported by SSL_do_handshake() are now logged at the
"info" or "crit" level, akin to handshakes on regular TCP connections.

7 months agoQUIC: removed ALPN feature test.
Sergey Kandaurov [Tue, 6 May 2025 11:17:44 +0000 (15:17 +0400)]
QUIC: removed ALPN feature test.

ALPN support is present in all libraries that have QUIC support,
it is safe to compile it unconditionally.

7 months agoQUIC: removed excessive casts for ngx_ssl_get_connection().
Sergey Kandaurov [Tue, 6 May 2025 11:53:49 +0000 (15:53 +0400)]
QUIC: removed excessive casts for ngx_ssl_get_connection().

They were blindly copied from ngx_ssl_info_callback(), where
the ngx_ssl_conn_t pointer is passed with const qualifier.

7 months agoQUIC: removed level field from ngx_quic_compat_record_t.
Sergey Kandaurov [Tue, 6 May 2025 15:57:44 +0000 (19:57 +0400)]
QUIC: removed level field from ngx_quic_compat_record_t.

It was made unused in d15f8f2 after introducing reusable crypto contexts.

7 months agoQUIC: do not block ACKs by congestion control.
Sergey Kandaurov [Fri, 25 Apr 2025 19:32:24 +0000 (23:32 +0400)]
QUIC: do not block ACKs by congestion control.

Previously, it was not possible to send acknowledgments if the
congestion window was limited or temporarily exceeded, such as
after sending a large response or MTU probe.  If ACKs were not
received from the peer for some reason to update the in-flight
bytes counter below the congestion window, this might result in
a stalled connection.

The fix is to send ACKs regardless of congestion control.  This
meets RFC 9002, Section 7:
: Similar to TCP, packets containing only ACK frames do not count
: toward bytes in flight and are not congestion controlled.

This is a simplified implementation to send ACK frames from the
head of the queue.  This was made possible after 6f5f17358.

Reported in trac ticket #2621 and subsequently by Vladimir Homutov:
https://mailman.nginx.org/pipermail/nginx-devel/2025-April/ZKBAWRJVQXSZ2ISG3YJAF3EWMDRDHCMO.html

8 months agoSSL: fixed build with OPENSSL_NO_DH.
Sergey Kandaurov [Wed, 16 Apr 2025 16:58:57 +0000 (20:58 +0400)]
SSL: fixed build with OPENSSL_NO_DH.

8 months agoSSL: fixed build with OPENSSL_NO_DEPRECATED.
Sergey Kandaurov [Wed, 16 Apr 2025 16:50:29 +0000 (20:50 +0400)]
SSL: fixed build with OPENSSL_NO_DEPRECATED.

8 months agoQUIC: fixed a typo.
nandsky [Fri, 18 Apr 2025 03:45:12 +0000 (11:45 +0800)]
QUIC: fixed a typo.

8 months agoWin32: added detection of ARM64 target.
Aleksei Bavshin [Tue, 14 Jan 2025 19:11:28 +0000 (11:11 -0800)]
Win32: added detection of ARM64 target.

This extends the target selection implemented in dad6ec3aa63f to support
Windows ARM64 platforms.  OpenSSL support for VC-WIN64-ARM target first
appeared in 1.1.1 and is present in all currently supported (3.x)
branches.

As a side effect, ARM64 Windows builds will get 16-byte alignment along
with the rest of non-x86 platforms.  This is safe, as malloc on 64-bit
Windows guarantees the fundamental alignment of allocations, 16 bytes.

8 months agoCore: improved NGX_ALIGNMENT detection on some x86_64 platforms.
Aleksei Bavshin [Tue, 14 Jan 2025 18:32:24 +0000 (10:32 -0800)]
Core: improved NGX_ALIGNMENT detection on some x86_64 platforms.

Previously, the default pool alignment used sizeof(unsigned long), with
the expectation that this would match to a platform word size.  Certain
64-bit platforms prove this assumption wrong by keeping the 32-bit long
type, which is fully compliant with the C standard.

This introduces a possibility of suboptimal misaligned access to the
data allocated with ngx_palloc() on the affected platforms, which is
addressed here by changing the default NGX_ALIGNMENT to a pointer size.

As we override the detection in auto/os/conf for all the machine types
except x86, and Unix-like 64-bit systems prefer the 64-bit long, the
impact of the change should be limited to Win64 x64.

8 months agoHTTP/3: fixed NGX_HTTP_V3_VARLEN_INT_LEN value.
Roman Arutyunyan [Fri, 18 Apr 2025 07:16:57 +0000 (11:16 +0400)]
HTTP/3: fixed NGX_HTTP_V3_VARLEN_INT_LEN value.

After fixing ngx_http_v3_encode_varlen_int() in 400eb1b628,
NGX_HTTP_V3_VARLEN_INT_LEN retained the old value of 4, which is
insufficient for the values over 1073741823 (1G - 1).

The NGX_HTTP_V3_VARLEN_INT_LEN macro is used in ngx_http_v3_uni.c to
format stream and frame types.  Old buffer size is enough for formatting
this data.  Also, the macro is used in ngx_http_v3_filter_module.c to
format output chunks and trailers.  Considering output_buffers and
proxy_buffer_size are below 1G in all realistic scenarios, the old buffer
size is enough here as well.

8 months agoFixed -Wunterminated-string-initialization with gcc15.
Roman Arutyunyan [Wed, 16 Apr 2025 12:56:44 +0000 (16:56 +0400)]
Fixed -Wunterminated-string-initialization with gcc15.

8 months agoQUIC: lowered log level for unsupported transport parameters.
Roman Arutyunyan [Tue, 8 Apr 2025 12:54:28 +0000 (16:54 +0400)]
QUIC: lowered log level for unsupported transport parameters.

8 months agoVersion bump.
Roman Arutyunyan [Wed, 16 Apr 2025 14:48:50 +0000 (18:48 +0400)]
Version bump.

8 months agonginx-1.27.5-RELEASE
Sergey Kandaurov [Mon, 14 Apr 2025 18:35:27 +0000 (22:35 +0400)]
nginx-1.27.5-RELEASE

8 months agoQUIC: dynamic packet threshold.
Roman Arutyunyan [Mon, 14 Apr 2025 13:16:47 +0000 (17:16 +0400)]
QUIC: dynamic packet threshold.

RFC 9002, Section 6.1.1 defines packet reordering threshold as 3.  Testing
shows that such low value leads to spurious packet losses followed by
congestion window collapse.  The change implements dynamic packet threshold
detection based on in-flight packet range.  Packet threshold is defined
as half the number of in-flight packets, with mininum value of 3.

Also, renamed ngx_quic_lost_threshold() to ngx_quic_time_threshold()
for better compliance with RFC 9002 terms.

8 months agoQUIC: optimized connection frame threshold.
Roman Arutyunyan [Fri, 4 Apr 2025 13:39:05 +0000 (17:39 +0400)]
QUIC: optimized connection frame threshold.

Previosly the threshold was hardcoded at 10000.  This value is too low for
high BDP networks.  For example, if all frames are STREAM frames, and MTU
is 1500, the upper limit for congestion window would be roughly 15M
(10000 * 1500).  With 100ms RTT it's just a 1.2Gbps network (15M * 10 * 8).
In reality, the limit is even lower because of other frame types.  Also,
the number of frames that could be used simultaneously depends on the total
amount of data buffered in all server streams, and client flow control.

The change sets frame threshold based on max concurrent streams and stream
buffer size, the product of which is the maximum number of in-flight stream
data in all server streams at any moment.  The value is divided by 2000 to
account for a typical MTU 1500 and the fact that not all frames are STREAM
frames.

8 months agoQUIC: CUBIC congestion control.
Roman Arutyunyan [Thu, 7 Nov 2024 13:25:45 +0000 (17:25 +0400)]
QUIC: CUBIC congestion control.

8 months agoQUIC: ignore congestion control when sending MTU probes.
Roman Arutyunyan [Mon, 6 Jan 2025 06:19:56 +0000 (10:19 +0400)]
QUIC: ignore congestion control when sending MTU probes.

If connection is network-limited, MTU probes have little chance of being
sent since congestion window is almost always full.  As a result, PMTUD
may not be able to reach the real MTU and the connection may operate with
a reduced MTU.  The solution is to ignore the congestion window.  This may
lead to a temporary increase in in-flight count beyond congestion window.

8 months agoQUIC: do not shrink congestion window after losing an MTU probe.
Roman Arutyunyan [Mon, 6 Jan 2025 12:27:03 +0000 (16:27 +0400)]
QUIC: do not shrink congestion window after losing an MTU probe.

As per RFC 9000, Section 14.4:

    Loss of a QUIC packet that is carried in a PMTU probe is therefore
    not a reliable indication of congestion and SHOULD NOT trigger a
    congestion control reaction.

8 months agoQUIC: do not increase underutilized congestion window.
Roman Arutyunyan [Sat, 4 Jan 2025 14:03:46 +0000 (18:03 +0400)]
QUIC: do not increase underutilized congestion window.

As per RFC 9002, Section 7.8, congestion window should not be increased
when it's underutilized.

8 months agoQUIC: all-levels commit and revert functions.
Roman Arutyunyan [Sun, 9 Mar 2025 12:09:28 +0000 (16:09 +0400)]
QUIC: all-levels commit and revert functions.

Previously, these functions operated on a per-level basis.  This however
resulted in excessive logging of in_flight and will also led to extra
work detecting underutilized congestion window in the followup patches.

8 months agoQUIC: ngx_msec_t overflow protection.
Roman Arutyunyan [Mon, 10 Mar 2025 08:19:25 +0000 (12:19 +0400)]
QUIC: ngx_msec_t overflow protection.

On some systems the value of ngx_current_msec is derived from monotonic
clock, for which the following is defined by POSIX:

   For this clock, the value returned by clock_gettime() represents
   the amount of time (in seconds and nanoseconds) since an unspecified
   point in the past.

As as result, overflow protection is needed when comparing two ngx_msec_t.
The change adds such protection to the ngx_quic_detect_lost() function.

8 months agoQUIC: prevent spurious congestion control recovery mode.
Roman Arutyunyan [Fri, 3 Jan 2025 09:01:06 +0000 (13:01 +0400)]
QUIC: prevent spurious congestion control recovery mode.

Since recovery_start field was initialized with ngx_current_msec, all
congestion events that happened within the same millisecond or cycle
iteration, were treated as in recovery mode.

Also, when handling persistent congestion, initializing recovery_start
with ngx_current_msec resulted in treating all sent packets as in recovery
mode, which violates RFC 9002, see example in Appendix B.8.

While here, also fixed recovery_start wrap protection.  Previously it used
2 * max_idle_timeout time frame for all sent frames, which is not a
reliable protection since max_idle_timeout is unrelated to congestion
control.  Now recovery_start <= now condition is enforced.  Note that
recovery_start wrap is highly unlikely and can only occur on a
32-bit system if there are no congestion events for 24 days.

8 months agoQUIC: use path MTU in congestion window computations.
Roman Arutyunyan [Fri, 3 Jan 2025 07:17:07 +0000 (11:17 +0400)]
QUIC: use path MTU in congestion window computations.

As per RFC 9002, Section B.2, max_datagram_size used in congestion window
computations should be based on path MTU.

8 months agoHTTP/3: graceful shutdown on keepalive timeout expiration.
Roman Arutyunyan [Tue, 7 Jan 2025 17:14:58 +0000 (21:14 +0400)]
HTTP/3: graceful shutdown on keepalive timeout expiration.

Previously, the expiration caused QUIC connection finalization even if
there are application-terminated streams finishing sending data.  Such
finalization terminated these streams.

An easy way to trigger this is to request a large file from HTTP/3 over
a small MTU.  In this case keepalive timeout expiration may abruptly
terminate the request stream.

8 months agoQUIC: graph-friendly congestion control logging.
Roman Arutyunyan [Fri, 3 Jan 2025 10:49:47 +0000 (14:49 +0400)]
QUIC: graph-friendly congestion control logging.

Improved logging for simpler data extraction for plotting congestion
window graphs.  In particular, added current milliseconds number from
ngx_current_msec.

While here, simplified logging text and removed irrelevant data.

8 months agoSSL: external groups support in $ssl_curve and $ssl_curves.
Sergey Kandaurov [Thu, 3 Apr 2025 11:29:31 +0000 (15:29 +0400)]
SSL: external groups support in $ssl_curve and $ssl_curves.

Starting with OpenSSL 3.0, groups may be added externally with pluggable
KEM providers.  Using SSL_get_negotiated_group(), which makes lookup in a
static table with known groups, doesn't allow to list such groups by names
leaving them in hex.  Adding X25519MLKEM768 to the default group list in
OpenSSL 3.5 made this problem more visible.  SSL_get0_group_name() and,
apparently, SSL_group_to_name() allow to resolve such provider-implemented
groups, which is also "generally preferred" over SSL_get_negotiated_group()
as documented in OpenSSL git commit 93d4f6133f.

This change makes external groups listing by name using SSL_group_to_name()
available since OpenSSL 3.0.  To preserve "prime256v1" naming for the group
0x0017, and to avoid breaking BoringSSL and older OpenSSL versions support,
it is used supplementary for a group that appears to be unknown.

See https://github.com/openssl/openssl/issues/27137 for related discussion.

8 months agoUpstream: fixed passwords support for dynamic certificates.
Sergey Kandaurov [Wed, 5 Feb 2025 15:16:05 +0000 (19:16 +0400)]
Upstream: fixed passwords support for dynamic certificates.

Passwords were not preserved in optimized SSL contexts, the bug had
appeared in d791b4aab (1.23.1), as in the following configuration:

    server {
        proxy_ssl_password_file password;
        proxy_ssl_certificate $ssl_server_name.crt;
        proxy_ssl_certificate_key $ssl_server_name.key;

        location /original/ {
            proxy_pass https://u1/;
        }

        location /optimized/ {
            proxy_pass https://u2/;
        }
    }

The fix is to always preserve passwords, by copying to the configuration
pool, if dynamic certificates are used.  This is done as part of merging
"ssl_passwords" configuration.

To minimize the number of copies, a preserved version is then used for
inheritance.  A notable exception is inheritance of preserved empty
passwords to the context with statically configured certificates:

    server {
        proxy_ssl_certificate $ssl_server_name.crt;
        proxy_ssl_certificate_key $ssl_server_name.key;

        location / {
            proxy_pass ...;

            proxy_ssl_certificate example.com.crt;
            proxy_ssl_certificate_key example.com.key;
        }
    }

In this case, an unmodified version (NULL) of empty passwords is set,
to allow reading them from the password prompt on nginx startup.

As an additional optimization, a preserved instance of inherited
configured passwords is set to the previous level, to inherit it
to other contexts:

    server {
        proxy_ssl_password_file password;

        location /1/ {
            proxy_pass https://u1/;
            proxy_ssl_certificate $ssl_server_name.crt;
            proxy_ssl_certificate_key $ssl_server_name.key;
        }

        location /2/ {
            proxy_pass https://u2/;
            proxy_ssl_certificate $ssl_server_name.crt;
            proxy_ssl_certificate_key $ssl_server_name.key;
        }
    }

8 months agoCharset filter: improved validation of charset_map with utf-8.
Sergey Kandaurov [Thu, 27 Feb 2025 14:42:06 +0000 (18:42 +0400)]
Charset filter: improved validation of charset_map with utf-8.

It was possible to write outside of the buffer used to keep UTF-8
decoded values when parsing conversion table configuration.

Since this happened before UTF-8 decoding, the fix is to check in
advance if character codes are of more than 3-byte sequence.  Note
that this is already enforced by a later check for ngx_utf8_decode()
decoded values for 0xffff, which corresponds to the maximum value
encoded as a valid 3-byte sequence, so the fix does not affect the
valid values.

Found with AddressSanitizer.
Fixes GitHub issue #529.

9 months agoSlice filter: improved memory allocation error handling.
Sergey Kandaurov [Thu, 27 Feb 2025 12:09:50 +0000 (16:09 +0400)]
Slice filter: improved memory allocation error handling.

As uncovered by recent addition in slice.t, a partially initialized
context, coupled with HTTP 206 response from stub backend, might be
accessed in the next slice subrequest.

Found by bad memory allocator simulation.

10 months agoSSL: removed stale comments.
Sergey Kandaurov [Fri, 21 Feb 2025 11:54:04 +0000 (15:54 +0400)]
SSL: removed stale comments.

It appears to be a relic from prototype locking removed in b0b7b5a35.

10 months agoSSL: improved logging of saving sessions from upstream servers.
Sergey Kandaurov [Fri, 21 Feb 2025 11:41:33 +0000 (15:41 +0400)]
SSL: improved logging of saving sessions from upstream servers.

This makes it easier to understand why sessions may not be saved
in shared memory due to size.

10 months agoSSL: raised limit for sessions stored in shared memory.
Sergey Kandaurov [Tue, 25 Feb 2025 15:50:44 +0000 (19:50 +0400)]
SSL: raised limit for sessions stored in shared memory.

Upstream SSL sessions may be of a noticeably larger size with tickets
in TLSv1.2 and older versions, or with "stateless" tickets in TLSv1.3,
if a client certificate is saved into the session.  Further, certain
stateless session resumption implemetations may store additional data.

Such one is JDK, known to also include server certificates in session
ticket data, which roughly doubles a decoded session size to slightly
beyond the previous limit.  While it's believed to be an issue on the
JDK side, this change allows to save such sessions.

Another, innocent case is using RSA certificates with 8192 key size.

10 months agoSSL: using static storage for NGX_SSL_MAX_SESSION_SIZE buffers.
Sergey Kandaurov [Fri, 21 Feb 2025 09:49:41 +0000 (13:49 +0400)]
SSL: using static storage for NGX_SSL_MAX_SESSION_SIZE buffers.

All such transient buffers are converted to the single storage in BSS.

In preparation to raise the limit.

10 months agoSSL: style.
Sergey Kandaurov [Tue, 25 Feb 2025 15:40:22 +0000 (19:40 +0400)]
SSL: style.

10 months agoImproved ngx_http_subrequest() error handling.
Sergey Kandaurov [Tue, 11 Feb 2025 18:54:04 +0000 (22:54 +0400)]
Improved ngx_http_subrequest() error handling.

Previously, request might be left in inconsistent state in case of error,
which manifested in "http request count is zero" alerts when used by SSI
filter.

The fix is to reshuffle initialization order to postpone committing state
changes until after any potentially failing parts.

Found by bad memory allocator simulation.

10 months agoAdd gitignore file.
Orgad Shaneh [Thu, 13 Feb 2025 20:35:17 +0000 (22:35 +0200)]
Add gitignore file.

10 months agoConfigure: MSVC compatibility with PCRE2 10.45.
Thierry Bastian [Mon, 17 Feb 2025 08:01:27 +0000 (09:01 +0100)]
Configure: MSVC compatibility with PCRE2 10.45.

10 months agoCore: fix build without libcrypt.
Piotr Sikora [Wed, 12 Feb 2025 08:40:58 +0000 (10:40 +0200)]
Core: fix build without libcrypt.

libcrypt is no longer part of glibc, so it might not be available.

Signed-off-by: Piotr Sikora <piotr@aviatrix.com>
10 months agoVersion bump.
Sergey Kandaurov [Tue, 18 Feb 2025 11:38:33 +0000 (15:38 +0400)]
Version bump.

10 months agonginx-1.27.4-RELEASE
Sergey Kandaurov [Wed, 5 Feb 2025 10:24:20 +0000 (14:24 +0400)]
nginx-1.27.4-RELEASE

10 months agoSNI: added restriction for TLSv1.3 cross-SNI session resumption.
Sergey Kandaurov [Wed, 22 Jan 2025 14:55:44 +0000 (18:55 +0400)]
SNI: added restriction for TLSv1.3 cross-SNI session resumption.

In OpenSSL, session resumption always happens in the default SSL context,
prior to invoking the SNI callback.  Further, unlike in TLSv1.2 and older
protocols, SSL_get_servername() returns values received in the resumption
handshake, which may be different from the value in the initial handshake.
Notably, this makes the restriction added in b720f650b insufficient for
sessions resumed with different SNI server name.

Considering the example from b720f650b, previously, a client was able to
request example.org by presenting a certificate for example.org, then to
resume and request example.com.

The fix is to reject handshakes resumed with a different server name, if
verification of client certificates is enabled in a corresponding server
configuration.

10 months agoAdded "keepalive_min_timeout" directive.
Roman Arutyunyan [Wed, 15 Jan 2025 08:42:39 +0000 (12:42 +0400)]
Added "keepalive_min_timeout" directive.

The directive sets a timeout during which a keepalive connection will
not be closed by nginx for connection reuse or graceful shutdown.

The change allows clients that send multiple requests over the same
connection without delay or with a small delay between them, to avoid
receiving a TCP RST in response to one of them.  This excludes network
issues and non-graceful shutdown.  As a side-effect, it also addresses
the TCP reset problem described in RFC 9112, Section 9.6, when the last
sent HTTP response could be damaged by a followup TCP RST.  It is important
for non-idempotent requests, which cannot be retried by client.

It is not recommended to set keepalive_min_timeout to large values as
this can introduce an additional delay during graceful shutdown and may
restrict nginx from effective connection reuse.

10 months agoMisc: moved documentation in generated ZIP archive.
Sergey Kandaurov [Mon, 9 Dec 2024 09:21:03 +0000 (13:21 +0400)]
Misc: moved documentation in generated ZIP archive.

The recently added GitHub files now reside in the docs directory.

10 months agoConfigure: fixed --with-libatomic=DIR with recent libatomic_ops.
Sergey Kandaurov [Fri, 17 Jan 2025 13:55:21 +0000 (17:55 +0400)]
Configure: fixed --with-libatomic=DIR with recent libatomic_ops.

The build location of the resulting libatomic_ops.a was changed in v7.4.0
after converting libatomic_ops to use libtool.  The fix is to use library
from the install path, this allows building with both old and new versions.

Initially reported here:
https://mailman.nginx.org/pipermail/nginx/2018-April/056054.html

10 months agoQUIC: added missing casts in iov_base assignments.
Aleksei Bavshin [Mon, 27 Jan 2025 18:33:25 +0000 (10:33 -0800)]
QUIC: added missing casts in iov_base assignments.

This is consistent with the rest of the code and fixes build on systems
with non-standard definition of struct iovec (Solaris, Illumos).

11 months agoUpstream: fixed --with-compat build without SSL, broken by 454ad0e.
Pavel Pautov [Wed, 22 Jan 2025 02:41:16 +0000 (18:41 -0800)]
Upstream: fixed --with-compat build without SSL, broken by 454ad0e.

11 months agoSSL: avoid using mismatched certificate/key cached pairs.
Sergey Kandaurov [Wed, 8 Jan 2025 13:50:33 +0000 (17:50 +0400)]
SSL: avoid using mismatched certificate/key cached pairs.

This can happen with certificates and certificate keys specified
with variables due to partial cache update in various scenarios:
- cache expiration with only one element of pair evicted
- on-disk update with non-cacheable encrypted keys
- non-atomic on-disk update

The fix is to retry with fresh data on X509_R_KEY_VALUES_MISMATCH.

11 months agoUpstream: caching certificates and certificate keys with variables.
Sergey Kandaurov [Tue, 29 Oct 2024 14:20:53 +0000 (18:20 +0400)]
Upstream: caching certificates and certificate keys with variables.

Caching is enabled with proxy_ssl_certificate_cache and friends.

Co-authored-by: Aleksei Bavshin <a.bavshin@nginx.com>
11 months agoSSL: cache revalidation of file based dynamic certificates.
Sergey Kandaurov [Mon, 13 Jan 2025 17:40:04 +0000 (21:40 +0400)]
SSL: cache revalidation of file based dynamic certificates.

Revalidation is based on file modification time and uniq file index,
and happens after the cache object validity time is expired.

11 months agoSSL: caching certificates and certificate keys with variables.
Sergey Kandaurov [Tue, 29 Oct 2024 12:25:11 +0000 (16:25 +0400)]
SSL: caching certificates and certificate keys with variables.

A new directive "ssl_certificate_cache max=N [valid=time] [inactive=time]"
enables caching of SSL certificate chain and secret key objects specified
by "ssl_certificate" and "ssl_certificate_key" directives with variables.

Co-authored-by: Aleksei Bavshin <a.bavshin@nginx.com>
11 months agoSSL: encrypted certificate keys are exempt from object cache.
Sergey Kandaurov [Wed, 18 Dec 2024 16:09:58 +0000 (20:09 +0400)]
SSL: encrypted certificate keys are exempt from object cache.

SSL object cache, as previously introduced in 1.27.2, did not take
into account encrypted certificate keys that might be unexpectedly
fetched from the cache regardless of the matching passphrase.  To
avoid this, caching of encrypted certificate keys is now disabled
based on the passphrase callback invocation.

A notable exception is encrypted certificate keys configured without
ssl_password_file.  They are loaded once resulting in the passphrase
prompt on startup and reused in other contexts as applicable.

11 months agoSSL: object cache inheritance from the old configuration cycle.
Sergey Kandaurov [Wed, 18 Dec 2024 16:03:35 +0000 (20:03 +0400)]
SSL: object cache inheritance from the old configuration cycle.

Memory based objects are always inherited, engine based objects are
never inherited to adhere the volatile nature of engines, file based
objects are inherited subject to modification time and file index.

The previous behaviour to bypass cache from the old configuration cycle
is preserved with a new directive "ssl_object_cache_inheritable off;".

11 months agoSlice filter: log the expected range in case of range error.
Daniel Vasquez Lopez [Thu, 21 Nov 2024 22:27:07 +0000 (14:27 -0800)]
Slice filter: log the expected range in case of range error.

11 months agoGzip: compatibility with recent zlib-ng 2.2.x versions.
Sergey Kandaurov [Mon, 23 Dec 2024 13:57:45 +0000 (17:57 +0400)]
Gzip: compatibility with recent zlib-ng 2.2.x versions.

It now uses 5/4 times more memory for the pending buffer.

Further, a single allocation is now used, which takes additional 56 bytes
for deflate_allocs in 64-bit mode aligned to 16, to store sub-allocation
pointers, and the total allocation size now padded up to 128 bytes, which
takes theoretically 200 additional bytes in total.  This fits though into
"4 * (64 + sizeof(void*))" additional space for ZALLOC used in zlib-ng
2.1.x versions.  The comment was updated to reflect this.

11 months agoYear 2025.
Roman Arutyunyan [Thu, 9 Jan 2025 13:00:14 +0000 (17:00 +0400)]
Year 2025.

12 months agoQUIC: fixed accessing a released stream.
Roman Arutyunyan [Tue, 10 Dec 2024 14:19:27 +0000 (18:19 +0400)]
QUIC: fixed accessing a released stream.

While trying to close a stream in ngx_quic_close_streams() by calling its
read event handler, the next stream saved prior to that could be destroyed
recursively.  This caused a segfault while trying to access the next stream.

The way the next stream could be destroyed in HTTP/3 is the following.
A request stream read event handler ngx_http_request_handler() could
end up calling ngx_http_v3_send_cancel_stream() to report a cancelled
request stream in the decoder stream.  If sending stream cancellation
decoder instruction fails for any reason, and the decoder stream is the
next in order after the request stream, the issue is triggered.

The fix is to postpone calling read event handlers for all streams being
closed to avoid closing a released stream.

12 months agoQUIC: ignore version negotiation packets.
Roman Arutyunyan [Fri, 13 Dec 2024 09:25:26 +0000 (13:25 +0400)]
QUIC: ignore version negotiation packets.

Previously, such packets were treated as long header packets with unknown
version 0, and a version negotiation packet was sent in response.  This
could be used to set up an infinite traffic reflect loop with another nginx
instance.

Now version negotiation packets are ignored.  As per RFC 9000, Section 6.1:

  An endpoint MUST NOT send a Version Negotiation packet in response to
  receiving a Version Negotiation packet.

12 months agoUpdated security policy to clarify experimental features.
Jordan Zebor [Mon, 23 Dec 2024 16:07:01 +0000 (08:07 -0800)]
Updated security policy to clarify experimental features.

The original security policy language did not capture the scope
as intended for experimental features and availability.

12 months agoQUIC: fixed client request timeout in 0-RTT scenarios.
nandsky [Mon, 25 Nov 2024 07:26:29 +0000 (15:26 +0800)]
QUIC: fixed client request timeout in 0-RTT scenarios.

Since 0-RTT and 1-RTT data exist in the same packet number space,
ngx_quic_discard_ctx incorrectly discards 1-RTT packets when
0-RTT keys are discarded.

The issue was introduced by 58b92177e7c3c50f77f807ab3846ad5c7bbf0ebe.

12 months agoVersion bump.
Roman Arutyunyan [Wed, 27 Nov 2024 16:01:26 +0000 (20:01 +0400)]
Version bump.

13 months agonginx-1.27.3-RELEASE
Sergey Kandaurov [Tue, 26 Nov 2024 11:36:52 +0000 (15:36 +0400)]
nginx-1.27.3-RELEASE

13 months agoMail: handling of LOGIN IMAP command untagged response.
Sergey Kandaurov [Wed, 23 Oct 2024 20:52:21 +0000 (00:52 +0400)]
Mail: handling of LOGIN IMAP command untagged response.

In particular, an untagged CAPABILITY response as described in the
interim RFC 3501 internet drafts was seen in various IMAP servers.
Previously resulted in a broken connection, now an untagged response
is proxied to client.

13 months agoRealip: allowed square brackets with portless IPv6 address.
Roman Arutyunyan [Mon, 11 Nov 2024 18:28:30 +0000 (22:28 +0400)]
Realip: allowed square brackets with portless IPv6 address.

When client address is received, IPv6 address could be specified without
square brackets and without port, as well as both with the brackets and
port.  The change allows IPv6 in square brackets and no port, which was
previously considered an error.  This format conforms to RFC 3986.

The change also affects proxy_bind and friends.

13 months agoQUIC: got rid of memory copy when initializing constant values.
Sergey Kandaurov [Mon, 7 Oct 2024 14:43:48 +0000 (18:43 +0400)]
QUIC: got rid of memory copy when initializing constant values.

13 months agoQUIC: constified nonce parameter of crypto functions.
Sergey Kandaurov [Mon, 7 Oct 2024 14:19:24 +0000 (18:19 +0400)]
QUIC: constified nonce parameter of crypto functions.

This follows OpenSSL and BoringSSL API, and gives a hint to compiler
that this parameter may not be modified.

13 months agoUpstream: disallow empty path in proxy_store and friends.
Sergey Kandaurov [Thu, 21 Nov 2024 08:35:50 +0000 (12:35 +0400)]
Upstream: disallow empty path in proxy_store and friends.

Renaming a temporary file to an empty path ("") returns NGX_ENOPATH
with a subsequent ngx_create_full_path() to create the full path.
This function skips initial bytes as part of path separator lookup,
which causes out of bounds access on short strings.

The fix is to avoid renaming a temporary file to an obviously invalid
path, as well as explicitly forbid such syntax for literal values.

Although Coverity reports about potential type underflow, it is not
actually possible because the terminating '\0' is always included.

Notably, the run-time check is sufficient enough for Win32 as well.
Other short invalid values result either in NGX_ENOENT or NGX_EEXIST
and "MoveFile() .. failed" critical log messages, which involves a
separate error handling.

Prodded by Coverity (CID 1605485).

13 months agoQUIC: prevented BIO leak in case of error.
Roman Arutyunyan [Fri, 22 Nov 2024 07:38:06 +0000 (11:38 +0400)]
QUIC: prevented BIO leak in case of error.

13 months agoSSL: a new macro to set default protocol versions.
Sergey Kandaurov [Mon, 18 Nov 2024 09:39:13 +0000 (13:39 +0400)]
SSL: a new macro to set default protocol versions.

This simplifies merging protocol values after ea15896 and ebd18ec.

Further, as outlined in ebd18ec18, for libraries preceeding TLSv1.2+
support, only meaningful versions TLSv1 and TLSv1.1 are set by default.

While here, fixed indentation.

13 months agoMp4: prevent chunk index underflow.
Roman Arutyunyan [Tue, 22 Oct 2024 14:34:13 +0000 (18:34 +0400)]
Mp4: prevent chunk index underflow.

When cropping stsc atom, it's assumed that chunk index is never 0.
Based on this assumption, start_chunk and end_chunk are calculated
by subtracting 1 from it.  If chunk index is zero, start_chunk or
end_chunk may underflow, which will later trigger
"start/end time is out mp4 stco chunks" error.  The change adds an
explicit check for zero chunk index to avoid underflow and report
a proper error.

Zero chunk index is explicitly banned in ISO/IEC 14496-12, 8.7.4
Sample To Chunk Box.  It's also implicitly banned in QuickTime File
Format specification.  Description of chunk offset table references
"Chunk 1" as the first table element.