public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Amith Kumar <apeetham@redhat.com>
To: git-commits@fedoraproject.org
Subject: [tests/selinux] pr775-checkpolicy-revdeps: sepolicy::anon_inode  Add test for bz1974559
Date: Fri, 11 Sep 2026 13:19:24 GMT	[thread overview]
Message-ID: <178913276499.1.1492838616086565664.tests-selinux-d16f70fe3a22@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : tests/selinux
            Branch : pr775-checkpolicy-revdeps
            Commit : d16f70fe3a2202a7e020ff1a2891cb9d98e4a808
            Author : Amith Kumar <apeetham@redhat.com>
            Date   : 2021-10-01T01:33:51+05:30
            Stats  : +227/-0 in 5 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/d16f70fe3a2202a7e020ff1a2891cb9d98e4a808?branch=pr775-checkpolicy-revdeps

            Log:
            sepolicy::anon_inode  Add test for bz1974559

Add a new selinux-policy testsuite to address issues related to tclass
anon_inode and also verifies bug 1974559. In this case, selinux policy
denies write permissons to userfaultfd syscall.

Signed-off-by: Amith Kumar <apeetham@redhat.com>

---
diff --git a/selinux-policy/anon_inode-and-similar/Makefile b/selinux-policy/anon_inode-and-similar/Makefile
new file mode 100644
index 0000000..d7b7a26
--- /dev/null
+++ b/selinux-policy/anon_inode-and-similar/Makefile
@@ -0,0 +1,68 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Makefile of /CoreOS/selinux-policy/Regression/anon_inode-and-similar
+#   Description: Upstream coverage for SELinux issues with anon_inode tclass.
+#   Author: Author: Amith Kumar <apeetham@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2021 Red Hat, Inc. All rights reserved.
+#
+#   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/anon_inode-and-similar
+export TESTVERSION=1.0
+
+BUILT_FILES=
+
+FILES=$(METADATA) runtest.sh Makefile PURPOSE reproducer.c
+
+.PHONY: all install download clean
+
+run: $(FILES) build
+	./runtest.sh
+
+build: $(BUILT_FILES)
+	chmod a+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:           Amith Kumar <apeetham@redhat.com>" > $(METADATA)
+	@echo "Name:            $(TEST)" >> $(METADATA)
+	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)
+	@echo "Path:            $(TEST_DIR)" >> $(METADATA)
+	@echo "Description:     SELinux AVC issues related to anon_inode tclass policies." >> $(METADATA)
+	@echo "Type:            Regression" >> $(METADATA)
+	@echo "TestTime:        30m" >> $(METADATA)
+	@echo "RunFor:          selinux-policy" >> $(METADATA)
+	@echo "Requires:        libselinux policycoreutils selinux-policy selinux-policy-targeted gcc glibc-headers" >> $(METADATA)
+	@echo "RhtsRequires:    library(selinux-policy/common)" >> $(METADATA)
+	@echo "Priority:        Normal" >> $(METADATA)
+	@echo "License:         GPLv2" >> $(METADATA)
+	@echo "Confidential:    no" >> $(METADATA)
+	@echo "Destructive:     no" >> $(METADATA)
+	@echo "Environment:     AVC_ERROR=+no_avc_check" >> $(METADATA)
+	@echo "Releases:        -RHEL4" >> $(METADATA)
+	@echo "Bug:             1974559" >> $(METADATA)
+
+	rhts-lint $(METADATA)
+

diff --git a/selinux-policy/anon_inode-and-similar/PURPOSE b/selinux-policy/anon_inode-and-similar/PURPOSE
new file mode 100644
index 0000000..7799186
--- /dev/null
+++ b/selinux-policy/anon_inode-and-similar/PURPOSE
@@ -0,0 +1,4 @@
+PURPOSE of /CoreOS/selinux-policy/Regression/anon_inode-and-similar
+Author: Amith Kumar <apeetham@redhat.com>
+
+SELinux denials affect processes that deals with anon_inode tclass.

diff --git a/selinux-policy/anon_inode-and-similar/main.fmf b/selinux-policy/anon_inode-and-similar/main.fmf
new file mode 100644
index 0000000..18a148c
--- /dev/null
+++ b/selinux-policy/anon_inode-and-similar/main.fmf
@@ -0,0 +1,8 @@
+path: /selinux-policy/anon_inode-and-similar
+summary: Test AVC issues related to tclass anon_inode
+description: |
+    Test coverage for cases verifying avc denial issues related to  
+    anon_inode tclass.
+adjust:
+-   enabled: false
+    when: distro < rhel-9

