I have started an unprivileged docker container and trying to start the privileged exec session. It has CAP_SYS_MODULE capabilities, but still, I am getting operations not permitted in insmod.
docker start -it -d --name test ubuntu
docker exec -it --privileged test sh
...
/ # insmod shell.ko
insmod: ERROR: could not insert module reverse-shell.ko: Operation not permitted
Then I tried to start the container with seccomp unconfined and executed the same commands and it is working
docker start -it -d --security-opts seccomp=unconfined --name test2 ubuntu
docker exec -it --privileged test2 sh
...
/ # insmod shell.ko
Now coming back to the seccomp, I see it blocks the syscalls based on the default profile from moby, where I see the finit_module is allowed. So why did my kernel module didn't loaded the first time with the seccomp confined container?
openat("/root/shell.ko"....) = 3
openat(...) = 3
means that openat completed successfully. Which syscalls does strace tell you are actually failing and with what error code? If strace does showfinit_module(...) = -1 EPERM
then this means that either Docker's seccomp profile is behaving differently than expected, or that the process running with the container doesn't actually have CAP_SYS_MODULE. You can inspect current capabilities withcapsh --print
, or more directly herecapsh --has-p=cap_sys_module; echo $?
(should have exit code 0).docker exec -it --privileged <name> sh
do add all the caps. What's confusing is that on the docker page, it says finit_module is blocked in default but in the default.json it is allowed.