From 3ecf12ffdad26ee5c6361a7c1e82ba507abdc04f Mon Sep 17 00:00:00 2001
From: Zdenek Pytela <zpytela@redhat.com>
Date: Thu, 13 Jan 2022 22:12:03 +0100
Subject: [PATCH] Allow systemd-io-bridge ioctl rpm_script_t
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reference: https://gitbub.com/fedora-selinux/selinux-policy/commit/3ecf12ffdad26ee5c6361a7c1e82ba507abdc04f
Conflict: NA

The permission to allow systemd-io-bridge ioctl rpm_script_t
with a unix domain stream socket was added to the policy.
It may be required when rpm packages are updated.

Addresses the following AVC denial:
type=PROCTITLE msg=audit(3.1.2022 01:17:50.921:486) : proctitle=(o-bridge)
type=SYSCALL msg=audit(3.1.2022 01:17:50.921:486) : arch=x86_64 syscall=ioctl success=no exit=ENOTTY(Pro toto zařízení nevhodné ioctl) a0=0x0 a1=TCGETS a2=0x7ffe8195d1e0 a3=0x7f9ea8a35ca0 items=0 ppid=1 pid=2846 auid=sddm uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=4 comm=(o-bridge) exe=/usr/lib/systemd/systemd subj=system_u:system_r:init_t:s0 key=(null)
type=AVC msg=audit(3.1.2022 01:17:50.921:486) : avc:  denied  { ioctl } for  pid=2846 comm=(o-bridge) path=socket:[43260] dev="sockfs" ino=43260 ioctlcmd=TCGETS scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:unconfined_r:rpm_script_t:s0-s0:c0.c1023 tclass=unix_stream_socket permissive=1

Resolves: rhbz#2024489
Signed-off-by: lujie54 <lujie54@huawei.com>
---
 policy/modules/contrib/rpm.if | 18 ++++++++++++++++++
 policy/modules/system/init.te |  1 +
 2 files changed, 19 insertions(+)

diff --git a/policy/modules/contrib/rpm.if b/policy/modules/contrib/rpm.if
index db809c6..190f3e2 100644
--- a/policy/modules/contrib/rpm.if
+++ b/policy/modules/contrib/rpm.if
@@ -957,3 +957,21 @@ interface(`rpm_admin',`
 
 	rpm_run($1, $2)
 ')
+
+## <summary>
+##	Allow the specified domain to ioctl rpm_script_t
+##	with a unix domain stream socket.
+## </summary>
+## <param name="domain">
+## <summary>
+##	Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`rpm_script_ioctl_stream_sockets',`
+	gen_require(`
+		type rpm_script_t;
+	')
+
+	allow $1 rpm_script_t:unix_stream_socket ioctl;
+')
diff --git a/policy/modules/system/init.te b/policy/modules/system/init.te
index 0de5f4a..a81f5da 100644
--- a/policy/modules/system/init.te
+++ b/policy/modules/system/init.te
@@ -516,6 +516,7 @@ optional_policy(`
 
 optional_policy(`
 	rpm_read_db(init_t)
+	rpm_script_ioctl_stream_sockets(init_t)
 ')
 
 optional_policy(`
-- 
1.8.3.1

