public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [tests/selinux] pr775-checkpolicy-revdeps: add the swap-file-and-systemd-access test to upstream
@ 2026-09-11 13:18 Milos Malik
  0 siblings, 0 replies; only message in thread
From: Milos Malik @ 2026-09-11 13:18 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : tests/selinux
            Branch : pr775-checkpolicy-revdeps
            Commit : e928e8eddb4a96103ebea47ac5dbd4c1445243c1
            Author : Milos Malik <mmalik@redhat.com>
            Date   : 2020-09-10T13:23:33+00:00
            Stats  : +181/-0 in 4 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/e928e8eddb4a96103ebea47ac5dbd4c1445243c1?branch=pr775-checkpolicy-revdeps

            Log:
            add the swap-file-and-systemd-access test to upstream

Fedora also provides some services which can hibernate, suspend
or put a machine to sleep, so it's a good idea to run the TC in
upstream testing.

There are no changes in the TC functionality, only moving the
downstream TC to the upstream repo.

---
diff --git a/selinux-policy/swap-file-and-systemd-access/Makefile b/selinux-policy/swap-file-and-systemd-access/Makefile
new file mode 100644
index 0000000..786c0d0
--- /dev/null
+++ b/selinux-policy/swap-file-and-systemd-access/Makefile
@@ -0,0 +1,71 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Makefile of /CoreOS/selinux-policy/Regression/swap-file-and-systemd-access
+#   Description: SELinux interferes with systemd when accessing a swap file
+#   Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2020 Red Hat, Inc.
+#
+#   This program is free software: you can redistribute it and/or
+#   modify it under the terms of the GNU General Public License as
+#   published by the Free Software Foundation, either version 2 of
+#   the License, or (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be
+#   useful, but WITHOUT ANY WARRANTY; without even the implied
+#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+#   PURPOSE.  See the GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program. If not, see http://www.gnu.org/licenses/.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+export TEST=/CoreOS/selinux-policy/Regression/swap-file-and-systemd-access
+export TESTVERSION=1.0
+
+BUILT_FILES=
+
+FILES=$(METADATA) runtest.sh Makefile PURPOSE
+
+.PHONY: all install download clean
+
+run: $(FILES) build
+	./runtest.sh
+
+build: $(BUILT_FILES)
+	test -x runtest.sh || chmod a+x runtest.sh
+	test -x runtest.sh || chcon -t bin_t runtest.sh
+
+clean:
+	rm -f *~ $(BUILT_FILES)
+
+include /usr/share/rhts/lib/rhts-make.include
+
+$(METADATA): Makefile
+	@echo "Owner:           Milos Malik <mmalik@redhat.com>" > $(METADATA)
+	@echo "Name:            $(TEST)" >> $(METADATA)
+	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)
+	@echo "Path:            $(TEST_DIR)" >> $(METADATA)
+	@echo "Description:     SELinux interferes with systemd when accessing a swap file" >> $(METADATA)
+	@echo "Type:            Regression" >> $(METADATA)
+	@echo "TestTime:        10m" >> $(METADATA)
+	@echo "RunFor:          selinux-policy" >> $(METADATA)
+	@echo "RunFor:          systemd" >> $(METADATA)
+	@echo "Requires:        audit libselinux-utils policycoreutils selinux-policy setools-console systemd util-linux binutils" >> $(METADATA)
+	@echo "RhtsRequires:    library(selinux-policy/common)" >> $(METADATA)
+	@echo "Environment:     AVC_ERROR=+no_avc_check" >> $(METADATA)
+	@echo "Priority:        Normal" >> $(METADATA)
+	@echo "License:         GPLv2+" >> $(METADATA)
+	@echo "Confidential:    no" >> $(METADATA)
+	@echo "Destructive:     no" >> $(METADATA)
+	@echo "Releases:        -RHEL4 -RHEL6 -RHEL7 -RHELClient5 -RHELServer5" >> $(METADATA)
+	@echo "Bug:             1367279" >> $(METADATA) # Fedora 24
+	@echo "Bug:             1797543" >> $(METADATA) # Fedora 31
+	@echo "Bug:             1798872" >> $(METADATA) # RHEL 8
+	@echo "Bug:             1845594" >> $(METADATA) # Fedora 32
+
+	rhts-lint $(METADATA)
+

diff --git a/selinux-policy/swap-file-and-systemd-access/PURPOSE b/selinux-policy/swap-file-and-systemd-access/PURPOSE
new file mode 100644
index 0000000..e92b3f3
--- /dev/null
+++ b/selinux-policy/swap-file-and-systemd-access/PURPOSE
@@ -0,0 +1,5 @@
+PURPOSE of /CoreOS/selinux-policy/Regression/swap-file-and-systemd-access
+Author: Milos Malik <mmalik@redhat.com>
+
+SELinux interferes with systemd when accessing a swap file.
+

diff --git a/selinux-policy/swap-file-and-systemd-access/main.fmf b/selinux-policy/swap-file-and-systemd-access/main.fmf
new file mode 100644
index 0000000..b2d17da
--- /dev/null
+++ b/selinux-policy/swap-file-and-systemd-access/main.fmf
@@ -0,0 +1,2 @@
+path: /selinux-policy/swap-file-and-systemd-access
+tier: 2

diff --git a/selinux-policy/swap-file-and-systemd-access/runtest.sh b/selinux-policy/swap-file-and-systemd-access/runtest.sh
new file mode 100755
index 0000000..770c8d0
--- /dev/null
+++ b/selinux-policy/swap-file-and-systemd-access/runtest.sh
@@ -0,0 +1,103 @@
+#!/bin/bash
+# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   runtest.sh of /CoreOS/selinux-policy/Regression/swap-file-and-systemd-access
+#   Description: SELinux interferes with systemd when accessing a swap file
+#   Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2020 Red Hat, Inc.
+#
+#   This program is free software: you can redistribute it and/or
+#   modify it under the terms of the GNU General Public License as
+#   published by the Free Software Foundation, either version 2 of
+#   the License, or (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be
+#   useful, but WITHOUT ANY WARRANTY; without even the implied
+#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+#   PURPOSE.  See the GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program. If not, see http://www.gnu.org/licenses/.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# Include Beaker environment
+. /usr/bin/rhts-environment.sh || exit 1
+. /usr/share/beakerlib/beakerlib.sh || exit 1
+
+PACKAGE="selinux-policy"
+
+rlJournalStart
+    rlPhaseStartSetup
+        rlRun "rlImport 'selinux-policy/common'"
+        rlSESatisfyRequires
+        rlAssertRpm ${PACKAGE}
+        rlAssertRpm ${PACKAGE}-targeted
+        rlAssertRpm systemd
+        rlAssertRpm util-linux
+        rlRun "strings /usr/sbin/mkswap | grep swapfile_t"
+
+        rlFileBackup /swapfile
+
+        rlSESetEnforce
+        rlSEStatus
+        rlSESetTimestamp
+        sleep 2
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#1367279"
+        rlSEMatchPathCon "/usr/lib/systemd/systemd" "init_exec_t"
+        rlSESearchRule "allow init_t swapfile_t : file { getattr } [ ]"
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#1797543 + bz#1798872"
+        rlSEMatchPathCon "/usr/lib/systemd/systemd-sleep" "init_exec_t"
+        rlSESearchRule "allow init_t swapfile_t : file { open read ioctl } [ ]"
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#1845594"
+        rlSEMatchPathCon "/usr/lib/systemd/systemd-logind" "systemd_logind_exec_t"
+        rlSESearchRule "allow systemd_logind_t swapfile_t : file { getattr open read ioctl } [ ]"
+    rlPhaseEnd
+
+    rlPhaseStartTest "real scenario"
+        rlRun "rm -f /swapfile"
+        rlRun "dd if=/dev/zero of=/swapfile bs=1M count=256"
+        rlRun "ls -Z /swapfile"
+        rlRun "mkswap /swapfile"
+        rlRun "ls -Z /swapfile | grep :swapfile_t"
+        rlRun "free"
+        rlRun "swapon /swapfile"
+        rlRun "free"
+        # TODO: 4 different services call systemd-sleep, any of them can be used
+        for SERVICE_NAME in systemd-hybrid-sleep systemd-hibernate ; do
+            rlRun "mkdir -p /etc/systemd/system/${SERVICE_NAME}.service.d"
+            rlRun "echo -en '[Service]\nPrivateDevices=yes\n' > /etc/systemd/system/${SERVICE_NAME}.service.d/PrivateDevices.conf"
+        done
+        rlRun "systemctl daemon-reload"
+        rlRun "systemctl start systemd-hybrid-sleep.service" 0,1
+        rlRun "systemctl status systemd-hybrid-sleep.service" 0,3
+        sleep 5
+        rlRun "systemctl hibernate" 0,1
+        sleep 5
+        rlRun "swapoff /swapfile"
+        rlRun "free"
+        rlRun "rm -f /swapfile"
+    rlPhaseEnd
+
+    rlPhaseStartCleanup
+        sleep 2
+        rlSECheckAVC
+        rlFileRestore
+        for SERVICE_NAME in systemd-hybrid-sleep systemd-hibernate ; do
+            rlRun "rm -f /etc/systemd/system/${SERVICE_NAME}.service.d/PrivateDevices.conf"
+        done
+        rlRun "systemctl daemon-reload"
+    rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd
+

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-11 13:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 13:18 [tests/selinux] pr775-checkpolicy-revdeps: add the swap-file-and-systemd-access test to upstream Milos Malik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox