【问题标题】:Cannot access PHP/C++ shared memory over the web无法通过 Web 访问 PHP/C++ 共享内存
【发布时间】:2010-11-15 17:04:44
【问题描述】:

我在 C++ 和 PHP 之间共享一些内存

在 PHP 端我有:

   $inputshm_id = shmop_open($shid, "w", 0777, 1024);

其中 shid 是我使用 ftok 创建的标识符。

当我在服务器上运行这个以 root 身份登录的 PHP 脚本时,一切正常,但是当我尝试通过网络远程运行它时,我得到:

警告:shmop_open() [function.shmop-open]:无法在第 6 行的 /var/www/html/prof/phpsm.php 中附加或创建共享内存段

...其中第 6 行是我上面显示的行。

由于当我以 root 身份从服务器运行它时一切都运行良好,我假设某处某处阻止网络用户请求连接到共享内存。

有人知道是什么原因造成的吗?

谢谢

【问题讨论】:

    标签: php c++ permissions shared-memory


    【解决方案1】:

    问题是 SELinux 阻止了 shm 访问(您可以通过运行 setenforce 0、测试和运行 setenforce 1 来验证),但除了修改策略之外,我不知道解决它的好方法或切换到 mmap。

    【讨论】:

    • 谢谢。 setenforce 0 给了我响应“setenforce() failed”,但现在你已经给了我一些东西,我会再调查一下。
    • 如果我执行 sestatus 它正在运行,它告诉我 SELinux 已启用,但尽管具有 root 访问权限(通过 SSH),但它不会让我进行任何更改。我试过'newrole -r sysadmn_r'来看看是否有帮助,但我只是得到:'newrole command not found'。
    【解决方案2】:

    为了补充已接受的答案,我需要将 SELinux 保持在强制模式,因此我最终执行了以下操作以允许访问 PHP 中的共享内存操作:

    1. 将 selinux 置于许可模式
    2. 将 selinux 置于“不阻塞”模式:semodule -DB(这很重要,因为默认情况下不记录 shmop 操作)
    3. 清除 /var/log/audit/audit.log
    4. 使用共享内存操作执行了有问题的脚本
    5. 生成了一个 selinux 模块:audit2allow -a -M audit.log
    6. 已安装的模块:semodule -i audit.log.pp

    我最终确实经历了几次迭代以使其正确,但我对 CentOS 6 的最终政策是:

    module audit.log 1.0;
    require {
            type unconfined_t;
            type httpd_t;
            type audisp_t;
            type auditd_t;
            type user_tmpfs_t;
            class process { siginh noatsecure rlimitinh };
            class shm { associate unix_read getattr read };
            class file { read };
    }
    allow auditd_t audisp_t:process { siginh rlimitinh noatsecure };
    allow httpd_t unconfined_t:shm { associate unix_read getattr read };
    allow httpd_t user_tmpfs_t:file read;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2014-07-26
      • 2021-11-26
      • 2019-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多