Apache [PTY Errors] in cgi-perl file while creating a new Expect object

强颜欢笑 提交于 2019-12-01 14:21:31

This is because httpd_sys_script_t doesn't have selinux permissions to read/write a pty, but the following selinux policy will allow it:

policy_module(httpd_pty,1.0)
require {
    type httpd_sys_cript_t;
    type ptmx_t;
    class chr_file { read write };
}
allow httpd_sys_script_t ptmx_t:chr_file { read write };

You might be able to change to class chr_file rw_chr_file_perms;, and allow httpd_sys_script_t ptmx_t:chr_file rw_chr_file_perms;, depending on how recent your selinux policy is. The above will work with rhel5, the macro in this line will work with rhel6.

Or, from advice from #selinux on freenode:

mkdir ~/myhttpd
cd ~/myhttpd
echo "policy_module(myhttpd,1.0.0) optional_policy(\` apache_content_template(myscript)')" > myhttpd.te
echo "/home/httpd/foo/cgi-bin/test.pl -- gen_context(system_u:object_r:httpd_myscript_script_exec_t,s0)" > myhttpd.fc
make -f /usr/share/selinux/devel/Makefile myhttpd.pp
sudo semodule -i myhttpd.pp

Basically, the apache policy has a way to create your own content type. Create the content type for your script in the above code fragment. Then use your new avc denials and add to the policy file myhttpd.te above. This will keep you from allowing all httpd processes from accessing pty's, just the one you specify. You would probably do the following afterwards:

allow httpd_myscript_script_t ptmx_t:chr_file rw_chr_file_perms;

added onto the end of myhttpd.te (or whatever you want to call the module), and recompile and load (make and semodule above).

I believe this is SELinux problem, check your log for selinux error and adjust your policy accordingly.

This will solve your problem:

cat > mypol.te<<EOF
module mypol 1.0;
require {
        type httpd_sys_script_t;
        type ptmx_t;
        type httpd_t;
        class chr_file { read write ioctl open };
}

#============= httpd_t ==============
allow httpd_t ptmx_t:chr_file open;
allow httpd_sys_script_t ptmx_t:chr_file { read write };
#!!!! This avc is allowed in the current policy
allow httpd_t ptmx_t:chr_file { read write ioctl };
EOF
checkmodule -M -m -o mypol.mod mypol.te
semodule_package -o mypol.pp -m mypol.mod
semodule -i mypol.pp

setsebool -P daemons_use_tty 1

grep httpd /var/log/audit/audit.log | audit2allow -M mypol
semodule -i mypol.pp
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!