You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2019/02/19 18:14:14 UTC

svn commit: r1853906 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_reqtimeout.xml modules/filters/mod_reqtimeout.c

Author: ylavic
Date: Tue Feb 19 18:14:13 2019
New Revision: 1853906

URL: http://svn.apache.org/viewvc?rev=1853906&view=rev
Log:
mod_reqtimeout: Allow to configure (TLS-)handshake timeouts.

The timeouts apply between the process_connection and pre_read_request hooks.
They are disabled by default for compatibily reasons.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/mod_reqtimeout.xml
    httpd/httpd/trunk/modules/filters/mod_reqtimeout.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1853906&r1=1853905&r2=1853906&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Tue Feb 19 18:14:13 2019
@@ -1,5 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.1
+
+  *) mod_reqtimeout: Allow to configure (TLS-)handshake timeouts.
+     PR 61310. [Yann Ylavic]
+
   *) mod_auth_digest: Fix a race condition. Authentication with valid credentials could be
      refused in case of concurrent accesses from different users.
      PR 63124 [Simon Kappel <simon.kappel axis.com>]

Modified: httpd/httpd/trunk/docs/manual/mod/mod_reqtimeout.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_reqtimeout.xml?rev=1853906&r1=1853905&r2=1853906&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_reqtimeout.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_reqtimeout.xml Tue Feb 19 18:14:13 2019
@@ -48,11 +48,12 @@
 
     <ol>
       <li>
-        Allow 10 seconds to receive the request including the headers and
-        30 seconds for receiving the request body:
+        Allow for 5 seconds to complete the TLS handshake, 10 seconds to
+        receive the request headers and 30 seconds for receiving the
+        request body:
 
         <highlight language="config">
-          RequestReadTimeout header=10 body=30
+          RequestReadTimeout handshake=5 header=10 body=30
         </highlight>
       </li>
 
@@ -69,10 +70,10 @@
       </li>
 
       <li>
-        Allow at least 10 seconds to receive the request including the headers.
+        Allow at least 10 seconds to receive the request headers.
         If the client sends data, increase the timeout by 1 second for every
         500 bytes received. But do not allow more than 30 seconds for the
-        request including the headers:
+        request headers:
 
         <highlight language="config">
           RequestReadTimeout header=10-30,MinRate=500
@@ -94,65 +95,69 @@
 
 <directivesynopsis>
 <name>RequestReadTimeout</name>
-<description>Set timeout values for receiving request headers and body from client.
+<description>Set timeout values for completing the TLS handshake, receiving
+the request headers and/or body from client.
 </description>
 <syntax>RequestReadTimeout
