1*e4a36f41SAndroid Build Coastguard Workertypeattribute lmkd coredomain; 2*e4a36f41SAndroid Build Coastguard Workertypeattribute lmkd bpfdomain; 3*e4a36f41SAndroid Build Coastguard Worker 4*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(lmkd) 5*e4a36f41SAndroid Build Coastguard Worker 6*e4a36f41SAndroid Build Coastguard Worker# Set sys.lmk.* properties. 7*e4a36f41SAndroid Build Coastguard Workerset_prop(lmkd, system_lmk_prop) 8*e4a36f41SAndroid Build Coastguard Worker 9*e4a36f41SAndroid Build Coastguard Worker# Set lmkd.* properties. 10*e4a36f41SAndroid Build Coastguard Workerset_prop(lmkd, lmkd_prop) 11*e4a36f41SAndroid Build Coastguard Worker 12*e4a36f41SAndroid Build Coastguard Worker# Get persist.device_config.lmk_native.* properties. 13*e4a36f41SAndroid Build Coastguard Workerget_prop(lmkd, device_config_lmkd_native_prop) 14*e4a36f41SAndroid Build Coastguard Worker 15*e4a36f41SAndroid Build Coastguard Worker# Needed for reading tracepoint ids in order to attach bpf programs. 16*e4a36f41SAndroid Build Coastguard Workerallow lmkd debugfs_tracing:file r_file_perms; 17*e4a36f41SAndroid Build Coastguard Workerallow lmkd self:perf_event { cpu kernel open write }; 18*e4a36f41SAndroid Build Coastguard Worker 19*e4a36f41SAndroid Build Coastguard Workerallow lmkd fs_bpf:file read; 20*e4a36f41SAndroid Build Coastguard Workerallow lmkd bpfloader:bpf { map_read map_write prog_run }; 21*e4a36f41SAndroid Build Coastguard Worker 22*e4a36f41SAndroid Build Coastguard Worker# Needed to interact with memevents-eBPF and receive notifications for memory events 23*e4a36f41SAndroid Build Coastguard Workerallow lmkd fs_bpf_memevents:file { read write }; 24*e4a36f41SAndroid Build Coastguard Workerallow lmkd fs_bpf_memevents:dir search; 25*e4a36f41SAndroid Build Coastguard Worker 26*e4a36f41SAndroid Build Coastguard Workerallow lmkd self:global_capability_class_set { dac_override dac_read_search sys_resource kill }; 27*e4a36f41SAndroid Build Coastguard Worker 28*e4a36f41SAndroid Build Coastguard Worker# lmkd locks itself in memory, to prevent it from being 29*e4a36f41SAndroid Build Coastguard Worker# swapped out and unable to kill other memory hogs. 30*e4a36f41SAndroid Build Coastguard Worker# system/core commit b28ff9131363f7b4a698990da5748b2a88c3ed35 31*e4a36f41SAndroid Build Coastguard Worker# b/16236289 32*e4a36f41SAndroid Build Coastguard Workerallow lmkd self:global_capability_class_set ipc_lock; 33*e4a36f41SAndroid Build Coastguard Worker 34*e4a36f41SAndroid Build Coastguard Worker## Open and write to /proc/PID/oom_score_adj and /proc/PID/timerslack_ns 35*e4a36f41SAndroid Build Coastguard Worker## TODO: maybe scope this down? 36*e4a36f41SAndroid Build Coastguard Workerr_dir_file(lmkd, domain) 37*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:file write; 38*e4a36f41SAndroid Build Coastguard Worker 39*e4a36f41SAndroid Build Coastguard Worker## Writes to /sys/module/lowmemorykiller/parameters/minfree 40*e4a36f41SAndroid Build Coastguard Workerr_dir_file(lmkd, sysfs_lowmemorykiller) 41*e4a36f41SAndroid Build Coastguard Workerallow lmkd sysfs_lowmemorykiller:file w_file_perms; 42*e4a36f41SAndroid Build Coastguard Worker 43*e4a36f41SAndroid Build Coastguard Worker# setsched and send kill signals to any registered process 44*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:process { setsched sigkill }; 45*e4a36f41SAndroid Build Coastguard Worker# TODO: delete this line b/131761776 46*e4a36f41SAndroid Build Coastguard Workerallow lmkd kernel:process { setsched }; 47*e4a36f41SAndroid Build Coastguard Worker 48*e4a36f41SAndroid Build Coastguard Worker# Clean up old cgroups 49*e4a36f41SAndroid Build Coastguard Workerallow lmkd cgroup:dir { remove_name rmdir }; 50*e4a36f41SAndroid Build Coastguard Workerallow lmkd cgroup_v2:dir { remove_name rmdir }; 51*e4a36f41SAndroid Build Coastguard Worker 52*e4a36f41SAndroid Build Coastguard Worker# Allow to read memcg stats 53*e4a36f41SAndroid Build Coastguard Workerallow lmkd cgroup:file r_file_perms; 54*e4a36f41SAndroid Build Coastguard Workerallow lmkd cgroup_v2:file r_file_perms; 55*e4a36f41SAndroid Build Coastguard Worker 56*e4a36f41SAndroid Build Coastguard Worker# Set self to SCHED_FIFO 57*e4a36f41SAndroid Build Coastguard Workerallow lmkd self:global_capability_class_set sys_nice; 58*e4a36f41SAndroid Build Coastguard Worker 59*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_zoneinfo:file r_file_perms; 60*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_vmstat:file r_file_perms; 61*e4a36f41SAndroid Build Coastguard Worker 62*e4a36f41SAndroid Build Coastguard Worker# live lock watchdog process allowed to look through /proc/ 63*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:dir { search open read }; 64*e4a36f41SAndroid Build Coastguard Workerallow lmkd domain:file { open read }; 65*e4a36f41SAndroid Build Coastguard Worker 66*e4a36f41SAndroid Build Coastguard Worker# live lock watchdog process allowed to dump process trace and 67*e4a36f41SAndroid Build Coastguard Worker# reboot because orderly shutdown may not be possible. 68*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_sysrq:file rw_file_perms; 69*e4a36f41SAndroid Build Coastguard Worker 70*e4a36f41SAndroid Build Coastguard Worker# Read /proc/lowmemorykiller 71*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_lowmemorykiller:file r_file_perms; 72*e4a36f41SAndroid Build Coastguard Worker 73*e4a36f41SAndroid Build Coastguard Worker# Read /proc/meminfo 74*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_meminfo:file r_file_perms; 75*e4a36f41SAndroid Build Coastguard Worker 76*e4a36f41SAndroid Build Coastguard Worker# Read /proc/pressure/cpu and /proc/pressure/io 77*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_cpu:file r_file_perms; 78*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_io:file r_file_perms; 79*e4a36f41SAndroid Build Coastguard Worker 80*e4a36f41SAndroid Build Coastguard Worker# Read/Write /proc/pressure/memory 81*e4a36f41SAndroid Build Coastguard Workerallow lmkd proc_pressure_mem:file rw_file_perms; 82*e4a36f41SAndroid Build Coastguard Worker 83*e4a36f41SAndroid Build Coastguard Worker# Allow lmkd to connect during reinit. 84*e4a36f41SAndroid Build Coastguard Workerallow lmkd lmkd_socket:sock_file write; 85*e4a36f41SAndroid Build Coastguard Worker 86*e4a36f41SAndroid Build Coastguard Worker# Allow lmkd to write to statsd. 87*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(lmkd, statsdw, statsd) 88*e4a36f41SAndroid Build Coastguard Worker 89*e4a36f41SAndroid Build Coastguard Worker### neverallow rules 90*e4a36f41SAndroid Build Coastguard Worker 91*e4a36f41SAndroid Build Coastguard Worker# never honor LD_PRELOAD 92*e4a36f41SAndroid Build Coastguard Workerneverallow * lmkd:process noatsecure; 93*e4a36f41SAndroid Build Coastguard Workerneverallow lmkd self:global_capability_class_set sys_ptrace; 94*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -lmkd -vendor_init } lmkd_prop:property_service set; 95*e4a36f41SAndroid Build Coastguard Workerneverallow lmkd self:perf_event ~{ cpu kernel open write }; 96