SELinux 阻止 procmail 执行 dspam,但没有 AVC 消息

SELinux 阻止 procmail 执行 dspam,但没有 AVC 消息

我有一个 CentOS 7 系统,其中我使用 postfix 作为 MTA。某些用户.forward在其主目录中通过以下方式使用 procmail:

# cat .forward
"|exec /usr/bin/procmail -f- || exit 75"

在这种情况下,我很难弄清楚为什么 SELinux 不允许 procmail 执行来自以下位置的 dspam .procmailrc

:0fw: dspam.lock
| /usr/bin/dspam --client --stdout --deliver=spam,innocent

在 procmail 日志中我得到:

procmail: Locking "dspam.lock"
procmail: Executing "/usr/bin/dspam,--client,--stdout,--deliver=spam,innocent"
/bin/sh: /usr/bin/dspam: Permission denied
procmail: Program failure (126) of "/usr/bin/dspam"
procmail: Rescue of unfiltered data succeeded
procmail: Unlocking "dspam.lock"

但是,如果我将 SELinux 设置为宽容模式,它就可以正常工作。

问题是它没有记录任何有关被拒绝的 AVC 消息。当我第一次设置时,我发现了一些漏洞audit2whyausearch修复了它们。现在我什么也没得到,尽管很明显是 SELinux 阻止了它工作。

编辑:这是 dspam 二进制文件:

# ls -lZ /usr/bin/dspam
-r-x--s--x. dspam mail system_u:object_r:dspam_exec_t:s0 /usr/bin/dspam

答案1

我遇到了非常类似的问题。就我而言,selinux 悄悄地阻止了我的 .procmailbin 文件夹中的代码执行(我已经将 .procmailbin 的默认上下文设置为 procmail_exec_t)。

我还没有完全解决这个问题,但我相信答案的路径是指示 selinux 报告全部否认,确实如此不是默认执行。

要启用所有拒绝的完整报告,请使用以下命令:

semodule --disable_dontaudit --build

查看 audit.log 并酌情使用 sealert 来确定发生了什么情况。

然后,完成后恢复正常使用:

semodule --build

祝你好运!就我而言,sealert 向我显示了之前没有出现过的信息:

SELinux is preventing sh from search access on the directory /home/chris/.procmailbin.

*****  Plugin catchall (100. confidence) suggests   **************************

If you believe that sh should be allowed search access on the .procmailbin directory by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'sh' --raw | audit2allow -M my-sh
# semodule -X 300 -i my-sh.pp

... 但我仍然需要审查这是否是实际问题以及最佳解决方案是什么。

更新:事实证明这为我解决了这个问题。

以下是我构建的自定义模块的内容:

# more procmailbin-sh-search.te

module my-sh 1.0;

require {
        type dmesg_t;
        type procmail_t;
        type procmail_exec_t;
        type abrt_t;
        class dir search;
        class process noatsecure;
}

#============= abrt_t ==============
allow abrt_t dmesg_t:process noatsecure;

#============= procmail_t ==============
allow procmail_t procmail_exec_t:dir search;

在我看来这应该是默认行为,所以我想我会看看是否能弄清楚向谁报告这个“错误”。

答案2

因此,在查看了 Chris Bennett 的回答后,我使用了它semodule --disable_dontaudit并能够弄清楚我需要什么。下面是我最终使 postfix+procmail+dspam 正常工作的方法:

require {
    type dspam_rw_content_t;
    type dspam_t;
    type dspam_exec_t;
    type procmail_t;
    class dir { open read write getattr add_name search };
    class file { append getattr lock open read write setgid };
    class unix_stream_socket connectto;
}

#============= dspam_t ==============
allow dspam_t dspam_rw_content_t:dir { open read write getattr add_name search };
allow dspam_t dspam_rw_content_t:file { append getattr lock open write };

#============= procmail_t ==============
allow procmail_t dspam_exec_t:file { open read setgid };
allow procmail_t dspam_t:unix_stream_socket connectto;

相关内容