]> granicus.if.org Git - apache/commitdiff
SECURITY (CVE-2014-0231): Fix for DoS due to hang waiting for CGI script.
authorEric Covener <covener@apache.org>
Wed, 23 Oct 2013 19:26:08 +0000 (19:26 +0000)
committerEric Covener <covener@apache.org>
Wed, 23 Oct 2013 19:26:08 +0000 (19:26 +0000)
Patch one of two.

Permit a read timeout to be used in mod_cgid to give up on a slow CGI script.

In trunk, it defaults to the servers Timeout.  PR43494

Submitted By: Eric Covener, Toshikuni Fukaya
Reviewed By: Eric Covener

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1535125 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/log-message-tags/next-number
docs/manual/mod/core.xml
docs/manual/mod/mod_cgid.xml
docs/manual/upgrading.xml
modules/generators/mod_cgid.c

diff --git a/CHANGES b/CHANGES
index d77d03ef095f6582ab1821969c7326f0c44c2ab0..43aae403687ec441207b1d3083751e8a6e51d96c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,13 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) mod_cgid: Use the servers Timeout for each read from a CGI script,
+     allow override with new CGIDRequestTimeout directive. PR43494
+     [Eric Covener, Toshikuni Fukaya <toshikuni-fukaya cybozu co jp>]
+
+  *) core: Add missing Reason-Phrase in HTTP response headers.
+     PR 54946. [Rainer Jung]
+
   *) core: ensure any abnormal exit is reported to stderr if it's a tty.
      PR 55670 [Nick Kew]
 
index 5cf23a56c5b190e38426e25a4681192eaee50024..668cebd7cd89862d6c925b8b43fe2c9ab91e3be0 100644 (file)
@@ -1 +1 @@
-2548
+2551
index ecd588653dad71226266b5325c43ee14849ac17c..ef194c6a1911dec83a2f37231db468c56c849094 100644 (file)
@@ -4164,8 +4164,8 @@ certain events before failing a request</description>
       for an acknowledgement of a packet if the send buffer is
       full.</li>
 
-      <li>In <module>mod_cgi</module>, the length of time to wait for
-      output from a CGI script.</li>
+      <li>In <module>mod_cgi</module> and <module>mod_cgid</module>, 
+      the length of time to wait for output from a CGI script.</li>
 
       <li>In <module>mod_ext_filter</module>, the length of time to
       wait for output from a filtering process.</li>
index d49bcc2a724415cef704189a43a9768196b175b6..a901ebb5d01f47ee10179c481e8dd578deeaf654 100644 (file)
@@ -102,5 +102,32 @@ the cgi daemon</description>
 </usage>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>CGIDScriptTimeout</name>
+<description>The length of time to wait for more output from the
+CGI program</description>
+<syntax>CGIDScriptTimeout <var>time</var>[s|ms]</syntax>
+<default>value of <directive module="core">Timeout</directive> directive when 
+unset</default>
+<contextlist><context>server config</context>
+<context>virtual host</context><context>directory</context>
+<context>.htaccess</context></contextlist>
+<compatibility>CGIDScriptTimeout defaults to zero in releases 2.4 and earlier
+</compatibility>
+
+<usage>
+    <p>This directive limits the length of time to wait for more output from
+    the CGI program.  If the time is exceeded, the request and CGI are 
+    terminated.</p>
+
+    <example><title>Example</title>
+    <highlight language="config">
+      CGIDScriptTimeout 20
+    </highlight>
+    </example>
+
+</usage>
+</directivesynopsis>
+
 </modulesynopsis>
 
index 936d61800c12bcd289155dfbfce4456f685f8e97..e2653e410ac04c330dc721f5f0586a6896beb02f 100644 (file)
@@ -360,6 +360,12 @@ Allow from example.org
       has been moved into <module>mod_authn_core</module>.  
       </li>
 
+      <li><module>mod_cgid</module> uses the servers <directive module="core"
+      >Timeout</directive> to limit the length of time to wait for CGI output.
+      This timeout can be overridden with <directive module="mod_cgid">
+      CGIDScriptTImeout</directive>.
+      </li>
+
     </ul>
 
   </section>
