Skip to content

Commit 8e69225

Browse files
authored
Merge pull request #4220 from cyphar/runc-dmz-no-selinux-magic
dmz: remove SELinux special-casing
2 parents 3db0871 + 37581ad commit 8e69225

File tree

10 files changed

+30
-69
lines changed

10 files changed

+30
-69
lines changed

.cirrus.yml

-11
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,6 @@ task:
159159
echo -e "Host localhost\n\tStrictHostKeyChecking no\t\nIdentityFile /root/.ssh/id_ed25519\n" >> /root/.ssh/config
160160
sed -e "s,PermitRootLogin.*,PermitRootLogin prohibit-password,g" -i /etc/ssh/sshd_config
161161
systemctl restart sshd
162-
163-
# Disable the dmz-vs-selinux workaround for distros that have
164-
# container-selinux >= 2.224.0 (CentOS 7 does not have it).
165-
case $DISTRO in
166-
centos-7)
167-
# Do nothing.
168-
;;
169-
*)
170-
echo 'export EXTRA_BUILDTAGS=runc_dmz_selinux_nocompat' >> /root/.bashrc
171-
;;
172-
esac
173162
host_info_script: |
174163
uname -a
175164
# -----

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ make BUILDTAGS=""
6969
|---------------|---------------------------------------|--------------------|---------------------|
7070
| `seccomp` | Syscall filtering using `libseccomp`. | yes | `libseccomp` |
7171
| `!runc_nodmz` | Reduce memory usage for CVE-2019-5736 protection by using a small C binary, [see `memfd-bind` for more details][contrib-memfd-bind]. `runc_nodmz` disables this **experimental feature** and causes runc to use a different protection mechanism which will further increases memory usage temporarily during container startup. To enable this feature you also need to set the `RUNC_DMZ=true` environment variable. | yes ||
72-
| `runc_dmz_selinux_nocompat` | Disables a SELinux DMZ workaround (new distros should set this). See [dmz README] for details. | no ||
7372

7473
The following build tags were used earlier, but are now obsoleted:
7574
- **nokmem** (since runc v1.0.0-rc94 kernel memory settings are ignored)

Vagrantfile.fedora

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ EOF
3232
# To avoid "avc: denied { nosuid_transition }" from SELinux as we run tests on /tmp.
3333
mount -o remount,suid /tmp
3434
35-
# Disable selinux-vs-dmz workaround as Fedora doesn't need it.
36-
echo 'export EXTRA_BUILDTAGS=runc_dmz_selinux_nocompat' >> /root/.bashrc
37-
3835
# Prevent the "fatal: unsafe repository" git complain during build.
3936
git config --global --add safe.directory /vagrant
4037

libcontainer/container_linux.go

-4
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,6 @@ func slicesContains[S ~[]E, E comparable](slice S, needle E) bool {
463463
}
464464

465465
func isDmzBinarySafe(c *configs.Config) bool {
466-
if !dmz.WorksWithSELinux(c) {
467-
return false
468-
}
469-
470466
// Because we set the dumpable flag in nsexec, the only time when it is
471467
// unsafe to use runc-dmz is when the container process would be able to
472468
// race against "runc init" and bypass the ptrace_may_access() checks.

libcontainer/dmz/README.md

-12
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,4 @@ It also support all the architectures we support in runc.
1515

1616
If the GOARCH we use for compiling doesn't support nolibc, it fallbacks to using the C stdlib.
1717

18-
## SELinux compatibility issue and a workaround
19-
20-
Older SELinux policy can prevent runc to execute the dmz binary. The issue is
21-
fixed in [container-selinux v2.224.0]. Yet, some older distributions may not
22-
have the fix, so runc has a runtime workaround of disabling dmz if it finds
23-
that SELinux is in enforced mode and the container SELinux label is set.
24-
25-
Distributions that have a sufficiently new container-selinux can disable the
26-
workaround by building runc with the `runc_dmz_selinux_nocompat` build flag,
27-
essentially allowing dmz to be used together with SELinux.
28-
2918
[nolibc-upstream]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/include/nolibc?h=v6.6-rc3
30-
[container-selinux v2.224.0]: https://github.com/containers/container-selinux/releases/tag/v2.224.0

libcontainer/dmz/selinux.go

-10
This file was deleted.

libcontainer/dmz/selinux_compat.go

-28
This file was deleted.

tests/integration/helpers.bash

+14
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,20 @@ function requires() {
538538
done
539539
}
540540

541+
# Allow a test to specify that it will not work properly on a given OS. The
542+
# fingerprint for the OS used for this test is $ID-$VERSION_ID, using the
543+
# variables in /etc/os-release. The arguments are regular expressions, and any
544+
# match will cause the test to be skipped.
545+
function exclude_os() {
546+
local host
547+
host="$(sh -c '. /etc/os-release ; echo "$ID-$VERSION_ID"')"
548+
for bad_os in "$@"; do
549+
if [[ "$host" =~ ^$bad_os$ ]]; then
550+
skip "test doesn't work on $bad_os"
551+
fi
552+
done
553+
}
554+
541555
# Retry a command $1 times until it succeeds. Wait $2 seconds between retries.
542556
function retry() {
543557
local attempts=$1

tests/integration/run.bats

+12
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ function teardown() {
128128
}
129129

130130
@test "RUNC_DMZ=true runc run [runc-dmz]" {
131+
# centos-7 has an outdated container-selinux (<2.224.0) which means
132+
# runc-dmz won't work.
133+
exclude_os centos-7
134+
131135
RUNC_DMZ=true runc --debug run test_hello
132136
[ "$status" -eq 0 ]
133137
[[ "$output" = *"Hello World"* ]]
@@ -136,6 +140,10 @@ function teardown() {
136140
}
137141

138142
@test "RUNC_DMZ=true runc run [cap_sys_ptrace -> /proc/self/exe clone]" {
143+
# centos-7 has an outdated container-selinux (<2.224.0) which means
144+
# runc-dmz won't work.
145+
exclude_os centos-7
146+
139147
# Add CAP_SYS_PTRACE to the bounding set, the minimum needed to indicate a
140148
# container process _could_ get CAP_SYS_PTRACE.
141149
update_config '.process.capabilities.bounding += ["CAP_SYS_PTRACE"]'
@@ -232,6 +240,10 @@ function teardown() {
232240
}
233241

234242
@test "RUNC_DMZ=true runc run [exec error]" {
243+
# centos-7 has an outdated container-selinux (<2.224.0) which means
244+
# runc-dmz won't work.
245+
exclude_os centos-7
246+
235247
cat <<EOF >rootfs/run.sh
236248
#!/mmnnttbb foo bar
237249
sh

tests/integration/selinux.bats

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ function teardown() {
4040

4141
# https://github.com/opencontainers/runc/issues/4057
4242
@test "runc run (custom selinux label, RUNC_DMZ=true)" {
43+
# centos-7 has an outdated container-selinux (<2.224.0) which means
44+
# runc-dmz won't work.
45+
exclude_os centos-7
46+
4347
update_config ' .process.selinuxLabel |= "system_u:system_r:container_t:s0:c4,c5"
4448
| .process.args = ["/bin/true"]'
4549
RUNC_DMZ=true runc run tst

0 commit comments

Comments
 (0)