public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [tests/selinux] pr775-checkpolicy-revdeps: add the dmidecode test to upstream repo
@ 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 : a17c57ee31b5b4ef17ae30c14df787abb80397fb
Author : Milos Malik <mmalik@redhat.com>
Date : 2021-02-19T08:18:17+00:00
Stats : +269/-0 in 6 file(s)
URL : https://src.fedoraproject.org/tests/selinux/c/a17c57ee31b5b4ef17ae30c14df787abb80397fb?branch=pr775-checkpolicy-revdeps
Log:
add the dmidecode test to upstream repo
The dmidecode component is also used by various users on Fedora
and RHEL, so it makes sense to run this TC in upstream testing too.
There are no changes in the TC functionality.
Moving the downstream TC to upstream repository.
---
diff --git a/selinux-policy/dmidecode-and-similar/Makefile b/selinux-policy/dmidecode-and-similar/Makefile
new file mode 100644
index 0000000..386e4f3
--- /dev/null
+++ b/selinux-policy/dmidecode-and-similar/Makefile
@@ -0,0 +1,73 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Makefile of /CoreOS/selinux-policy/Regression/dmidecode-and-similar
+# Description: SELinux interferes with dmidecode and related programs
+# Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2017 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing
+# to use, modify, copy, or redistribute it subject to the terms
+# and conditions of the GNU General Public License version 2.
+#
+# 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, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+export TEST=/CoreOS/selinux-policy/Regression/dmidecode-and-similar
+export TESTVERSION=1.0
+
+BUILT_FILES=
+
+FILES=$(METADATA) runtest.sh Makefile PURPOSE testpolicy.te ssh.exp
+
+.PHONY: all install download clean
+
+run: $(FILES) build
+ ./runtest.sh
+
+build: $(BUILT_FILES)
+ chmod a+x runtest.sh ssh.exp
+ chcon -t bin_t runtest.sh ssh.exp
+
+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 dmidecode and related programs" >> $(METADATA)
+ @echo "Type: Regression" >> $(METADATA)
+ @echo "TestTime: 15m" >> $(METADATA)
+ @echo "RunFor: selinux-policy" >> $(METADATA)
+ @echo "RunFor: dmidecode" >> $(METADATA)
+ @echo "Requires: audit libselinux libselinux-utils policycoreutils selinux-policy selinux-policy-targeted setools setools-console dmidecode selinux-policy-devel shadow-utils openssh-clients expect" >> $(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" >> $(METADATA)
+ @echo "Bug: 263141" >> $(METADATA) # RHEL-5
+ @echo "Bug: 1289274" >> $(METADATA) # RHEL-7
+ @echo "Bug: 1300799" >> $(METADATA) # RHEL-7
+ @echo "Bug: 1608480" >> $(METADATA) # RHEL-7
+ @echo "Bug: 1926696" >> $(METADATA) # Fedora 34
+
+ rhts-lint $(METADATA)
+
diff --git a/selinux-policy/dmidecode-and-similar/PURPOSE b/selinux-policy/dmidecode-and-similar/PURPOSE
new file mode 100644
index 0000000..06eaabe
--- /dev/null
+++ b/selinux-policy/dmidecode-and-similar/PURPOSE
@@ -0,0 +1,5 @@
+PURPOSE of /CoreOS/selinux-policy/Regression/dmidecode-and-similar
+Author: Milos Malik <mmalik@redhat.com>
+
+SELinux interferes with dmidecode and related programs.
+
diff --git a/selinux-policy/dmidecode-and-similar/main.fmf b/selinux-policy/dmidecode-and-similar/main.fmf
new file mode 100644
index 0000000..af1851c
--- /dev/null
+++ b/selinux-policy/dmidecode-and-similar/main.fmf
@@ -0,0 +1,2 @@
+path: /selinux-policy/dmidecode-and-similar
+tier: 2
diff --git a/selinux-policy/dmidecode-and-similar/runtest.sh b/selinux-policy/dmidecode-and-similar/runtest.sh
new file mode 100755
index 0000000..0defe7a
--- /dev/null
+++ b/selinux-policy/dmidecode-and-similar/runtest.sh
@@ -0,0 +1,151 @@
+#!/bin/bash
+# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# runtest.sh of /CoreOS/selinux-policy/Regression/dmidecode-and-similar
+# Description: SELinux interferes with dmidecode and related programs
+# Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2017 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing
+# to use, modify, copy, or redistribute it subject to the terms
+# and conditions of the GNU General Public License version 2.
+#
+# 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, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# Include Beaker environment
+. /usr/bin/rhts-environment.sh || exit 1
+. /usr/share/beakerlib/beakerlib.sh || exit 1
+
+PACKAGE="selinux-policy"
+ALLOWED_USERS=${ALLOWED_USERS:-"sysadm_u unconfined_u"}
+DENIED_USERS=${DENIED_USERS:-"staff_u user_u guest_u xguest_u"}
+
+rlJournalStart
+ rlPhaseStartSetup
+ rlRun "rlImport 'selinux-policy/common'"
+ rlSESatisfyRequires
+ rlAssertRpm ${PACKAGE}
+ rlAssertRpm ${PACKAGE}-targeted
+ rlAssertRpm dmidecode
+
+ rlSESetEnforce
+ rlSEStatus
+ rlSESetTimestamp
+ sleep 2
+ rlPhaseEnd
+
+ rlPhaseStartTest "bz#263141"
+ rlSEMatchPathCon "/usr/sbin/dmidecode" "dmidecode_exec_t"
+ rlSESearchRule "allow dmidecode_t sysfs_t : dir { getattr open search } [ ]"
+ rlSESearchRule "allow dmidecode_t sysfs_t : file { getattr open read } [ ]"
+ rlPhaseEnd
+
+ if ! rlIsRHEL 5 6 ; then
+ rlPhaseStartTest "bz#1289274"
+ rlSEMatchPathCon "/usr/sbin/dmidecode" "dmidecode_exec_t"
+ rlSEMatchPathCon "/dev/urandom" "urandom_device_t"
+ rlSESearchRule "allow dmidecode_t urandom_device_t : chr_file { getattr open read } [ ]"
+ rlPhaseEnd
+
+ rlPhaseStartTest "bz#1300799"
+ rlSEMatchPathCon "/usr/sbin/dmidecode" "dmidecode_exec_t"
+ rlSEMatchPathCon "/run/lock/subsys/rhsmcertd" "rhsmcertd_lock_t"
+ rlSEMatchPathCon "/var/log/rhsm/rhsm.log" "rhsmcertd_log_t"
+ rlSESearchRule "allow dmidecode_t rhsmcertd_lock_t : file { open }"
+ rlSESearchRule "allow dmidecode_t rhsmcertd_log_t : file { open read }"
+ rlPhaseEnd
+ fi
+
+ if ! rlIsRHEL 5 6 ; then
+ rlPhaseStartTest "bz#1608480"
+ rlSEMatchPathCon "/usr/sbin/dmidecode" "dmidecode_exec_t"
+ rlSESearchRule "allow rhsmcertd_t dmidecode_exec_t : file { map } [ ]"
+ rlPhaseEnd
+ fi
+
+ if seinfo -c | grep -q lockdown ; then
+ rlPhaseStartTest "bz#1926696"
+ rlSEMatchPathCon "/usr/sbin/biosdecode" "dmidecode_exec_t"
+ rlSEMatchPathCon "/usr/sbin/vpddecode" "dmidecode_exec_t"
+ rlSESearchRule "allow dmidecode_t dmidecode_t : lockdown { integrity } [ ]"
+ rlPhaseEnd
+ fi
+
+ rlPhaseStartTest "real scenario -- runcon"
+ # this TC does not belong to the small set of SELinux domains which can run dmidecode in the system_u:system_r:dmidecode_t:s0 context, therefore we need some help
+ # TODO: use sysadm_t user instead of initrc_t to run dmidecode, because sysadm_t is allowed to transition to dmidecode_t
+ rlRun "ls -l testpolicy.*"
+ rlRun "make -f /usr/share/selinux/devel/Makefile testpolicy.pp"
+ rlRun "semodule -i testpolicy.pp"
+
+ rlRun "runcon system_u:system_r:initrc_t:s0 bash -c /usr/sbin/dmidecode"
+ if [ -f /usr/sbin/biosdecode ] ; then
+ rlRun "runcon system_u:system_r:initrc_t:s0 bash -c /usr/sbin/biosdecode"
+ fi
+ if [ -f /usr/sbin/vpddecode ] ; then
+ rlRun "runcon system_u:system_r:initrc_t:s0 bash -c /usr/sbin/vpddecode"
+ fi
+ if [ -f /usr/sbin/ownership ] ; then
+ rlRun "runcon system_u:system_r:initrc_t:s0 bash -c /usr/sbin/ownership"
+ fi
+
+ rlRun "semodule -l | grep testpolicy"
+ rlRun "semodule -r testpolicy"
+ rlRun "semodule -l | grep testpolicy" 1
+ rlPhaseEnd
+
+ rlPhaseStartTest "real scenario -- confined users"
+ rlFileBackup /etc/ssh/sshd_config
+ rlRun "sed -i 's/^.*PermitRootLogin.*$/PermitRootLogin yes/' /etc/ssh/sshd_config"
+ rlRun "sed -i 's/^.*PasswordAuthentication.*$/PasswordAuthentication yes/' /etc/ssh/sshd_config"
+ rlRun "service sshd restart"
+
+ rlRun "setsebool ssh_sysadm_login on"
+ rlLog "configuration says not to test SELinux users: ${DENIED_USERS}"
+ for SELINUX_USER in ${ALLOWED_USERS} ; do
+ USER_NAME="user${RANDOM}"
+ USER_SECRET="S3kr3t${RANDOM}"
+ rlRun "useradd -o -u 0 -g 0 -Z ${SELINUX_USER} ${USER_NAME}"
+ rlRun "echo ${USER_SECRET} | passwd --stdin ${USER_NAME}"
+ rlRun "restorecon -RvF /home/${USER_NAME}"
+ if [ -f /usr/sbin/dmidecode ] ; then
+ rlRun "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost /usr/sbin/dmidecode"
+ fi
+ if [ -f /usr/sbin/biosdecode ] ; then
+ rlRun "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost /usr/sbin/biosdecode"
+ fi
+ if [ -f /usr/sbin/vpddecode ] ; then
+ rlRun "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost /usr/sbin/vpddecode"
+ fi
+ if [ -f /usr/sbin/ownership ] ; then
+ rlRun "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost /usr/sbin/ownership"
+ fi
+ sleep 2
+ rlRun "userdel -rfZ ${USER_NAME}"
+ done
+ rlRun "setsebool ssh_sysadm_login off"
+ rlFileRestore
+ rlRun "service sshd restart"
+ rlPhaseEnd
+
+ rlPhaseStartCleanup
+ sleep 2
+ rlSECheckAVC
+ rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd
+
diff --git a/selinux-policy/dmidecode-and-similar/ssh.exp b/selinux-policy/dmidecode-and-similar/ssh.exp
new file mode 100644
index 0000000..1244013
--- /dev/null
+++ b/selinux-policy/dmidecode-and-similar/ssh.exp
@@ -0,0 +1,20 @@
+#!/usr/bin/expect -f
+# Expect script for SSH logging as $username to $hostname using $password and executing $command.
+# Usage:
+# ./ssh.exp username password hostname command
+set username [lrange $argv 0 0]
+set password [lrange $argv 1 1]
+set hostname [lrange $argv 2 2]
+set command [lrange $argv 3 10]
+set timeout 15
+# connect to remote host and execute given command
+log_user 1
+spawn ssh -t $username@$hostname "$command ; sleep 5"
+expect {
+ -nocase "yes/no" { send -- "yes\r" ; exp_continue }
+ -nocase "password" { send -- "$password\r" }
+}
+log_user 1
+# send -- "\r"
+expect eof
+
diff --git a/selinux-policy/dmidecode-and-similar/testpolicy.te b/selinux-policy/dmidecode-and-similar/testpolicy.te
new file mode 100644
index 0000000..9f732dd
--- /dev/null
+++ b/selinux-policy/dmidecode-and-similar/testpolicy.te
@@ -0,0 +1,18 @@
+policy_module(testpolicy,1.0)
+
+require {
+ type initrc_t;
+ type dmidecode_t;
+ type dmidecode_exec_t;
+ type console_device_t;
+ class file { getattr open read execute };
+ class process { transition };
+ class chr_file { read write };
+}
+
+allow initrc_t dmidecode_exec_t : file { getattr open read execute };
+type_transition initrc_t dmidecode_exec_t : process dmidecode_t;
+allow initrc_t dmidecode_t : process { transition };
+allow dmidecode_t initrc_t:process { sigchld };
+allow dmidecode_t console_device_t : chr_file { read write };
+
^ 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 dmidecode test to upstream repo Milos Malik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox