summaryrefslogtreecommitdiffhomepage
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2019-02-07SSL: fixed EVP_DigestFinal_ex() error message.Sergey Kandaurov1-1/+1
2019-01-31SSL: separate checks for errors in ngx_ssl_read_password_file().Maxim Dounin1-2/+5
Checking multiple errors at once is a bad practice, as in general it is not guaranteed that an object can be used after the error. In this particular case, checking errors after multiple allocations can result in excessive errors being logged when there is no memory available.
2019-01-31SSL: explicitly zero out session ticket keys.Ruslan Ermilov1-0/+24
2019-01-31Modules compatibility: down flag in ngx_peer_connection_t.Roman Arutyunyan1-0/+1
2018-12-25Use %s for errors returned from configuration parsing handlers.Ruslan Ermilov1-1/+1
2019-01-28Removed --test-build-eventport workaround for old FreeBSD versions.Sergey Kandaurov1-2/+0
2019-01-28Fixed portability issues with union sigval.Sergey Kandaurov2-1/+7
AIO support in nginx was originally developed against FreeBSD versions 4-6, where the sival_ptr field was named as sigval_ptr (seemingly by mistake[1]), which made nginx use the only name available then. The standard-complaint name was restored in 2005 (first appeared in FreeBSD 7.0, 2008), retaining compatibility with previous versions[2][3]. In DragonFly, similar changes were committed in 2009[4], with backward compatibility recently removed[5]. The change switches to the standard name, retaining compatibility with old FreeBSD versions. [1] https://svnweb.freebsd.org/changeset/base/48621 [2] https://svnweb.freebsd.org/changeset/base/152029 [3] https://svnweb.freebsd.org/changeset/base/174003 [4] https://gitweb.dragonflybsd.org/dragonfly.git/commit/3693401 [5] https://gitweb.dragonflybsd.org/dragonfly.git/commit/7875042
2019-01-24Win32: detection of connect() errors in select().Maxim Dounin1-4/+13
On Windows, connect() errors are only reported via exceptfds descriptor set from select(). Previously exceptfds was set to NULL, and connect() errors were not detected at all, so connects to closed ports were waiting till a timeout occurred. Since ongoing connect() means that there will be a write event active, except descriptor set is copied from the write one. While it is possible to construct except descriptor set as a concatenation of both read and write descriptor sets, this looks unneeded. With this change, connect() errors are properly detected now when using select(). Note well that it is not possible to detect connect() errors with WSAPoll() (see https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/).
2019-01-24Win32: added WSAPoll() support.Maxim Dounin3-0/+510
WSAPoll() is only available with Windows Vista and newer (and only available during compilation if _WIN32_WINNT >= 0x0600). To make sure the code works with Windows XP, we do not redefine _WIN32_WINNT, but instead load WSAPoll() dynamically if it is not available during compilation. Also, sockets are not guaranteed to be small integers on Windows. So an index array is used instead of NGX_USE_FD_EVENT to map events to connections.
2019-01-24Events: fixed copying of old events in poll init.Maxim Dounin1-1/+1
Previously, the code incorrectly assumed "ngx_event_t *" elements instead of "struct pollfd". This is mostly cosmetic change, as this code is never called now.
2018-12-27Stream: do not split datagrams when limiting proxy rate.Roman Arutyunyan1-1/+1
Previously, when using proxy_upload_rate and proxy_download_rate, the buffer size for reading from a socket could be reduced as a result of rate limiting. For connection-oriented protocols this behavior is normal since unread data will normally be read at the next iteration. But for datagram-oriented protocols this is not the case, and unread part of the datagram is lost. Now buffer size is not limited for datagrams. Rate limiting still works in this case by delaying the next reading event.
2019-01-14Prevented scheduling events on a shared connection.Roman Arutyunyan2-2/+8
A shared connection does not own its file descriptor, which means that ngx_handle_read_event/ngx_handle_write_event calls should do nothing for it. Currently the c->shared flag is checked in several places in the stream proxy module prior to calling these functions. However it was not done everywhere. Missing checks could lead to calling ngx_handle_read_event/ngx_handle_write_event on shared connections. The problem manifested itself when using proxy_upload_rate and resulted in either duplicate file descriptor error (e.g. with epoll) or incorrect further udp packet processing (e.g. with kqueue). The fix is to set and reset the event active flag in a way that prevents ngx_handle_read_event/ngx_handle_write_event from scheduling socket events.
2019-01-17Added the ngx_http_test_required_predicates() function.Vladimir Homutov2-0/+30
In contrast to ngx_http_test_predicates(), it requires all values to be non-empty and not equal to "0".
2019-01-17Version bump.Vladimir Homutov1-2/+2
2018-12-25Autoindex: fixed possible integer overflow on 32-bit systems.Vladimir Homutov1-24/+42
2018-12-24Win32: removed NGX_DIR_MASK concept.Maxim Dounin6-14/+21
Previous interface of ngx_open_dir() assumed that passed directory name has a room for NGX_DIR_MASK at the end (NGX_DIR_MASK_LEN bytes). While all direct users of ngx_dir_open() followed this interface, this also implied similar requirements for indirect uses - in particular, via ngx_walk_tree(). Currently none of ngx_walk_tree() uses provides appropriate space, and fixing this does not look like a right way to go. Instead, ngx_dir_open() interface was changed to not require any additional space and use appropriate allocations instead.
2018-12-24Userid: using stub for AF_UNIX addresses.Sergey Kandaurov1-0/+7
Previously, AF_UNIX addresses misbehaved as AF_INET, which typically resulted in $uid_set composed from the middle of sun_path.
2018-12-18SSL: avoid reading on pending SSL_write_early_data().Sergey Kandaurov2-0/+21
If SSL_write_early_data() returned SSL_ERROR_WANT_WRITE, stop further reading using a newly introduced c->ssl->write_blocked flag, as otherwise this would result in SSL error "ssl3_write_bytes:bad length". Eventually, normal reading will be restored by read event posted from successful SSL_write_early_data(). While here, place "SSL_write_early_data: want write" debug on the path.
2018-12-14Geo: fixed handling of AF_UNIX client addresses (ticket #1684).Maxim Dounin2-0/+26
Previously, AF_UNIX client addresses were handled as AF_INET, leading to unexpected results.
2018-12-13Upstream: implemented $upstream_bytes_sent.Ruslan Ermilov2-0/+16
2018-12-11Resolver: report SRV resolve failure if all A resolves failed.Roman Arutyunyan1-1/+9
Previously, if an SRV record was successfully resolved, but all of its A records failed to resolve, NXDOMAIN was returned to the caller, which is considered a successful resolve rather than an error. This could result in losing the result of a previous successful resolve by the caller. Now NXDOMAIN is only returned if at least one A resolve completed with this code. Otherwise the error state of the first A resolve is returned.
2018-12-11Copy regex unnamed captures to cloned subrequests.Roman Arutyunyan3-1/+15
Previously, unnamed regex captures matched in the parent request, were not available in a cloned subrequest. Now 3 fields related to unnamed captures are copied to a cloned subrequest: r->ncaptures, r->captures and r->captures_data. Since r->captures cannot be changed by either request after creating a clone, a new flag r->realloc_captures is introduced to force reallocation of r->captures. The issue was reported as a proxy_cache_background_update misbehavior in http://mailman.nginx.org/pipermail/nginx/2018-December/057251.html.
2018-12-11Version bump.Roman Arutyunyan1-2/+2
2018-11-26Negative size buffers detection.Maxim Dounin3-12/+132
In the past, there were several security issues which resulted in worker process memory disclosure due to buffers with negative size. It looks reasonable to check for such buffers in various places, much like we already check for zero size buffers. While here, removed "#if 1 / #endif" around zero size buffer checks. It looks highly unlikely that we'll disable these checks anytime soon.
2018-11-21Mp4: fixed possible pointer overflow on 32-bit platforms.Maxim Dounin1-1/+8
On 32-bit platforms mp4->buffer_pos might overflow when a large enough (close to 4 gigabytes) atom is being skipped, resulting in incorrect memory addesses being read further in the code. In most cases this results in harmless errors being logged, though may also result in a segmentation fault if hitting unmapped pages. To address this, ngx_mp4_atom_next() now only increments mp4->buffer_pos up to mp4->buffer_end. This ensures that overflow cannot happen.
2018-11-21Limit req: "delay=" parameter.Maxim Dounin1-10/+22
This parameter specifies an additional "soft" burst limit at which requests become delayed (but not yet rejected as it happens if "burst=" limit is exceeded). Defaults to 0, i.e., all excess requests are delayed. Originally inspired by Vladislav Shabanov (http://mailman.nginx.org/pipermail/nginx-devel/2016-April/008126.html). Further improved based on a patch by Peter Shchuchkin (http://mailman.nginx.org/pipermail/nginx-devel/2018-October/011522.html).
2018-11-21Limit req: fixed error message wording.Maxim Dounin1-1/+1
2018-11-21Upstream: revised upstream response time variables.Vladimir Homutov5-29/+36
Variables now do not depend on presence of the HTTP status code in response. If the corresponding event occurred, variables contain time between request creation and the event, and "-" otherwise. Previously, intermediate value of the $upstream_response_time variable held unix timestamp.
2018-11-21Upstream: removed unused ngx_http_upstream_t.timeout field.Vladimir Homutov1-2/+0
2018-11-15Core: ngx_explicit_memzero().Maxim Dounin3-2/+12
2018-11-15Core: free shared memory on cycle initialization failure.Ruslan Ermilov1-0/+64
2018-11-12Stream: proxy_requests directive.Vladimir Homutov3-4/+39
The directive allows to drop binding between a client and existing UDP stream session after receiving a specified number of packets. First packet from the same client address and port will start a new session. Old session continues to exist and will terminate at moment defined by configuration: either after receiving the expected number of responses, or after timeout, as specified by the "proxy_responses" and/or "proxy_timeout" directives. By default, proxy_requests is zero (disabled).
2018-11-12Stream: session completion check code moved to a separate function.Vladimir Homutov1-38/+76
The code refactored to simplify the ngx_stream_proxy_process() function and facilitate adding new session termination conditions.
2018-11-07Stream: fixed possible use of a freed connection.Vladimir Homutov1-1/+6
The session handler may result in session termination, thus a connection pool (from which c->udp was allocated) may be destroyed.
2018-11-13Version bump.Vladimir Homutov1-2/+2
2018-11-06gRPC: limited allocations due to ping and settings frames.Maxim Dounin1-0/+15
2018-11-06HTTP/2: limit the number of idle state switches.Ruslan Ermilov2-3/+11
An attack that continuously switches HTTP/2 connection between idle and active states can result in excessive CPU usage. This is because when a connection switches to the idle state, all of its memory pool caches are freed. This change limits the maximum allowed number of idle state switches to 10 * http2_max_requests (i.e., 10000 by default). This limits possible CPU usage in one connection, and also imposes a limit on the maximum lifetime of a connection. Initially reported by Gal Goldshtein from F5 Networks.
2018-11-06HTTP/2: flood detection.Ruslan Ermilov2-1/+12
Fixed uncontrolled memory growth in case peer is flooding us with some frames (e.g., SETTINGS and PING) and doesn't read data. Fix is to limit the number of allocated control frames.
2018-11-06Mp4: fixed reading 64-bit atoms.Roman Arutyunyan1-0/+7
Previously there was no validation for the size of a 64-bit atom in an mp4 file. This could lead to a CPU hog when the size is 0, or various other problems due to integer underflow when calculating atom data size, including segmentation fault or worker process memory disclosure.
2018-10-31Cache: improved keys zone size error reporting.Maxim Dounin1-12/+21
After this change, too small keys zones are explicitly reported as such, much like in the other modules which use shared memory.
2018-10-31Cache: fixed minimum cache keys zone size limit.Maxim Dounin1-1/+1
Size of a shared memory zones must be at least two pages - one page for slab allocator internal data, and another page for actual allocations. Using 8192 instead is wrong, as there are systems with page sizes other than 4096. Note well that two pages is usually too low as well. In particular, cache is likely to use two allocations of different sizes for global structures, and at least four pages will be needed to properly allocate cache nodes. Except in a few very special cases, with keys zone of just two pages nginx won't be able to start. Other uses of shared memory impose a limit of 8 pages, which provides some room for global allocations. This patch doesn't try to address this though. Inspired by ticket #1665.
2018-10-19A minor code clean for macro ngx_event_get_conf in ngx_event.h.chronolaw1-1/+1
2018-10-23SSL: explicitly set maximum version (ticket #1654).Maxim Dounin1-0/+5
With maximum version explicitly set, TLSv1.3 will not be unexpectedly enabled if nginx compiled with OpenSSL 1.1.0 (without TLSv1.3 support) will be run with OpenSSL 1.1.1 (with TLSv1.3 support).
2018-10-03Upstream: proxy_socket_keepalive and friends.Vladimir Homutov11-1/+101
The directives enable the use of the SO_KEEPALIVE option on upstream connections. By default, the value is left unchanged.
2018-10-03Version bump.Vladimir Homutov1-2/+2
2018-10-02SSL: fixed segfault on renegotiation (ticket #1646).Maxim Dounin1-1/+5
In e3ba4026c02d (1.15.4) nginx own renegotiation checks were disabled if SSL_OP_NO_RENEGOTIATION is available. But since SSL_OP_NO_RENEGOTIATION is only set on a connection, not in an SSL context, SSL_clear_option() removed it as long as a matching virtual server was found. This resulted in a segmentation fault similar to the one fixed in a6902a941279 (1.9.8), affecting nginx built with OpenSSL 1.1.0h or higher. To fix this, SSL_OP_NO_RENEGOTIATION is now explicitly set in ngx_http_ssl_servername() after adjusting options. Additionally, instead of c->ssl->renegotiation we now check c->ssl->handshaked, which seems to be a more correct flag to test, and will prevent the segmentation fault from happening even if SSL_OP_NO_RENEGOTIATION is not working.
2018-10-02Fixed off-by-one error in shared zone initialization.Ruslan Ermilov1-1/+2
On systems without atomic ops, not enough space was allocated for mutex's file name during shared zone initialization.
2018-09-25SSL: fixed unlocked access to sess_id->len.Ruslan Ermilov1-2/+5
2018-09-27Version bump.Ruslan Ermilov1-2/+2
2018-09-25SSL: logging level of "no suitable signature algorithm".Maxim Dounin1-0/+6
The "no suitable signature algorithm" errors are reported by OpenSSL 1.1.1 when using TLSv1.3 if there are no shared signature algorithms. In particular, this can happen if the client limits available signature algorithms to something we don't have a certificate for, or to an empty list. For example, the following command: openssl s_client -connect 127.0.0.1:8443 -sigalgs rsa_pkcs1_sha1 will always result in the "no suitable signature algorithm" error as the "rsa_pkcs1_sha1" algorithm refers solely to signatures which appear in certificates and not defined for use in TLS 1.3 handshake messages. The SSL_R_NO_COMMON_SIGNATURE_ALGORITHMS error is what BoringSSL returns in the same situation.