aboutsummaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAge
...
* Stream: do not split datagrams when limiting proxy rate.Roman Arutyunyan2018-12-27
| | | | | | | | | | | 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.
* Prevented scheduling events on a shared connection.Roman Arutyunyan2019-01-14
| | | | | | | | | | | | | | | | 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.
* Added the ngx_http_test_required_predicates() function.Vladimir Homutov2019-01-17
| | | | | In contrast to ngx_http_test_predicates(), it requires all values to be non-empty and not equal to "0".
* Version bump.Vladimir Homutov2019-01-17
|
* Autoindex: fixed possible integer overflow on 32-bit systems.Vladimir Homutov2018-12-25
|
* Win32: removed NGX_DIR_MASK concept.Maxim Dounin2018-12-24
| | | | | | | | | | | | 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.
* Userid: using stub for AF_UNIX addresses.Sergey Kandaurov2018-12-24
| | | | | Previously, AF_UNIX addresses misbehaved as AF_INET, which typically resulted in $uid_set composed from the middle of sun_path.
* SSL: avoid reading on pending SSL_write_early_data().Sergey Kandaurov2018-12-18
| | | | | | | | | 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.
* Geo: fixed handling of AF_UNIX client addresses (ticket #1684).Maxim Dounin2018-12-14
| | | | | Previously, AF_UNIX client addresses were handled as AF_INET, leading to unexpected results.
* Upstream: implemented $upstream_bytes_sent.Ruslan Ermilov2018-12-13
|
* Resolver: report SRV resolve failure if all A resolves failed.Roman Arutyunyan2018-12-11
| | | | | | | | | | 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.
* Copy regex unnamed captures to cloned subrequests.Roman Arutyunyan2018-12-11
| | | | | | | | | | | | 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.
* Version bump.Roman Arutyunyan2018-12-11
|
* Negative size buffers detection.Maxim Dounin2018-11-26
| | | | | | | | | | 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.
* Mp4: fixed possible pointer overflow on 32-bit platforms.Maxim Dounin2018-11-21
| | | | | | | | | | | 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.
* Limit req: "delay=" parameter.Maxim Dounin2018-11-21
| | | | | | | | | | | 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).
* Limit req: fixed error message wording.Maxim Dounin2018-11-21
|
* Upstream: revised upstream response time variables.Vladimir Homutov2018-11-21
| | | | | | | | | 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.
* Upstream: removed unused ngx_http_upstream_t.timeout field.Vladimir Homutov2018-11-21
|
* Core: ngx_explicit_memzero().Maxim Dounin2018-11-15
|
* Core: free shared memory on cycle initialization failure.Ruslan Ermilov2018-11-15
|
* Stream: proxy_requests directive.Vladimir Homutov2018-11-12
| | | | | | | | | | | 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).
* Stream: session completion check code moved to a separate function.Vladimir Homutov2018-11-12
| | | | | The code refactored to simplify the ngx_stream_proxy_process() function and facilitate adding new session termination conditions.
* Stream: fixed possible use of a freed connection.Vladimir Homutov2018-11-07
| | | | | The session handler may result in session termination, thus a connection pool (from which c->udp was allocated) may be destroyed.
* Version bump.Vladimir Homutov2018-11-13
|
* gRPC: limited allocations due to ping and settings frames.Maxim Dounin2018-11-06
|
* HTTP/2: limit the number of idle state switches.Ruslan Ermilov2018-11-06
| | | | | | | | | | | | | | 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.
* HTTP/2: flood detection.Ruslan Ermilov2018-11-06
| | | | | | 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.
* Mp4: fixed reading 64-bit atoms.Roman Arutyunyan2018-11-06
| | | | | | | | 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.
* Cache: improved keys zone size error reporting.Maxim Dounin2018-10-31
| | | | | After this change, too small keys zones are explicitly reported as such, much like in the other modules which use shared memory.
* Cache: fixed minimum cache keys zone size limit.Maxim Dounin2018-10-31
| | | | | | | | | | | | | | | | | 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.
* A minor code clean for macro ngx_event_get_conf in ngx_event.h.chronolaw2018-10-19
|
* SSL: explicitly set maximum version (ticket #1654).Maxim Dounin2018-10-23
| | | | | | 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).
* Upstream: proxy_socket_keepalive and friends.Vladimir Homutov2018-10-03
| | | | | The directives enable the use of the SO_KEEPALIVE option on upstream connections. By default, the value is left unchanged.
* Version bump.Vladimir Homutov2018-10-03
|
* SSL: fixed segfault on renegotiation (ticket #1646).Maxim Dounin2018-10-02
| | | | | | | | | | | | | | | 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.
* Fixed off-by-one error in shared zone initialization.Ruslan Ermilov2018-10-02
| | | | | On systems without atomic ops, not enough space was allocated for mutex's file name during shared zone initialization.
* SSL: fixed unlocked access to sess_id->len.Ruslan Ermilov2018-09-25
|
* Version bump.Ruslan Ermilov2018-09-27
|
* SSL: logging level of "no suitable signature algorithm".Maxim Dounin2018-09-25
| | | | | | | | | | | | | | | | | | 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.
* SSL: logging level of "no suitable key share".Maxim Dounin2018-09-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The "no suitable key share" errors are reported by OpenSSL 1.1.1 when using TLSv1.3 if there are no shared groups (that is, elliptic curves). In particular, it is easy enough to trigger by using only a single curve in ssl_ecdh_curve: ssl_ecdh_curve secp384r1; and using a different curve in the client: openssl s_client -connect 127.0.0.1:443 -curves prime256v1 On the client side it is seen as "sslv3 alert handshake failure", "SSL alert number 40": 0:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:ssl/record/rec_layer_s3.c:1528:SSL alert number 40 It can be also triggered with default ssl_ecdh_curve by using a curve which is not in the default list (X25519, prime256v1, X448, secp521r1, secp384r1): openssl s_client -connect 127.0.0.1:8443 -curves brainpoolP512r1 Given that many clients hardcode prime256v1, these errors might become a common problem with TLSv1.3 if ssl_ecdh_curve is redefined. Previously this resulted in not using ECDH with such clients, but with TLSv1.3 it is no longer possible and will result in a handshake failure. The SSL_R_NO_SHARED_GROUP error is what BoringSSL returns in the same situation. Seen at: https://serverfault.com/questions/932102/nginx-ssl-handshake-error-no-suitable-key-share
* Cache: status must be less then 599 in *_cache_valid directives.Gena Makhomed2018-09-24
| | | | | | | | | Previously, configurations with typo, for example fastcgi_cache_valid 200301 302 5m; successfully pass configuration test. Adding check for status codes > 599, and such configurations are now properly rejected.
* Removed bgcolor attribute on body in error pages and autoindex.Nova DasSarma2018-09-19
| | | | | | The bgcolor attribute overrides compatibility settings in browsers and leads to undesirable behavior when the default font color is set to white in the browser, since font-color is not also overridden.
* SSL: support for TLSv1.3 early data with OpenSSL.Sergey Kandaurov2018-09-21
| | | | In collaboration with Maxim Dounin.
* SSL: disabled renegotiation checks with SSL_OP_NO_RENEGOTIATION.Maxim Dounin2018-09-21
| | | | | | | | | | | | Following 7319:dcab86115261, as long as SSL_OP_NO_RENEGOTIATION is defined, it is OpenSSL library responsibility to prevent renegotiation, so the checks are meaningless. Additionally, with TLSv1.3 OpenSSL tends to report SSL_CB_HANDSHAKE_START at various unexpected moments - notably, on KeyUpdate messages and when sending tickets. This change prevents unexpected connection close on KeyUpdate messages and when finishing handshake with upcoming early data changes.
* Rewrite: removed r->err_status special handling (ticket #1634).Maxim Dounin2018-09-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Trying to look into r->err_status in the "return" directive makes it behave differently than real errors generated in other parts of the code, and is an endless source of various problems. This behaviour was introduced in 726:7b71936d5299 (0.4.4) with the comment "fix: "return" always overrode "error_page" response code". It is not clear if there were any real cases this was expected to fix, but there are several cases which are broken due to this change, some previously fixed (4147:7f64de1cc2c0). In ticket #1634, the problem is that when r->err_status is set to a non-special status code, it is not possible to return a response by simply returning r->err_status. If this is the case, the only option is to return script's e->status instead. An example configuration: location / { error_page 404 =200 /err502; return 404; } location = /err502 { return 502; } After the change, such a configuration will properly return standard 502 error, much like it happens when a 502 error is generated by proxy_pass. This also fixes the following configuration to properly close connection as clearly requested by "return 444": location / { error_page 404 /close; return 404; } location = /close { return 444; } Previously, this required "error_page 404 = /close;" to work as intended.
* Fixed socket leak with "return 444" in error_page (ticket #274).Maxim Dounin2018-09-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Socket leak was observed in the following configuration: error_page 400 = /close; location = /close { return 444; } The problem is that "return 444" triggers termination of the request, and due to error_page termination thinks that it needs to use a posted request to clear stack. But at the early request processing where 400 errors are generated there are no ngx_http_run_posted_requests() calls, so the request is only terminated after an external event. Variants of the problem include "error_page 497" instead (ticket #695) and various other errors generated during early request processing (405, 414, 421, 494, 495, 496, 501, 505). The same problem can be also triggered with "return 499" and "return 408" as both codes trigger ngx_http_terminate_request(), much like "return 444". To fix this, the patch adds ngx_http_run_posted_requests() calls to ngx_http_process_request_line() and ngx_http_process_request_headers() functions, and to ngx_http_v2_run_request() and ngx_http_v2_push_stream() functions in HTTP/2. Since the ngx_http_process_request() function is now only called via other functions which call ngx_http_run_posted_requests(), the call there is no longer needed and was removed.
* SSL: restore handlers after blocking.Maxim Dounin2018-09-10
| | | | | | | | | | | It is possible that after SSL_read() will return SSL_ERROR_WANT_WRITE, further calls will return SSL_ERROR_WANT_READ without reading any application data. We have to call ngx_handle_write_event() and switch back to normal write handling much like we do if there are some application data, or the write there will be reported again and again. Similarly, we have to switch back to normal read handling if there is saved read handler and SSL_write() returns SSL_ERROR_WANT_WRITE.
* SSL: corrected SSL_ERROR_WANT_WRITE / SSL_ERROR_WANT_READ logging.Maxim Dounin2018-09-10
| | | | | | | | | | | | | | | | While SSL_read() most likely to return SSL_ERROR_WANT_WRITE (and SSL_write() accordingly SSL_ERROR_WANT_READ) during an SSL renegotiation, it is not necessary mean that a renegotiation was started. In particular, it can never happen during a renegotiation or can happen multiple times during a renegotiation. Because of the above, misleading "peer started SSL renegotiation" info messages were replaced with "SSL_read: want write" and "SSL_write: want read" debug ones. Additionally, "SSL write handler" and "SSL read handler" are now logged by the SSL write and read handlers, to make it easier to understand that temporary SSL handlers are called instead of normal handlers.
* Lingering close changed to handle NGX_AGAIN.Maxim Dounin2018-09-10
| | | | | | | | | | | | | The "do { c->recv() } while (c->read->ready)" form used in the ngx_http_lingering_close_handler() is not really correct, as for example with SSL c->read->ready may be still set when returning NGX_AGAIN due to SSL_ERROR_WANT_WRITE. Therefore the above might be an infinite loop. This doesn't really matter in lingering close, as we shutdown write side of the socket anyway and also disable renegotiation (and even without shutdown and with renegotiation it requires using very large certificate chain and tuning socket buffers to trigger SSL_ERROR_WANT_WRITE). But for the sake of correctness added an NGX_AGAIN check.