Selinux 正在阻止我的外部内核模块

Selinux 正在阻止我的外部内核模块

我正在尝试以永久模式插入外部内核模块。在启动过程中,systemd-modules-load只要Selinux允许,我的模块就会被服务加载。但我想保留强制模式。我无法Selinux使用命令将模块插入列表中semodule。我还能做什么?这是我的环境:

Fedora release 27
Kernel version 4.18.19-100.fc27.x86_64

rpm -qa 'selinux-*' 输出:

selinux-policy-targeted-3.13.1-284.37.fc27.noarch
selinux-policy-3.13.1-284.37.fc27.noarch

状态输出:

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      31

systemctl status systemd-modules-load.service 输出:

● systemd-modules-load.service - Load Kernel Modules
   Loaded: loaded (/usr/lib/systemd/system/systemd-modules-load.service; static; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2018-12-14 09:50:42 CET; 19min ago
     Docs: man:systemd-modules-load.service(8)
           man:modules-load.d(5)
  Process: 4397 ExecStart=/usr/lib/systemd/systemd-modules-load (code=exited, status=1/FAILURE)
 Main PID: 4397 (code=exited, status=1/FAILURE)

dic 14 09:50:42 localhost.localdomain systemd[1]: Starting Load Kernel Modules...
dic 14 09:50:42 localhost.localdomain systemd-modules-load[4397]: Failed to insert 'hello': Permission denied
dic 14 09:50:42 localhost.localdomain systemd[1]: systemd-modules-load.service: Main process exited, code=exited, status=1/FAILURE
dic 14 09:50:42 localhost.localdomain systemd[1]: Failed to start Load Kernel Modules.
dic 14 09:50:42 localhost.localdomain systemd[1]: systemd-modules-load.service: Unit entered failed state.
dic 14 09:50:42 localhost.localdomain systemd[1]: systemd-modules-load.service: Failed with result 'exit-code'.

ls -lZ /usr/lib/systemd/systemd-modules-load 输出:

 -rwxr-xr-x. 1 root root system_u:object_r:systemd_modules_load_exec_t:s0 15576  4 mag  2018 /usr/lib/systemd/systemd-modules-load

/var/log/audit/audit.log

type=SELINUX_ERR msg=audit(1533716850.521:304): op=security_bounded_transition seresult=denied oldcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 newcontext=unconfined_u:unconfined_r:thumb_t:s0-s0:c0.c1023
type=SELINUX_ERR msg=audit(1533716850.596:305): op=security_bounded_transition seresult=denied oldcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 newcontext=unconfined_u:unconfined_r:thumb_t:s0-s0:c0.c1023
type=SELINUX_ERR msg=audit(1533716851.081:306): op=security_bounded_transition seresult=denied oldcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 newcontext=unconfined_u:unconfined_r:thumb_t:s0-s0:c0.c1023
type=SELINUX_ERR msg=audit(1533716851.422:307): op=security_bounded_transition seresult=denied oldcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 newcontext=unconfined_u:unconfined_r:thumb_t:s0-s0:c0.c1023
..
type=SELINUX_ERR msg=audit(1533717134.510:310): op=security_bounded_transition seresult=denied oldcontext=system_u:system_r:init_t:s0 newcontext=system_u:system_r:fprintd_t:s0

Journalctl -xeb -u systemd-modules-load.service

L'unità systemd-modules-load.service ha iniziato la fase di avvio.
dic 13 16:38:08 localhost.localdomain systemd-modules-load[14937]: Failed to insert 'hello': Permission denied
dic 13 16:38:08 localhost.localdomain systemd[1]: systemd-modules-load.service: Main process exited, code=exited, status=1/FAILURE
dic 13 16:38:08 localhost.localdomain systemd[1]: Failed to start Load Kernel Modules. -- Subject: L'unità systemd-modules-load.service è fallita

ls-Z

    system_u:object_r:modules_object_t:s0 bls.conf             unconfined_u:object_r:modules_object_t:s0 modules.devname
    system_u:object_r:modules_object_t:s0 build                    system_u:object_r:modules_object_t:s0 modules.drm
    system_u:object_r:modules_object_t:s0 config                   system_u:object_r:modules_object_t:s0 modules.modesetting
    system_u:object_r:modules_object_t:s0 extra                    system_u:object_r:modules_object_t:s0 modules.networking
unconfined_u:object_r:modules_object_t:s0 hello.ko                 system_u:object_r:modules_object_t:s0 modules.order
    system_u:object_r:modules_object_t:s0 kernel               unconfined_u:object_r:modules_object_t:s0 modules.softdep
unconfined_u:object_r:modules_object_t:s0 modules.alias        unconfined_u:object_r:modules_object_t:s0 modules.symbols
unconfined_u:object_r:modules_object_t:s0 modules.alias.bin    unconfined_u:object_r:modules_object_t:s0 modules.symbols.bin
    system_u:object_r:modules_object_t:s0 modules.block            system_u:object_r:modules_object_t:s0 source
    system_u:object_r:modules_object_t:s0 modules.builtin          system_u:object_r:modules_object_t:s0 System.map
unconfined_u:object_r:modules_object_t:s0 modules.builtin.bin      system_u:object_r:modules_object_t:s0 updates
unconfined_u:object_r:modules_object_t:s0 modules.dep              system_u:object_r:modules_object_t:s0 vdso
unconfined_u:object_r:modules_object_t:s0 modules.dep.bin                     system_u:object_r:usr_t:s0 vmlinuz

我的模块位于

/lib/modules/$(uname -r)

答案1

解决了!构建内核模块后,我将其放入目录中/lib/modules/$(uname -r)/kernel/drivers/net。然后用命令depmod我解决了这个问题。现在每次启动后都会加载。

答案2

从安全角度来看,这可能并不理想...但是您可以尝试解决此问题,同时Enforcing通过允许任何域加载内核模块来维持模式,通过调整此 SELinux 布尔值:

$ sudo semanage boolean --list | grep domain_kernel_load_modules
domain_kernel_load_modules     (off  ,  off)  Allow all domains to have the kernel load modules

您可以通过以下方式调整它:

$ sudo semanage boolean --modify --on domain_kernel_load_modules

此操作实际上修改了编译后的 SELinux 策略,因此一旦执行该命令,它就是永久性的(无需在以后重新启动时再次执行它。)

相关内容