diff --git a/selinux-policy/anon_inode-and-similar/reproducer.c b/selinux-policy/anon_inode-and-similar/reproducer.c
new file mode 100644
index 0000000..9759c2c
--- /dev/null
+++ b/selinux-policy/anon_inode-and-similar/reproducer.c
@@ -0,0 +1,84 @@
+#include <assert.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+static void test_assert(int cond) {
+  if (!cond) {
+     abort();
+  }
+}
+
+static void do_child(int sock) {
+  int fd;
+  struct msghdr msg;
+  char mbuf;
+  struct iovec iov = { &mbuf, 1 };
+  char cbuf[CMSG_SPACE(sizeof(fd))];
+  const struct cmsghdr* cmsg;
+
+  memset(&msg, 0, sizeof(msg));
+  msg.msg_iov = &iov;
+  msg.msg_iovlen = 1;
+  msg.msg_control = cbuf;
+  msg.msg_controllen = sizeof(cbuf);
+
+  test_assert(recvmsg(sock, &msg, 0) == 1);
+  test_assert(mbuf == 'x');
+
+  test_assert(!(msg.msg_flags & MSG_CTRUNC));
+  test_assert(msg.msg_controllen == CMSG_SPACE(sizeof(fd)));
+  cmsg = CMSG_FIRSTHDR(&msg);
+  test_assert(SOL_SOCKET == cmsg->cmsg_level && SCM_RIGHTS == cmsg->cmsg_type);
+  memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd));
+
+  printf("fd=%d\n", fd);
+}
+
+#define USER_MODE_ONLY 1
+
+int main(void) {
+  int sockfds[2];
+  pid_t child;
+  int fd;
+  struct msghdr msg;
+  struct iovec iov = { "x", 1 };
+  char cbuf[CMSG_SPACE(sizeof(fd))];
+  struct cmsghdr* cmsg;
+  ssize_t nsent;
+  int status;
+
+  test_assert(0 == socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfds));
+
+  if (0 == (child = fork())) {
+    do_child(sockfds[1]);
+    return 0;
+  }
+
+  fd = syscall(SYS_userfaultfd, USER_MODE_ONLY);
+  test_assert(fd >= 0);
+
+  memset(&msg, 0, sizeof(msg));
+  msg.msg_iov = &iov;
+  msg.msg_iovlen = 1;
+  msg.msg_control = cbuf;
+  msg.msg_controllen = sizeof(cbuf);
+  cmsg = CMSG_FIRSTHDR(&msg);
+  cmsg->cmsg_level = SOL_SOCKET;
+  cmsg->cmsg_type = SCM_RIGHTS;
+  cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
+  memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd));
+
+  test_assert(sendmsg(sockfds[0], &msg, 0) == 1);
+
+  test_assert(child == waitpid(child, &status, 0));
+  test_assert(WIFEXITED(status) && 0 == WEXITSTATUS(status));
+
+  return 0;
+}

diff --git a/selinux-policy/anon_inode-and-similar/runtest.sh b/selinux-policy/anon_inode-and-similar/runtest.sh
new file mode 100755
index 0000000..0a2bf68
--- /dev/null
+++ b/selinux-policy/anon_inode-and-similar/runtest.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   runtest.sh of /CoreOS/selinux-policy/Regression/anon_inode-and-similar
+#   Description: Test coverage for cases verifying avc denial issues related to anon_inode tclass.
+#   Author: Amith Kumar <apeetham@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2021 Red Hat, Inc. All rights reserved.
+#
+#   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 rhts environment
+. /usr/bin/rhts-environment.sh
+. /usr/share/beakerlib/beakerlib.sh
+
+PACKAGE="selinux-policy"
+
+rlJournalStart
+    rlPhaseStartSetup
+        rlRun "rlImport 'selinux-policy/common'"
+        rlSESatisfyRequires
+        rlAssertRpm ${PACKAGE}
+        rlAssertRpm ${PACKAGE}-targeted
+        rlAssertRpm gcc
+        rlSESetEnforce
+        rlSEStatus
+        rlSESetTimestamp
+        sleep 2
+    rlPhaseEnd
+
+    rlPhaseStartTest "SELinux policy prevents userfaultfds bz1974559"
+        rlRun "gcc -o reproducer reproducer.c"
+        tst_Time="$(date '+%T')"
+        rlRun "./reproducer"
+        sleep 3
+        rlRun "ausearch -m AVC -m USER_AVC --start $tst_Time" 1
+        rlSESearchRule "allow unconfined_t unconfined_t : anon_inode { write }"
+        rlRun "rm -f reproducer"
+    rlPhaseEnd
+
+    rlPhaseStartCleanup
+        sleep 2
+        rlSECheckAVC
+    rlPhaseEnd
+    rlJournalPrintText
+rlJournalEnd

                 reply	other threads:[~2026-09-11 13:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178913276499.1.1492838616086565664.tests-selinux-d16f70fe3a22@fedoraproject.org \
    --to=apeetham@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox