Skip to content
Snippets Groups Projects
  • Chenbo Feng's avatar
    566411ed
    Add sepolicy to lock down bpf access · 566411ed
    Chenbo Feng authored
    Add a new set of sepolicy for the process that only netd use to load
    and run ebpf programs. It is the only process that can load eBPF
    programs into the kernel and is only used to do that. Add some
    neverallow rules regarding which processes have access to bpf objects.
    
    Test: program successfully loaded and pinned at sys/fs/bpf after device
    boot. No selinux violation for bpfloader
    Bug: 30950746
    
    Change-Id: Ia6bb1afda29ae0749bdc368e2dfc5faa12e81b2f
    566411ed
    History
    Add sepolicy to lock down bpf access
    Chenbo Feng authored
    Add a new set of sepolicy for the process that only netd use to load
    and run ebpf programs. It is the only process that can load eBPF
    programs into the kernel and is only used to do that. Add some
    neverallow rules regarding which processes have access to bpf objects.
    
    Test: program successfully loaded and pinned at sys/fs/bpf after device
    boot. No selinux violation for bpfloader
    Bug: 30950746
    
    Change-Id: Ia6bb1afda29ae0749bdc368e2dfc5faa12e81b2f
bpfloader.te 1.09 KiB
# bpf program loader
type bpfloader, domain;
type bpfloader_exec, exec_type, file_type;
typeattribute bpfloader coredomain;

# Process need CAP_NET_ADMIN to run bpf programs as cgroup filter
allow bpfloader self:global_capability_class_set net_admin;

r_dir_file(bpfloader, cgroup_bpf)

# These permission is required for pin bpf program for netd.
allow bpfloader fs_bpf:dir  create_dir_perms;
allow bpfloader fs_bpf:file create_file_perms;
allow bpfloader devpts:chr_file { read write };

# TODO: unknown fd pass denials, need further investigation.
dontaudit bpfloader netd:fd use;

# Use pinned bpf map files from netd.
allow bpfloader netd:bpf { map_read map_write };
allow bpfloader self:bpf { prog_load prog_run };

# Neverallow rules
neverallow { domain -bpfloader } *:bpf { prog_load prog_run };
neverallow { domain -netd -bpfloader } bpfloader_exec:file { execute execute_no_trans };
neverallow bpfloader domain:{ tcp_socket udp_socket rawip_socket } *;
# only system_server, netd and bpfloader can read/write the bpf maps
neverallow { domain -system_server -netd -bpfloader} netd:bpf { map_read map_write };