为何打开文件后调用PHP mail()会引发sendmail.postfix尝试写入该文件?
为什么打开文件后调用
mail()会导致sendmail.postfix尝试写入该文件? 概念验证
<?php $h = fopen('/var/www/test.txt', 'w'); mail('example@example.com', 'Test', 'Test Data');
SELinux 审计消息
type=AVC msg=audit(1669742006.859:131227): avc: denied { write } for pid=1886412 comm="sendmail" path="/var/www/test.txt" dev="vda1" ino=29380975 scontext=system_u:system_r:system_mail_t:s0 tcontext=system_u:object_r:httpd_sys_rw_content_t:s0 tclass=file permissive=0
关键现象
- 在调用
mail()前关闭文件,或者移除变量赋值$h =,则不会生成上述审计消息 - 问题仅出现在Apache + PHP FPM环境(运行于专用系统账户www-example),CLI模式下无法复现
目录权限与ACL信息
目录列表:
drwxrwxr-x+ 2 deploy deploy unconfined_u:object_r:httpd_sys_rw_content_t:s0 4096 Nov 29 17:19 www
目录ACL规则:
# file: www # owner: deploy # group: deploy user::rwx user:www-example:rwx user:deploy:rwx group::rwx mask::rwx other::r-x default:user::rwx default:user:www-example:rwx default:user:deploy:rwx default:group::rwx default:mask::rwx default:other::r-x
环境信息
- 平台:Rocky Linux 8.7 (Green Obsidian)
- Postfix版本:2:3.5.8-4.el8
- PHP版本:PHP 8.0.26
疑问
这是PHP还是sendmail的Bug?
内容的提问来源于stack exchange,提问作者jamieburchell
相关产品推荐
相关产品推荐

