Skip to content

Commit 2802e4b

Browse files
author
Kemal Rasim Sh
committed
selinux: Enhance Wayland SEPolicy rules
Introduce a new interface, wayland_stream_connect(), which allows domains to connect to a Wayland compositor via UNIX stream sockets. The interface grants permissions to search user runtime directories and establish connections to sockets labeled with wayland_runtime_t, enabling confined domains such as container runtimes or applications to communicate with the Wayland display server. Extend Wayland socket labeling by adding a file context rule for /run/wayland-*, ensuring sockets created directly under /run are labeled as wayland_runtime_t. This addresses systems where Wayland operates outside of per-user runtime directories, providing consistent behavior across embedded and single-user environments. Signed-off-by: Kemal Rasim Sh <kshakir@qti.qualcomm.com>
1 parent e8aa790 commit 2802e4b

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
From 86ee8eb9fb4226ba11e02254b12278c9de446f8a Mon Sep 17 00:00:00 2001
2+
From: Kemal Rasim Sh <kshakir@qti.qualcomm.com>
3+
Date: Fri, 19 Jun 2026 13:30:02 +0300
4+
Subject: [PATCH 2/3] wayland: Add wayland_stream_connect interface
5+
6+
Add a new interface, wayland_stream_connect(), to allow domains to
7+
connect to a Wayland compositor via a UNIX stream socket.
8+
9+
This interface grants the necessary permissions to search the user
10+
runtime directory and establish a stream connection to Wayland
11+
compositor sockets labeled with wayland_runtime_t.
12+
13+
Typical usage includes enabling confined domains (such as container
14+
runtimes or applications) to communicate with the Wayland display server.
15+
16+
Upstream-Status: Backport [https://github.com/SELinuxProject/refpolicy/pull/1166]
17+
18+
Signed-off-by: Kemal Rasim Sh <kshakir@qti.qualcomm.com>
19+
---
20+
policy/modules/session/wayland.if | 22 ++++++++++++++++++++++
21+
1 file changed, 22 insertions(+)
22+
23+
diff --git a/policy/modules/session/wayland.if b/policy/modules/session/wayland.if
24+
index 2812dcb30..bc4185c2a 100644
25+
--- a/policy/modules/session/wayland.if
26+
+++ b/policy/modules/session/wayland.if
27+
@@ -99,3 +99,25 @@ interface(`wayland_client_sandboxed_domain',`
28+
29+
typeattribute $1 wayland_client_sandboxed;
30+
')
31+
+
32+
+#########################################
33+
+## <summary>
34+
+## Connect to the Wayland compositor
35+
+## using a UNIX domain stream socket.
36+
+## </summary>
37+
+## <param name="domain">
38+
+## <summary>
39+
+## Domain allowed access.
40+
+## </summary>
41+
+## </param>
42+
+#
43+
+interface(`wayland_stream_connect',`
44+
+ gen_require(`
45+
+ type wayland_runtime_t;
46+
+ ')
47+
+
48+
+ files_search_runtime($1)
49+
+ userdom_search_user_runtime($1)
50+
+ allow $1 wayland_runtime_t:sock_file write_sock_file_perms;
51+
+ allow $1 wayland_runtime_t:unix_stream_socket connectto;
52+
+')
53+
--
54+
2.43.0
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
From d4a85ae3abdbac8065b6389a103723755866af2c Mon Sep 17 00:00:00 2001
2+
From: Kemal Rasim Sh <kshakir@qti.qualcomm.com>
3+
Date: Mon, 22 Jun 2026 15:49:44 +0300
4+
Subject: [PATCH 3/3] wayland: Label sockets under /run with wayland_runtime_t
5+
6+
On some embedded or single-user systems the Wayland socket
7+
(e.g. wayland-0) is created directly under /run instead of
8+
/run/user/<uid>/. The existing policy only covers per-user runtime
9+
directories, leaving these sockets unlabeled.
10+
11+
Add a file context rule for /run/wayland-* to ensure such sockets are
12+
correctly labeled with wayland_runtime_t, aligning behavior across
13+
different system configurations.
14+
15+
Upstream-Status: Backport [https://github.com/SELinuxProject/refpolicy/pull/1166]
16+
17+
Signed-off-by: Kemal Rasim Sh <kshakir@qti.qualcomm.com>
18+
---
19+
policy/modules/session/wayland.fc | 1 +
20+
1 file changed, 1 insertion(+)
21+
22+
diff --git a/policy/modules/session/wayland.fc b/policy/modules/session/wayland.fc
23+
index 73151efba..bd2ccc08e 100644
24+
--- a/policy/modules/session/wayland.fc
25+
+++ b/policy/modules/session/wayland.fc
26+
@@ -1 +1,2 @@
27+
/run/user/%{USERID}/wayland-.* -s gen_context(system_u:object_r:wayland_runtime_t,s0)
28+
+/run/wayland-.* -s gen_context(system_u:object_r:wayland_runtime_t,s0)
29+
--
30+
2.43.0
31+

dynamic-layers/selinux/recipes-security/refpolicy/refpolicy-targeted_git.bbappend

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
22

33
SRC_URI:append:qcom = " \
44
file://0001-container-Allow-access-to-etc-cdi-for-CDI-configurat.patch \
5+
file://0002-wayland-Add-wayland_stream_connect-interface.patch \
6+
file://0003-wayland-Label-sockets-under-run-with-wayland_runtime.patch \
57
"

0 commit comments

Comments
 (0)