+[handshake=<var>timeout</var>[-<var>maxtimeout</var>][,MinRate=<var>rate</var>]
 [header=<var>timeout</var>[-<var>maxtimeout</var>][,MinRate=<var>rate</var>]
 [body=<var>timeout</var>[-<var>maxtimeout</var>][,MinRate=<var>rate</var>]
 </syntax>
-<default>RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500</default>
+<default>RequestReadTimeout handshake=0 header=20-40,MinRate=500 body=20,MinRate=500</default>
 <contextlist><context>server config</context><context>virtual host</context>
 </contextlist>
-<compatibility>Defaulted to disabled in
-version 2.3.14 and earlier.</compatibility>
+<compatibility>Defaulted to disabled in version 2.3.14 and earlier. The
+<code>handshake</code> stage is available since version 2.5.
+</compatibility>
 
 <usage>
-    <p>This directive can set various timeouts for receiving the request headers
-    and the request body from the client. If the client fails to send headers or
-    body within the configured time, a <code>408 REQUEST TIME OUT</code> error
-    is sent.</p>
+    <p>This directive can set various timeouts for completing the TLS handshake,
+    receiving the request headers and/or the request body from the client.
+    If the client fails to complete each of these stages within the configured
+    time, a <code>408 REQUEST TIME OUT</code> error is sent.</p>
 
-    <p>For SSL virtual hosts, the header timeout values include the time needed
-    to do the initial SSL handshake.  If the user's browser is configured to
+    <p>For SSL virtual hosts, the <code>handshake</code> timeout values is the time
+    needed to do the initial SSL handshake.  If the user's browser is configured to
     query certificate revocation lists and the CRL server is not reachable, the
     initial SSL handshake may take a significant time until the browser gives up
-    waiting for the CRL.  Therefore the header timeout values should not be set
-    to very low values for SSL virtual hosts.
+    waiting for the CRL.  Therefore the <code>handshake</code> timeout should take
+    this possible overhead into consideration for SSL virtual hosts (if necessary).
     The body timeout values include the time needed for SSL renegotiation
     (if necessary).</p>
 
     <p>When an <directive module="core">AcceptFilter</directive> is in use
     (usually the case on Linux and FreeBSD), the socket is not sent to the
     server process before at least one byte (or the whole request for
-    <code>httpready</code>) is received. The header timeout configured with
-    <directive>RequestReadTimeout</directive> is only effective after the server process has
-    received the socket.</p>
+    <code>httpready</code>) is received. The handshake and header timeouts
+    configured with <directive>RequestReadTimeout</directive> are only effective
+    after the server process has received the socket.</p>
 
-    <p>For each of the two timeout types (header or body), there are three ways
-    to specify the timeout:
+    <p>For each of the three timeout stages (handshake, header or body), there are
+    three ways to specify the timeout:
     </p>
 
     <ul>
 
     <li><strong>Fixed timeout value</strong>:<br />
 
-    <example><var>type</var>=<var>timeout</var></example>
+    <example><var>stage</var>=<var>timeout</var></example>
 
-    <p>The time in seconds allowed for reading all of the request headers or
-    body, respectively. A value of 0 means no limit.</p>
+    <p>The time in seconds allowed for completing the whole stage (handshaking,
+    reading all of the request headers or body). A value of 0 means no limit.</p>
     </li>
 
     <li><strong>Disable module for a vhost</strong>:<br />
 
-    <example>header=0 body=0</example>
+    <example>handshake=0 header=0 body=0</example>
 
-    <p>This disables <module>mod_reqtimeout</module> completely.</p>
+    <p>This disables <module>mod_reqtimeout</module> completely (note that
+    <code>handshake=0</code> is the default already and could be omitted).</p>
     </li>
 
     <li><strong>Timeout value that is increased when data is
     received</strong>:<br />
     <example>
-    <var>type</var>=<var>timeout</var>,MinRate=<var>data_rate</var>
+    <var>stage</var>=<var>timeout</var>,MinRate=<var>data_rate</var>
     </example>
 
     <p>Same as above, but whenever data is received, the timeout value is
@@ -163,7 +168,7 @@ version 2.3.14 and earlier.</compatibili
     <li><strong>Timeout value that is increased when data is received, with an
     upper bound</strong>:<br />
     <example>
-    <var>type</var>=<var>timeout</var>-<var>maxtimeout</var>,MinRate=<var>data_rate</var>
+    <var>stage</var>=<var>timeout</var>-<var>maxtimeout</var>,MinRate=<var>data_rate</var>
     </example>
 
     <p>Same as above, but the timeout will not be increased above the second

Modified: httpd/httpd/trunk/modules/filters/mod_reqtimeout.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_reqtimeout.c?rev=1853906&r1=1853905&r2=1853906&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/filters/mod_reqtimeout.c (original)
+++ httpd/httpd/trunk/modules/filters/mod_reqtimeout.c Tue Feb 19 18:14:13 2019
@@ -29,6 +29,9 @@
 module AP_MODULE_DECLARE_DATA reqtimeout_module;
 
 #define UNSET                            -1
+#define MRT_DEFAULT_handshake_TIMEOUT     0 /* disabled */
+#define MRT_DEFAULT_handshake_MAX_TIMEOUT 0
+#define MRT_DEFAULT_handshake_MIN_RATE    APR_INT32_MAX
 #define MRT_DEFAULT_header_TIMEOUT       20
 #define MRT_DEFAULT_header_MAX_TIMEOUT   40
 #define MRT_DEFAULT_header_MIN_RATE      500
@@ -46,6 +49,7 @@ typedef struct
 
 typedef struct
 {
+    reqtimeout_stage_t handshake;   /* Handshaking (TLS) */
     reqtimeout_stage_t header;      /* Reading the HTTP header */
     reqtimeout_stage_t body;        /* Reading the HTTP body */
 } reqtimeout_srv_cfg;
@@ -63,6 +67,7 @@ typedef struct
 } reqtimeout_con_cfg;
 
 static const char *const reqtimeout_filter_name = "reqtimeout";
+static int default_handshake_rate_factor;
 static int default_header_rate_factor;
 static int default_body_rate_factor;
 
@@ -372,7 +377,10 @@ static int reqtimeout_init(conn_rec *c)
                                &reqtimeout_module);
     AP_DEBUG_ASSERT(cfg != NULL);
 
