영구 모드에서 외부 커널 모듈을 삽입하려고 합니다. 시작하는 동안 허용될 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 상태 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 정책을 수정하므로 일단 명령이 실행되면 영구적입니다(이후 재부팅 시 다시 실행할 필요가 없습니다).