From 400c278dc20c89d2b85a351c9a6567d3fb348a01 Mon Sep 17 00:00:00 2001
From: Zdenek Pytela <zpytela@redhat.com>
Date: Wed, 10 Aug 2022 17:26:03 +0200
Subject: [PATCH] Allow xdm read the kernel key ring

Reference: https://gitbub.com/fedora-selinux/selinux-policy/commit/400c278dc20c89d2b85a351c9a6567d3fb348a01
Conflict: NA

The kernel_read_key() interface was added.

Addresses the following AVC denial:
type=PROCTITLE msg=audit(28.7.2022 13:38:34.889:250) : proctitle=gdm-session-worker [pam/gdm-autologin]
type=SYSCALL msg=audit(28.7.2022 13:38:34.889:250) : arch=x86_64 syscall=keyctl success=yes exit=10 a0=0xb a1=0x1276ecec a2=0x0 a3=0x0 items=0 ppid=1417 pid=1455 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=gdm-session-wor exe=/usr/libexec/gdm-session-worker subj=system_u:system_r:xdm_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(28.7.2022 13:38:34.889:250) : avc:  denied  { read } for  pid=1455 comm=gdm-session-wor scontext=system_u:system_r:xdm_t:s0-s0:c0.c1023 tcontext=system_u:system_r:kernel_t:s0 tclass=key permissive=0

Resolves: rhbz#2111834
Signed-off-by: lujie54 <lujie54@huawei.com>
---
 policy/modules/kernel/kernel.if    | 18 ++++++++++++++++++
 policy/modules/services/xserver.te |  1 +
 2 files changed, 19 insertions(+)

diff --git a/policy/modules/kernel/kernel.if b/policy/modules/kernel/kernel.if
index 6828750..8ffd498 100644
--- a/policy/modules/kernel/kernel.if
+++ b/policy/modules/kernel/kernel.if
@@ -510,6 +510,24 @@ interface(`kernel_rw_key',`
 
 ########################################
 ## <summary>
+##	Allow read the kernel key ring.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`kernel_read_key',`
+	gen_require(`
+		type kernel_t;
+	')
+
+	allow $1 kernel_t:key read;
+')
+
+########################################
+## <summary>
 ##	Allow view the kernel key ring.
 ## </summary>
 ## <param name="domain">
diff --git a/policy/modules/services/xserver.te b/policy/modules/services/xserver.te
index cc215b8..6638ed9 100644
--- a/policy/modules/services/xserver.te
+++ b/policy/modules/services/xserver.te
@@ -566,6 +566,7 @@ kernel_read_net_sysctls(xdm_t)
 kernel_read_network_state(xdm_t)
 kernel_request_load_module(xdm_t)
 kernel_stream_connect(xdm_t)
+kernel_read_key(xdm_t)
 kernel_view_key(xdm_t)
 
 corecmd_exec_shell(xdm_t)
-- 
1.8.3.1