-    if (cfg->header.timeout == 0 && cfg->body.timeout == 0) {
+    /* For compatibility, handshake timeout is disabled when UNSET (< 0) */
+    if (cfg->handshake.timeout <= 0
+            && cfg->header.timeout == 0
+            && cfg->body.timeout == 0) {
         /* disabled for this vhost */
         return DECLINED;
     }
@@ -383,6 +391,10 @@ static int reqtimeout_init(conn_rec *c)
         ap_set_module_config(c->conn_config, &reqtimeout_module, ccfg);
         ap_add_output_filter(reqtimeout_filter_name, ccfg, NULL, c);
         ap_add_input_filter(reqtimeout_filter_name, ccfg, NULL, c);
+
+        if (cfg->handshake.timeout > 0) {
+            INIT_STAGE(cfg, ccfg, handshake);
+        }
     }
 
     /* we are not handling the connection, we just do initialization */
@@ -450,6 +462,7 @@ static void *reqtimeout_create_srv_confi
 {
     reqtimeout_srv_cfg *cfg = apr_pcalloc(p, sizeof(reqtimeout_srv_cfg));
 
+    UNSET_STAGE(cfg, handshake);
     UNSET_STAGE(cfg, header);
     UNSET_STAGE(cfg, body);
 
@@ -473,6 +486,7 @@ static void *reqtimeout_merge_srv_config
     reqtimeout_srv_cfg *add  = add_;
     reqtimeout_srv_cfg *cfg  = apr_pcalloc(p, sizeof(reqtimeout_srv_cfg));
 
+    MERGE_STAGE(cfg, base, add, handshake);
     MERGE_STAGE(cfg, base, add, header);
     MERGE_STAGE(cfg, base, add, body);
 
@@ -505,7 +519,10 @@ static const char *set_reqtimeout_param(
     char *rate_str = NULL, *initial_str, *max_str = NULL;
     reqtimeout_stage_t *stage;
 
-    if (!strcasecmp(key, "header")) {
+    if (!strcasecmp(key, "handshake")) {
+        stage = &conf->handshake;
+    }
+    else if (!strcasecmp(key, "header")) {
         stage = &conf->header;
     }
     else if (!strcasecmp(key, "body")) {
@@ -611,13 +628,17 @@ static void reqtimeout_hooks(apr_pool_t
      * e.g. mod_ftp. Also, if mod_reqtimeout used the pre_connection hook, it
      * would be inserted on mod_proxy's backend connections.
      */
-    ap_hook_process_connection(reqtimeout_init, NULL, NULL, APR_HOOK_LAST);
+    ap_hook_process_connection(reqtimeout_init, NULL, NULL, APR_HOOK_FIRST);
 
     ap_hook_pre_read_request(reqtimeout_before_header, NULL, NULL,
                              APR_HOOK_MIDDLE);
     ap_hook_post_read_request(reqtimeout_before_body, NULL, NULL,
                               APR_HOOK_MIDDLE);
 
+#if MRT_DEFAULT_HANDSHAKE_MIN_RATE > 0
+    default_handshake_rate_factor = apr_time_from_sec(1) /
+                                    MRT_DEFAULT_HANDSHAKE_MIN_RATE;
+#endif
 #if MRT_DEFAULT_HEADER_MIN_RATE > 0
     default_header_rate_factor = apr_time_from_sec(1) /
                                  MRT_DEFAULT_HEADER_MIN_RATE;
@@ -630,8 +651,8 @@ static void reqtimeout_hooks(apr_pool_t
 
 static const command_rec reqtimeout_cmds[] = {
     AP_INIT_RAW_ARGS("RequestReadTimeout", set_reqtimeouts, NULL, RSRC_CONF,
-                     "Set various timeout parameters for reading request "
-                     "headers and body"),
+                     "Set various timeout parameters for TLS handshake and/or "
+                     "reading request headers and body"),
     {NULL}
 };