Skip to content

Commit 586caea

Browse files
Add SELinux policy support for Userspace Resource Manager (URM) (#1097)
Add SELinux policy definitions for the URM (Username Resource Manager) service, which manages CPU, IRQ, and cgroup resources per username for optimizing system performance. Changes include: - urm.fc: File context definitions mapping: - /etc/urm(/.*)? configuration files to urm_config_t - /run/restune_sock runtime socket to urm_runtime_t - /usr/bin/urm binary to urm_exec_t - urm.te: Type declarations for 4 types: - urm_config_t: URM configuration files under /etc/urm - urm_exec_t: URM executable - urm_t: URM daemon process domain - urm_runtime_t: URM runtime socket under /run Policy rules include: - Suppress spurious capability denials for dac_override, dac_read_search and net_admin - Netlink connector socket for kernel-userspace communication - Unix stream socket for client-server communication - Config file read/write for per-username CPU frequency scaling settings e.g. scaling_max_freq.txt - Runtime socket management under /run for client communication - Runtime socket transition under /run for client communication - PM QoS access via /dev/cpu_dma_latency for power and latency management per username - sysfs read/write for CPU frequency scaling and IRQ affinity - All domain process state read from /proc/<pid> for per-username process resource monitoring - Cgroup file and directory management for per-username resource group isolation - System state read from /proc for per-username resource usage monitoring - Kernel module request for netlink connector - IRQ sysctl read/write for per-username IRQ affinity management via /proc/irq/*/smp_affinity - Kernel sysctl read/write e.g. sched_util_clamp_min - Syslog access for logging - Config file read via urm_read_config() interface - urm.if: Two interface definitions: - urm_read_config(): allows domains to read URM configuration files under /etc/urm - urm_stream_connect(): allows domains to connect to URM via unix domain stream socket Signed-off-by: Varun Singhal <varusing@qti.qualcomm.com>
1 parent 4e360aa commit 586caea

3 files changed

Lines changed: 139 additions & 0 deletions

File tree

policy/modules/services/urm.fc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/etc/urm(/.*)? gen_context(system_u:object_r:urm_config_t,s0)
2+
/run/restune_sock -s gen_context(system_u:object_r:urm_runtime_t,s0)
3+
/usr/bin/urm -- gen_context(system_u:object_r:urm_exec_t,s0)

policy/modules/services/urm.if

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## <summary> Policy for the URM (Username Resource Manager) service.</summary>
2+
## <desc>
3+
## <p>
4+
## URM (Username Resource Manager) is a system service
5+
## that manages CPU, IRQ, and cgroup resources per
6+
## username for optimizing system performance.
7+
## </p>
8+
## </desc>
9+
#
10+
11+
########################################
12+
## <summary>
13+
## Read the URM configuration files.
14+
## </summary>
15+
## <param name="domain">
16+
## <summary>
17+
## Domain allowed access.
18+
## </summary>
19+
## </param>
20+
#
21+
interface(`urm_read_config',`
22+
gen_require(`
23+
type urm_config_t;
24+
')
25+
26+
files_search_etc($1)
27+
allow $1 urm_config_t:dir list_dir_perms;
28+
read_files_pattern($1, urm_config_t, urm_config_t)
29+
read_lnk_files_pattern($1, urm_config_t, urm_config_t)
30+
')
31+
32+
########################################
33+
## <summary>
34+
## Connect to urm with a unix stream socket.
35+
## </summary>
36+
## <param name="domain">
37+
## <summary>
38+
## Domain allowed access.
39+
## </summary>
40+
## </param>
41+
#
42+
interface(`urm_stream_connect',`
43+
gen_require(`
44+
type urm_t, urm_runtime_t;
45+
')
46+
47+
allow $1 urm_runtime_t:sock_file rw_sock_file_perms;
48+
stream_connect_pattern($1, urm_runtime_t, urm_runtime_t, urm_t)
49+
')

policy/modules/services/urm.te

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
policy_module(urm)
2+
3+
########################################
4+
#
5+
# Declarations
6+
#
7+
8+
type urm_config_t;
9+
files_config_file(urm_config_t)
10+
11+
type urm_exec_t;
12+
type urm_t;
13+
init_daemon_domain(urm_t, urm_exec_t)
14+
15+
type urm_runtime_t;
16+
files_runtime_file(urm_runtime_t)
17+
18+
########################################
19+
#
20+
# urm local policy
21+
#
22+
23+
# Suppress spurious capability denials
24+
dontaudit urm_t self:capability { dac_override dac_read_search net_admin };
25+
26+
# Netlink connector socket access
27+
allow urm_t self:netlink_connector_socket create_socket_perms;
28+
29+
# Unix stream socket for client-server communication
30+
allow urm_t self:unix_stream_socket { create connectto };
31+
32+
# Read and write its own config files
33+
# e.g. scaling_max_freq.txt for per-username
34+
# CPU frequency scaling settings
35+
allow urm_t urm_config_t:file rw_file_perms;
36+
37+
# Allow urm to manage its runtime socket
38+
# under /run for client communication
39+
allow urm_t urm_runtime_t:sock_file manage_sock_file_perms;
40+
41+
# Create runtime socket transition under /run
42+
files_runtime_filetrans(urm_t, urm_runtime_t, sock_file)
43+
44+
# Access /dev/cpu_dma_latency for PM QoS
45+
# to manage power and latency per username
46+
dev_rw_pmqos(urm_t)
47+
48+
# Read and write sysfs entries for CPU frequency
49+
# scaling and IRQ affinity management
50+
dev_rw_sysfs(urm_t)
51+
52+
# Read all domain process state /proc/<pid>
53+
# for per-username process resource monitoring
54+
domain_read_all_domains_state(urm_t)
55+
56+
# Create camera and other cgroup directories
57+
# for per-username resource group isolation
58+
fs_create_cgroup_dirs(urm_t)
59+
60+
# Create and manage cgroup files
61+
# for per-username resource group isolation
62+
fs_create_cgroup_files(urm_t)
63+
64+
# Read and write cgroup files/dirs for
65+
# per-username resource group management
66+
fs_rw_cgroup_files(urm_t)
67+
68+
# Read system state from /proc for monitoring
69+
# per-username resource usage
70+
kernel_read_system_state(urm_t)
71+
72+
# Request kernel module loading e.g. netlink connector
73+
kernel_request_load_module(urm_t)
74+
75+
# Read and write IRQ sysctls /proc/irq/*/smp_affinity
76+
# for per-username IRQ affinity management
77+
kernel_rw_irq_sysctls(urm_t)
78+
79+
# Read and write kernel sysctls e.g. sched_util_clamp_min
80+
# for per-username CPU scheduling resource management
81+
kernel_rw_kernel_sysctl(urm_t)
82+
83+
# Send log messages to syslog
84+
logging_send_syslog_msg(urm_t)
85+
86+
# Read per-username resource configuration files under /etc/urm
87+
urm_read_config(urm_t)

0 commit comments

Comments
 (0)