xref: /aosp_15_r20/system/sepolicy/prebuilts/api/29.0/public/lmkd.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# lmkd low memory killer daemon
2*e4a36f41SAndroid Build Coastguard Workertype lmkd, domain, mlstrustedsubject;
3*e4a36f41SAndroid Build Coastguard Workertype lmkd_exec, system_file_type, exec_type, file_type;
4*e4a36f41SAndroid Build Coastguard Worker
5*e4a36f41SAndroid Build Coastguard Workerallow lmkd self:global_capability_class_set { dac_override dac_read_search sys_resource kill };
6*e4a36f41SAndroid Build Coastguard Worker
7*e4a36f41SAndroid Build Coastguard Worker# lmkd locks itself in memory, to prevent it from being
8*e4a36f41SAndroid Build Coastguard Worker# swapped out and unable to kill other memory hogs.
9*e4a36f41SAndroid Build Coastguard Worker# system/core commit b28ff9131363f7b4a698990da5748b2a88c3ed35
10*e4a36f41SAndroid Build Coastguard Worker# b/16236289
11*e4a36f41SAndroid Build Coastguard Workerallow lmkd self:global_capability_class_set ipc_lock;
12*e4a36f41SAndroid Build Coastguard Worker
13*e4a36f41SAndroid Build Coastguard Worker## Open and write to /proc/PID/oom_score_adj
14*e4a36f41SAndroid Build Coastguard Worker## TODO: maybe scope this down?
15*e4a36f41SAndroid Build Coastguard Workerr_dir_file(lmkd, appdomain)
16*e4a36f41SAndroid Build Coastguard Workerallow lmkd appdomain:file write;
17*e4a36f41SAndroid Build Coastguard Workerr_dir_file(lmkd, system_server)
18*e4a36f41SAndroid Build Coastguard Workerallow lmkd system_server:file write;
19*e4a36f41SAndroid Build Coastguard Worker
20*e4a36f41SAndroid Build Coastguard Worker## Writes to /sys/module/lowmemorykiller/parameters/minfree
21*e4a36f41SAndroid Build Coastguard Workerr_dir_file(lmkd, sysfs_lowmemorykiller)
22*e4a36f41SAndroid Build Coastguard Workerallow lmkd sysfs_lowmemorykiller:file w_file_perms;
23*e4a36f41SAndroid Build Coastguard Worker
24*e4a36f41SAndroid Build Coastguard Worker# setsched and send kill signals
25*e4a36f41SAndroid Build Coastguard Workerallow lmkd appdomain:process { setsched sigkill };
26*e4a36f41SAndroid Build Coastguard Workerallow lmkd kernel:process { setsched };
27*e4a36f41SAndroid Build Coastguard Worker
28*e4a36f41SAndroid Build Coastguard Worker# Clean up old cgroups
29*e4a36f41SAndroid Build Coastguard Workerallow lmkd cgroup:dir { remove_name rmdir };
30*e4a36f41SAndroid Build Coastguard Worker
31*e4a36f41SAndroid Build Coastguard Worker# Allow to read memcg stats
32*e4a36f41SAndroid Build Coastguard Workerallow lmkd cgroup:file r_file_perms;
33*e4a36f41SAndroid Build Coastguard Worker
34*e4a36f41SAndroid Build Coastguard Worker# Set self to SCHED_FIFO
35*e4a36f41SAndroid Build Coastguard Workerallow lmkd self:global_capability_class_set sys_nice;
36*e4a36f41SAndroid Build Coastguard Worker
37*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_zoneinfo:file r_file_perms;
38*e4a36f41SAndroid Build Coastguard Worker
39*e4a36f41SAndroid Build Coastguard Worker# Set sys.lmk.* properties.
40*e4a36f41SAndroid Build Coastguard Workerset_prop(lmkd, system_lmk_prop)
41*e4a36f41SAndroid Build Coastguard Worker
42*e4a36f41SAndroid Build Coastguard Worker# live lock watchdog process allowed to look through /proc/
43*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:dir { search open read };
44*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:file { open read };
45*e4a36f41SAndroid Build Coastguard Worker
46*e4a36f41SAndroid Build Coastguard Worker# live lock watchdog process allowed to dump process trace and
47*e4a36f41SAndroid Build Coastguard Worker# reboot because orderly shutdown may not be possible.
48*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_sysrq:file rw_file_perms;
49*e4a36f41SAndroid Build Coastguard Worker
50*e4a36f41SAndroid Build Coastguard Worker# Read /proc/meminfo
51*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_meminfo:file r_file_perms;
52*e4a36f41SAndroid Build Coastguard Worker
53*e4a36f41SAndroid Build Coastguard Worker# Read /proc/pressure/cpu and /proc/pressure/io
54*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_cpu:file r_file_perms;
55*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_io:file r_file_perms;
56*e4a36f41SAndroid Build Coastguard Worker
57*e4a36f41SAndroid Build Coastguard Worker# Read/Write /proc/pressure/memory
58*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_mem:file rw_file_perms;
59*e4a36f41SAndroid Build Coastguard Worker
60*e4a36f41SAndroid Build Coastguard Worker# Allow lmkd to write to statsd.
61*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(lmkd, statsdw, statsd)
62*e4a36f41SAndroid Build Coastguard Worker
63*e4a36f41SAndroid Build Coastguard Worker### neverallow rules
64*e4a36f41SAndroid Build Coastguard Worker
65*e4a36f41SAndroid Build Coastguard Worker# never honor LD_PRELOAD
66*e4a36f41SAndroid Build Coastguard Workerneverallow * lmkd:process noatsecure;
67