index 07c31930e5b81ff41084e4771af818fb5d083afe..71e2b32eb1c9a54829fe4359ffe9092b74830e0a 100644 (file)
@@ -98,6 +98,10 @@ static apr_socklen_t server_addr_len;
 static pid_t parent_pid;
 static ap_unix_identity_t empty_ugid = { (uid_t)-1, (gid_t)-1, -1 };
 
+typedef struct { 
+    apr_interval_time_t timeout;
+} cgid_dirconf;
+
 /* The APR other-child API doesn't tell us how the daemon exited
  * (SIGSEGV vs. exit(1)).  The other-child maintenance function
  * needs to decide whether to restart the daemon after a failure
@@ -973,7 +977,14 @@ static void *merge_cgid_config(apr_pool_t *p, void *basev, void *overridesv)
     return overrides->logname ? overrides : base;
 }
 
+static void *create_cgid_dirconf(apr_pool_t *p, char *dummy)
+{
+    cgid_dirconf *c = (cgid_dirconf *) apr_pcalloc(p, sizeof(cgid_dirconf));
+    return c;
+}
+
 static const char *set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg)
+
 {
     server_rec *s = cmd->server;
     cgid_server_conf *conf = ap_get_module_config(s->module_config,
@@ -1026,7 +1037,16 @@ static const char *set_script_socket(cmd_parms *cmd, void *dummy, const char *ar
 
     return NULL;
 }
+static const char *set_script_timeout(cmd_parms *cmd, void *dummy, const char *arg)
+{
+    cgid_dirconf *dc = dummy;
 
+    if (ap_timeout_parameter_parse(arg, &dc->timeout, "s") != APR_SUCCESS) { 
+        return "CGIDScriptTimeout has wrong format";
+    }
+    return NULL;
+}
 static const command_rec cgid_cmds[] =
 {
     AP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF,
@@ -1038,6 +1058,10 @@ static const command_rec cgid_cmds[] =
     AP_INIT_TAKE1("ScriptSock", set_script_socket, NULL, RSRC_CONF,
                   "the name of the socket to use for communication with "
                   "the cgi daemon."),
+    AP_INIT_TAKE1("CGIDScriptTimeout", set_script_timeout, NULL, RSRC_CONF | ACCESS_CONF,
+                  "The amount of time to wait between successful reads from "
+                  "the CGI script, in seconds."),
+                  
     {NULL}
 };
 
@@ -1361,12 +1385,16 @@ static int cgid_handler(request_rec *r)
     apr_file_t *tempsock;
     struct cleanup_script_info *info;
     apr_status_t rv;
+    cgid_dirconf *dc;
 
     if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) {
         return DECLINED;
     }
 
     conf = ap_get_module_config(r->server->module_config, &cgid_module);
+    dc = ap_get_module_config(r->per_dir_config, &cgid_module);
+
+    
     is_included = !strcmp(r->protocol, "INCLUDED");
 
     if ((argv0 = strrchr(r->filename, '/')) != NULL) {
@@ -1446,6 +1474,12 @@ static int cgid_handler(request_rec *r)
      */
 
     apr_os_pipe_put_ex(&tempsock, &sd, 1, r->pool);
+    if (dc->timeout > 0) { 
+        apr_file_pipe_timeout_set(tempsock, dc->timeout);
+    }
+    else { 
+        apr_file_pipe_timeout_set(tempsock, r->server->timeout);
+    }
     apr_pool_cleanup_kill(r->pool, (void *)((long)sd), close_unix_socket);
 
     /* Transfer any put/post args, CERN style...
@@ -1615,7 +1649,13 @@ static int cgid_handler(request_rec *r)
             return HTTP_MOVED_TEMPORARILY;
         }
 
-        ap_pass_brigade(r->output_filters, bb);
+        rv = ap_pass_brigade(r->output_filters, bb);
+        if (rv != APR_SUCCESS) { 
+            /* APLOG_ERR because the core output filter message is at error,
+             * but doesn't know it's passing CGI output 
+             */
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02550) "Failed to flush CGI output to client");
+        }
     }
 
     if (nph) {
@@ -1880,7 +1920,7 @@ static void register_hook(apr_pool_t *p)
 
 AP_DECLARE_MODULE(cgid) = {
     STANDARD20_MODULE_STUFF,
-    NULL, /* dir config creater */
+    create_cgid_dirconf, /* dir config creater */
     NULL, /* dir merger --- default is to override */
     create_cgid_config, /* server config */
     merge_cgid_config, /* merge server config */