Skip to content

Commit 06c7c36

Browse files
author
Jerome Loyet
committed
- Fixed bug #61835 (php-fpm is not allowed to run as root)
1 parent 8475c5b commit 06c7c36

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ PHP NEWS
5656

5757
- FPM
5858
. Fixed bug #61045 (fpm don't send error log to fastcgi clients). (fat)
59+
. Fixed bug #61835 (php-fpm is not allowed to run as root). (fat)
5960

6061
- Libxml:
6162
. Fixed bug #61617 (Libxml tests failed(ht is already destroyed)).

sapi/fpm/fpm/fpm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ struct fpm_globals_s fpm_globals = {
3737
.max_requests = 0,
3838
.is_child = 0,
3939
.test_successful = 0,
40-
.heartbeat = 0
40+
.heartbeat = 0,
41+
.run_as_root = 0,
4142
};
4243

43-
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf) /* {{{ */
44+
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root) /* {{{ */
4445
{
4546
fpm_globals.argc = argc;
4647
fpm_globals.argv = argv;
@@ -49,6 +50,7 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t
4950
}
5051
fpm_globals.prefix = prefix;
5152
fpm_globals.pid = pid;
53+
fpm_globals.run_as_root = run_as_root;
5254

5355
if (0 > fpm_php_init_main() ||
5456
0 > fpm_stdio_init_main() ||

sapi/fpm/fpm/fpm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <unistd.h>
99

1010
int fpm_run(int *max_requests);
11-
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf);
11+
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root);
1212

1313
struct fpm_globals_s {
1414
pid_t parent_pid;
@@ -25,6 +25,7 @@ struct fpm_globals_s {
2525
int is_child;
2626
int test_successful;
2727
int heartbeat;
28+
int run_as_root;
2829
};
2930

3031
extern struct fpm_globals_s fpm_globals;

sapi/fpm/fpm/fpm_main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ static const opt_struct OPTIONS[] = {
154154
{'t', 0, "test"},
155155
{'p', 1, "prefix"},
156156
{'g', 1, "pid"},
157+
{'R', 0, "allow-to-run-as-root"},
157158
{'-', 0, NULL} /* end of args */
158159
};
159160

@@ -927,6 +928,8 @@ static void php_cgi_usage(char *argv0)
927928
" -y, --fpm-config <file>\n"
928929
" Specify alternative path to FastCGI process manager config file.\n"
929930
" -t, --test Test FPM configuration and exit\n",
931+
" -R, allow-to-run-as-root\n"
932+
" Allow pool to run as root (disabled by default)\n",
930933
prog, PHP_PREFIX);
931934
}
932935
/* }}} */
@@ -1548,6 +1551,7 @@ int main(int argc, char *argv[])
15481551
char *fpm_pid = NULL;
15491552
int test_conf = 0;
15501553
int php_information = 0;
1554+
int php_allow_to_run_as_root = 0;
15511555

15521556
#ifdef HAVE_SIGNAL_H
15531557
#if defined(SIGPIPE) && defined(SIG_IGN)
@@ -1662,6 +1666,10 @@ int main(int argc, char *argv[])
16621666
php_information = 1;
16631667
break;
16641668

1669+
case 'R': /* allow to run as root */
1670+
php_allow_to_run_as_root = 1;
1671+
break;
1672+
16651673
default:
16661674
case 'h':
16671675
case '?':
@@ -1789,7 +1797,7 @@ consult the installation file that came with this distribution, or visit \n\
17891797
}
17901798
}
17911799

1792-
if (0 > fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf)) {
1800+
if (0 > fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root)) {
17931801
return FAILURE;
17941802
}
17951803

sapi/fpm/fpm/fpm_unix.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */
112112
}
113113
}
114114

115-
#ifndef I_REALLY_WANT_ROOT_PHP
116-
if (wp->set_uid == 0 || wp->set_gid == 0) {
117-
zlog(ZLOG_ERROR, "[pool %s] please specify user and group other than root", wp->config->name);
118-
return -1;
115+
if (!fpm_globals.run_as_root) {
116+
if (wp->set_uid == 0 || wp->set_gid == 0) {
117+
zlog(ZLOG_ERROR, "[pool %s] please specify user and group other than root", wp->config->name);
118+
return -1;
119+
}
119120
}
120-
#endif
121121
} else { /* not root */
122122
if (wp->config->user && *wp->config->user) {
123123
zlog(ZLOG_WARNING, "[pool %s] 'user' directive is ignored when FPM is not running as root", wp->config->name);

0 commit comments

Comments
 (0)