xref: /aosp_15_r20/system/sepolicy/prebuilts/api/30.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 and /proc/PID/timerslack_ns
14*e4a36f41SAndroid Build Coastguard Worker## TODO: maybe scope this down?
15*e4a36f41SAndroid Build Coastguard Workerr_dir_file(lmkd, domain)
16*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:file write;
17*e4a36f41SAndroid Build Coastguard Worker
18*e4a36f41SAndroid Build Coastguard Worker## Writes to /sys/module/lowmemorykiller/parameters/minfree
19*e4a36f41SAndroid Build Coastguard Workerr_dir_file(lmkd, sysfs_lowmemorykiller)
20*e4a36f41SAndroid Build Coastguard Workerallow lmkd sysfs_lowmemorykiller:file w_file_perms;
21*e4a36f41SAndroid Build Coastguard Worker
22*e4a36f41SAndroid Build Coastguard Worker# setsched and send kill signals to any registered process
23*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:process { setsched sigkill };
24*e4a36f41SAndroid Build Coastguard Worker# TODO: delete this line b/131761776
25*e4a36f41SAndroid Build Coastguard Workerallow lmkd kernel:process { setsched };
26*e4a36f41SAndroid Build Coastguard Worker
27*e4a36f41SAndroid Build Coastguard Worker# Clean up old cgroups
28*e4a36f41SAndroid Build Coastguard Workerallow lmkd cgroup:dir { remove_name rmdir };
29*e4a36f41SAndroid Build Coastguard Worker
30*e4a36f41SAndroid Build Coastguard Worker# Allow to read memcg stats
31*e4a36f41SAndroid Build Coastguard Workerallow lmkd cgroup:file r_file_perms;
32*e4a36f41SAndroid Build Coastguard Worker
33*e4a36f41SAndroid Build Coastguard Worker# Set self to SCHED_FIFO
34*e4a36f41SAndroid Build Coastguard Workerallow lmkd self:global_capability_class_set sys_nice;
35*e4a36f41SAndroid Build Coastguard Worker
36*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_zoneinfo:file r_file_perms;
37*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_vmstat: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/lowmemorykiller
51*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_lowmemorykiller:file r_file_perms;
52*e4a36f41SAndroid Build Coastguard Worker
53*e4a36f41SAndroid Build Coastguard Worker# Read /proc/meminfo
54*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_meminfo:file r_file_perms;
55*e4a36f41SAndroid Build Coastguard Worker
56*e4a36f41SAndroid Build Coastguard Worker# Read /proc/pressure/cpu and /proc/pressure/io
57*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_cpu:file r_file_perms;
58*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_io:file r_file_perms;
59*e4a36f41SAndroid Build Coastguard Worker
60*e4a36f41SAndroid Build Coastguard Worker# Read/Write /proc/pressure/memory
61*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_mem:file rw_file_perms;
62*e4a36f41SAndroid Build Coastguard Worker
63*e4a36f41SAndroid Build Coastguard Worker# Allow lmkd to connect during reinit.
64*e4a36f41SAndroid Build Coastguard Workerallow lmkd lmkd_socket:sock_file write;
65*e4a36f41SAndroid Build Coastguard Worker
66*e4a36f41SAndroid Build Coastguard Worker# Allow lmkd to write to statsd.
67*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(lmkd, statsdw, statsd)
68*e4a36f41SAndroid Build Coastguard Worker
69*e4a36f41SAndroid Build Coastguard Worker### neverallow rules
70*e4a36f41SAndroid Build Coastguard Worker
71*e4a36f41SAndroid Build Coastguard Worker# never honor LD_PRELOAD
72*e4a36f41SAndroid Build Coastguard Workerneverallow * lmkd:process noatsecure;
73*e4a36f41SAndroid Build Coastguard Workerneverallow lmkd self:global_capability_class_set sys_ptrace;
74