Skip to content

Commit 7bb2a9f

Browse files
devnexenbukka
authored andcommitted
Add extra check for FPM proc dumpable on SELinux based systems
The deny_ptrace is a OS runtime setting and is off by default, at least on workstations flavors (fedora) however it might be different on production servers.
1 parent cdf7240 commit 7bb2a9f

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212

1313
- FPM:
1414
. Emit error for invalid port setting. (David Carlier)
15+
. Added extra check for FPM proc dumpable on SELinux based systems.
16+
(David Carlier)
1517

1618
- Intl:
1719
. Update all grandfathered language tags with preferred values

sapi/fpm/config.m4

+14
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ if test "$PHP_FPM" != "no"; then
563563
[no],
564564
[no])
565565

566+
PHP_ARG_WITH([fpm-selinux],,
567+
[AS_HELP_STRING([--with-fpm-selinux],
568+
[Support SELinux policy library])],
569+
[no],
570+
[no])
571+
566572
if test "$PHP_FPM_SYSTEMD" != "no" ; then
567573
PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 209])
568574

@@ -605,6 +611,14 @@ if test "$PHP_FPM" != "no"; then
605611
])
606612
fi
607613

614+
if test "x$PHP_FPM_SELINUX" != "xno" ; then
615+
AC_CHECK_HEADERS([selinux/selinux.h])
616+
AC_CHECK_LIB(selinux, security_setenforce, [
617+
PHP_ADD_LIBRARY(selinux)
618+
AC_DEFINE(HAVE_SELINUX, 1, [ SElinux available ])
619+
],[])
620+
fi
621+
608622
PHP_SUBST_OLD(php_fpm_systemd)
609623
AC_DEFINE_UNQUOTED(PHP_FPM_SYSTEMD, "$php_fpm_systemd", [fpm systemd service type])
610624

sapi/fpm/fpm/fpm_unix.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <sys/acl.h>
3232
#endif
3333

34+
#ifdef HAVE_SELINUX
35+
#include <selinux/selinux.h>
36+
#endif
37+
3438
#include "fpm.h"
3539
#include "fpm_conf.h"
3640
#include "fpm_cleanup.h"
@@ -412,8 +416,17 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
412416
}
413417

414418
#ifdef HAVE_PRCTL
415-
if (wp->config->process_dumpable && 0 > prctl(PR_SET_DUMPABLE, 1, 0, 0, 0)) {
416-
zlog(ZLOG_SYSERROR, "[pool %s] failed to prctl(PR_SET_DUMPABLE)", wp->config->name);
419+
if (wp->config->process_dumpable) {
420+
int dumpable = 1;
421+
#ifdef HAVE_SELINUX
422+
if (security_get_boolean_active("deny_ptrace") == 1) {
423+
zlog(ZLOG_SYSERROR, "[pool %s] ptrace is denied", wp->config->name);
424+
dumpable = 0;
425+
}
426+
#endif
427+
if (dumpable && 0 > prctl(PR_SET_DUMPABLE, 1, 0, 0, 0)) {
428+
zlog(ZLOG_SYSERROR, "[pool %s] failed to prctl(PR_SET_DUMPABLE)", wp->config->name);
429+
}
417430
}
418431
#endif
419432

0 commit comments

Comments
 (0)