@@ -6690,7 +6690,7 @@ static const char *wsgi_add_daemon_process(cmd_parms *cmd, void *mconfig,
66906690 group_name = ap_getword (cmd -> pool , & items , ',' );
66916691
66926692 while (group_name && * group_name ) {
6693- if (groups_count > groups_maximum )
6693+ if (groups_count >= groups_maximum )
66946694 return "Too many supplementary groups WSGI daemon process" ;
66956695
66966696 groups [groups_count ++ ] = ap_gname2id (group_name );
@@ -7087,7 +7087,7 @@ static void wsgi_setup_daemon_name(WSGIDaemonProcess *daemon, apr_pool_t *p)
70877087#endif
70887088}
70897089
7090- static void wsgi_setup_access (WSGIDaemonProcess * daemon )
7090+ static int wsgi_setup_access (WSGIDaemonProcess * daemon )
70917091{
70927092 /* Setup the umask for the effective user. */
70937093
@@ -7101,6 +7101,8 @@ static void wsgi_setup_access(WSGIDaemonProcess *daemon)
71017101 ap_log_error (APLOG_MARK , APLOG_ALERT , errno , wsgi_server ,
71027102 "mod_wsgi (pid=%d): Unable to change root "
71037103 "directory to '%s'." , getpid (), daemon -> group -> root );
7104+
7105+ return -1 ;
71047106 }
71057107 }
71067108
@@ -7111,6 +7113,8 @@ static void wsgi_setup_access(WSGIDaemonProcess *daemon)
71117113 ap_log_error (APLOG_MARK , APLOG_ALERT , errno , wsgi_server ,
71127114 "mod_wsgi (pid=%d): Unable to change working "
71137115 "directory to '%s'." , getpid (), daemon -> group -> home );
7116+
7117+ return -1 ;
71147118 }
71157119 }
71167120 else if (geteuid ()) {
@@ -7123,12 +7127,16 @@ static void wsgi_setup_access(WSGIDaemonProcess *daemon)
71237127 ap_log_error (APLOG_MARK , APLOG_ALERT , errno , wsgi_server ,
71247128 "mod_wsgi (pid=%d): Unable to change working "
71257129 "directory to '%s'." , getpid (), pwent -> pw_dir );
7130+
7131+ return -1 ;
71267132 }
71277133 }
71287134 else {
71297135 ap_log_error (APLOG_MARK , APLOG_ALERT , errno , wsgi_server ,
71307136 "mod_wsgi (pid=%d): Unable to determine home "
71317137 "directory for uid=%ld." , getpid (), (long )geteuid ());
7138+
7139+ return -1 ;
71327140 }
71337141 }
71347142 else {
@@ -7141,27 +7149,33 @@ static void wsgi_setup_access(WSGIDaemonProcess *daemon)
71417149 ap_log_error (APLOG_MARK , APLOG_ALERT , errno , wsgi_server ,
71427150 "mod_wsgi (pid=%d): Unable to change working "
71437151 "directory to '%s'." , getpid (), pwent -> pw_dir );
7152+
7153+ return -1 ;
71447154 }
71457155 }
71467156 else {
71477157 ap_log_error (APLOG_MARK , APLOG_ALERT , errno , wsgi_server ,
71487158 "mod_wsgi (pid=%d): Unable to determine home "
71497159 "directory for uid=%ld." , getpid (),
71507160 (long )daemon -> group -> uid );
7161+
7162+ return -1 ;
71517163 }
71527164 }
71537165
71547166 /* Don't bother switch user/group if not root. */
71557167
71567168 if (geteuid ())
7157- return ;
7169+ return 0 ;
71587170
71597171 /* Setup the daemon process real and effective group. */
71607172
71617173 if (setgid (daemon -> group -> gid ) == -1 ) {
71627174 ap_log_error (APLOG_MARK , APLOG_ALERT , errno , wsgi_server ,
71637175 "mod_wsgi (pid=%d): Unable to set group id to gid=%u." ,
71647176 getpid (), (unsigned )daemon -> group -> gid );
7177+
7178+ return -1 ;
71657179 }
71667180 else {
71677181 if (daemon -> group -> groups ) {
@@ -7172,13 +7186,17 @@ static void wsgi_setup_access(WSGIDaemonProcess *daemon)
71727186 "to set supplementary groups for uname=%s "
71737187 "of '%s'." , getpid (), daemon -> group -> user ,
71747188 daemon -> group -> groups_list );
7189+
7190+ return -1 ;
71757191 }
71767192 }
71777193 else if (initgroups (daemon -> group -> user , daemon -> group -> gid ) == -1 ) {
71787194 ap_log_error (APLOG_MARK , APLOG_ALERT , errno ,
71797195 wsgi_server , "mod_wsgi (pid=%d): Unable "
71807196 "to set groups for uname=%s and gid=%u." , getpid (),
71817197 daemon -> group -> user , (unsigned )daemon -> group -> gid );
7198+
7199+ return -1 ;
71827200 }
71837201 }
71847202
@@ -7196,8 +7214,19 @@ static void wsgi_setup_access(WSGIDaemonProcess *daemon)
71967214 * reached their process limit. In that case will be left
71977215 * running as wrong user. Just exit on all failures to be
71987216 * safe. Don't die immediately to avoid a fork bomb.
7217+ *
7218+ * We could just return -1 here and let the caller do the
7219+ * sleep() and exit() but this failure is critical enough
7220+ * that we still do it here so it is obvious that the issue
7221+ * is being addressed.
71997222 */
72007223
7224+ ap_log_error (APLOG_MARK , APLOG_ALERT , 0 , wsgi_server ,
7225+ "mod_wsgi (pid=%d): Failure to configure the "
7226+ "daemon process correctly and process left in "
7227+ "unspecified state. Restarting daemon process "
7228+ "after delay." , getpid ());
7229+
72017230 sleep (20 );
72027231
72037232 exit (-1 );
@@ -7219,6 +7248,8 @@ static void wsgi_setup_access(WSGIDaemonProcess *daemon)
72197248 }
72207249 }
72217250#endif
7251+
7252+ return 0 ;
72227253}
72237254
72247255static int wsgi_setup_socket (WSGIProcessGroup * process )
@@ -8561,7 +8592,24 @@ static int wsgi_start_process(apr_pool_t *p, WSGIDaemonProcess *daemon)
85618592
85628593 /* Setup daemon process user/group/umask etc. */
85638594
8564- wsgi_setup_access (daemon );
8595+ if (wsgi_setup_access (daemon ) == -1 ) {
8596+ /*
8597+ * If we get any failure from setting up the appropriate
8598+ * permissions or working directory for the daemon process
8599+ * then we exit the process. Don't die immediately to avoid
8600+ * a fork bomb.
8601+ */
8602+
8603+ ap_log_error (APLOG_MARK , APLOG_ALERT , 0 , wsgi_server ,
8604+ "mod_wsgi (pid=%d): Failure to configure the "
8605+ "daemon process correctly and process left in "
8606+ "unspecified state. Restarting daemon process "
8607+ "after delay." , getpid ());
8608+
8609+ sleep (20 );
8610+
8611+ exit (-1 );
8612+ }
85658613
85668614 /* Reinitialise accept mutex in daemon process. */
85678615
0 commit comments