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 Workerallow lmkd cgroup_v2: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 Workerallow lmkd cgroup_v2:file r_file_perms; 34*e4a36f41SAndroid Build Coastguard Worker 35*e4a36f41SAndroid Build Coastguard Worker# Set self to SCHED_FIFO 36*e4a36f41SAndroid Build Coastguard Workerallow lmkd self:global_capability_class_set sys_nice; 37*e4a36f41SAndroid Build Coastguard Worker 38*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_zoneinfo:file r_file_perms; 39*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_vmstat:file r_file_perms; 40*e4a36f41SAndroid Build Coastguard Worker 41*e4a36f41SAndroid Build Coastguard Worker# live lock watchdog process allowed to look through /proc/ 42*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:dir { search open read }; 43*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:file { open read }; 44*e4a36f41SAndroid Build Coastguard Worker 45*e4a36f41SAndroid Build Coastguard Worker# live lock watchdog process allowed to dump process trace and 46*e4a36f41SAndroid Build Coastguard Worker# reboot because orderly shutdown may not be possible. 47*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_sysrq:file rw_file_perms; 48*e4a36f41SAndroid Build Coastguard Worker 49*e4a36f41SAndroid Build Coastguard Worker# Read /proc/lowmemorykiller 50*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_lowmemorykiller:file r_file_perms; 51*e4a36f41SAndroid Build Coastguard Worker 52*e4a36f41SAndroid Build Coastguard Worker# Read /proc/meminfo 53*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_meminfo:file r_file_perms; 54*e4a36f41SAndroid Build Coastguard Worker 55*e4a36f41SAndroid Build Coastguard Worker# Read /proc/pressure/cpu and /proc/pressure/io 56*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_cpu:file r_file_perms; 57*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_io:file r_file_perms; 58*e4a36f41SAndroid Build Coastguard Worker 59*e4a36f41SAndroid Build Coastguard Worker# Read/Write /proc/pressure/memory 60*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_mem:file rw_file_perms; 61*e4a36f41SAndroid Build Coastguard Worker 62*e4a36f41SAndroid Build Coastguard Worker# Allow lmkd to connect during reinit. 63*e4a36f41SAndroid Build Coastguard Workerallow lmkd lmkd_socket:sock_file write; 64*e4a36f41SAndroid Build Coastguard Worker 65*e4a36f41SAndroid Build Coastguard Worker# Allow lmkd to write to statsd. 66*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(lmkd, statsdw, statsd) 67*e4a36f41SAndroid Build Coastguard Worker 68*e4a36f41SAndroid Build Coastguard Worker### neverallow rules 69*e4a36f41SAndroid Build Coastguard Worker 70*e4a36f41SAndroid Build Coastguard Worker# never honor LD_PRELOAD 71*e4a36f41SAndroid Build Coastguard Workerneverallow * lmkd:process noatsecure; 72*e4a36f41SAndroid Build Coastguard Workerneverallow lmkd self:global_capability_class_set sys_ptrace; 73