php - SELinux 阻止 php 的 exec ('kill pid' ) 日志中没有任何错误

标签 php linux apache centos selinux

我正在尝试获取进程 PID 并使用以下代码将其终止:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$_script_path = "/path/to/scriptname.php";

$cmd_find_process = "ps aux | grep '[p]hp -f ".$_script_path."'";

echo $cmd_find_process.PHP_EOL;
echo exec($cmd_find_process);
echo PHP_EOL.PHP_EOL;

$cmd = "kill $(".$cmd_find_process." | awk '{print $2}')";
echo $cmd;
echo exec($cmd);
?>

最初我无法列出进程,我通过编译自定义 SELinux 模块selinux-httpd-allow-ps-aux.te 修复了这个问题:

policy_module(myhttpd,1.0.0)

gen_require(`
    type httpd_t;
')

domain_read_all_domains_state(httpd_t);

我已经禁用了 dontaudit 语句:

semodule -DB

但我无法终止我之前由同一用户启动的任何进程:apache。/var/log/audit/audit.log 文件中没有记录错误。

为了完整理解,我试图杀死的 PHP 脚本是使用以下命令执行的:

su -s /bin/sh apache -c php -f /path/to/scriptname.php

我知道这是 SELinux,因为用

关闭 SELinux
echo 0 > /selinux/enforce

会让它发挥作用。

最佳答案

显然我必须重新启动 auditd 才能显示错误。

service auditd restart

这是错误:

type=AVC msg=audit(1459790992.546:15889813): avc:  denied  { signal } for  pid=25478 comm="sh" scontext=unconfined_u:system_r:httpd_t:s0 tcontext=system_u:system_r:initrc_t:s0 tclass=process
    Was caused by:
        Missing type enforcement (TE) allow rule.

        You can use audit2allow to generate a loadable module to allow this access.

我能够通过 audit2allow 解决问题工具。这是解决问题的生成的自定义模块。

module selinux-httpd-allow-signal 1.0;

require {
        type httpd_t;
        type initrc_t;
        class process signal;
}

#============= httpd_t ==============
allow httpd_t initrc_t:process signal;

关于php - SELinux 阻止 php 的 exec ('kill pid' ) 日志中没有任何错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36408053/

相关文章:

linux - 在 core_pattern 调用过程中调用 sched_setaffinity 失败

c++ - 是否可以编译两次并仅通过编写 debian/rules 来构建单独的包?

java - 配置 Apache JMeter HTTP(S) 测试脚本记录器时遇到错误

PHP & 定时任务 : security issues

php - HTML 模板 -- php?

javascript - AJAX/PHP ajax 数据/回显返回 "?>"

linux - Debian 中收到的电子邮件的位置

python - django request.POST 包含<无法解析>

django - 在 Ubuntu 11 上的 Apache 2 上使用 virtualenv 的多个 Django 应用程序

php处理que