Skip to content

Commit 234dc93

Browse files
committed
rpm: Ship SELinux policy denying AF_ALG sockets
Ship a CIL policy module that denies AF_ALG socket creation for all container domains (container_t, spc_t). Like AppArmor, SELinux hooks into the kernel's security_socket_create() LSM callback, which fires regardless of whether the socket was created via socket(2) or the legacy socketcall(2) multiplexer. This blocks AF_ALG selectively without disrupting other socketcall usage by 32-bit binaries. This complements the seccomp profile change in moby, which blocks socket(AF_ALG) but cannot filter socketcall arguments. On SELinux-only systems (Fedora, RHEL, CentOS) where AppArmor is not available, this CIL module provides equivalent protection. Load the module from %post when SELinux is enabled, warning but keeping installation non-fatal if semodule cannot load it. Remove the module on uninstall. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent 7af33f2 commit 234dc93

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

rpm/SPECS/docker-ce.spec

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ install -D -p -m 0644 engine/contrib/init/systemd/docker.socket ${RPM_BUILD_ROOT
104104
# install manpages
105105
make -C ${RPM_BUILD_DIR}/src/engine/man DESTDIR=${RPM_BUILD_ROOT} mandir=%{_mandir} install
106106

107+
# install SELinux policy to deny AF_ALG sockets in container domains
108+
install -D -m 644 engine/contrib/docker-af-alg-deny.cil %{buildroot}%{_datadir}/docker-ce/selinux/docker-af-alg-deny.cil
109+
107110
# create the config directory
108111
mkdir -p ${RPM_BUILD_ROOT}/etc/docker
109112

@@ -114,18 +117,32 @@ mkdir -p ${RPM_BUILD_ROOT}/etc/docker
114117
%{_unitdir}/docker.service
115118
%{_unitdir}/docker.socket
116119
%{_mandir}/man*/*
120+
%{_datadir}/docker-ce/selinux/docker-af-alg-deny.cil
117121
%dir /etc/docker
118122

119123
%post
120124
%systemd_post docker.service
121125
if ! getent group docker > /dev/null; then
122126
groupadd --system docker
123127
fi
128+
# Load the AF_ALG deny policy when SELinux is enabled. This may fail on systems
129+
# with SELinux userspace < 3.6, or without container-selinux's container_domain
130+
# attribute, so keep installation non-fatal.
131+
if command -v semodule > /dev/null 2>&1 && selinuxenabled 2>/dev/null; then
132+
if ! semodule -i %{_datadir}/docker-ce/selinux/docker-af-alg-deny.cil 2>/dev/null; then
133+
echo "warning: could not load docker-af-alg-deny.cil SELinux policy; AF_ALG SELinux denial is not active" >&2
134+
fi
135+
fi
124136

125137
%preun
126138
%systemd_preun docker.service docker.socket
127139

128140
%postun
129141
%systemd_postun_with_restart docker.service
142+
if [ "$1" -eq 0 ]; then
143+
if command -v semodule > /dev/null 2>&1; then
144+
semodule -r container-af-alg-deny 2>/dev/null || :
145+
fi
146+
fi
130147

131148
%changelog

0 commit comments

Comments
 (0)