xref: /aosp_15_r20/system/sepolicy/private/fuseblkd_untrusted.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# Fuseblk is a Filesystem in USErspace for block device. It should only be used
2*e4a36f41SAndroid Build Coastguard Worker# to mount untrusted blocks like USB drives.
3*e4a36f41SAndroid Build Coastguard Workertype fuseblkd_untrusted_exec, system_file_type, exec_type, file_type;
4*e4a36f41SAndroid Build Coastguard Workertype fuseblkd_untrusted, domain;
5*e4a36f41SAndroid Build Coastguard Worker
6*e4a36f41SAndroid Build Coastguard Workertypeattribute fuseblkd_untrusted coredomain;
7*e4a36f41SAndroid Build Coastguard Worker
8*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(fuseblkd_untrusted, fuseblkd_exec, fuseblkd);
9*e4a36f41SAndroid Build Coastguard Worker
10*e4a36f41SAndroid Build Coastguard Worker# Allow stdin/out back to vold.
11*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted vold:fd use;
12*e4a36f41SAndroid Build Coastguard Worker
13*e4a36f41SAndroid Build Coastguard Worker# Allows fuseblk to read block devices.
14*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted block_device:dir search;
15*e4a36f41SAndroid Build Coastguard Worker
16*e4a36f41SAndroid Build Coastguard Worker# Permissions to read dynamic partitions blocks.
17*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted super_block_device:blk_file getattr;
18*e4a36f41SAndroid Build Coastguard Worker
19*e4a36f41SAndroid Build Coastguard Worker# Permissions to access FUSE character devices.
20*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted fuse_device:chr_file { getattr open read write };
21*e4a36f41SAndroid Build Coastguard Worker
22*e4a36f41SAndroid Build Coastguard Worker# Permissions to access /mnt/media_rw/.
23*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted mnt_media_rw_file:dir { getattr search };
24*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted mnt_media_rw_stub_file:dir getattr;
25*e4a36f41SAndroid Build Coastguard Worker
26*e4a36f41SAndroid Build Coastguard Worker# Permissions to read device mappers.
27*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted sysfs_dm:dir search;
28*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted sysfs_dm:file { getattr open read };
29*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted dm_device:blk_file getattr;
30*e4a36f41SAndroid Build Coastguard Worker
31*e4a36f41SAndroid Build Coastguard Worker# Permissions to read links in tmpfs.
32*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted tmpfs:lnk_file read;
33*e4a36f41SAndroid Build Coastguard Worker
34*e4a36f41SAndroid Build Coastguard Worker# Permissions to read loop device blocks.
35*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted loop_device:blk_file getattr;
36*e4a36f41SAndroid Build Coastguard Worker
37*e4a36f41SAndroid Build Coastguard Worker# Permissions to access the /proc/filesystems file.
38*e4a36f41SAndroid Build Coastguard Workerallow fuseblkd_untrusted proc_filesystems:file { open read getattr };
39*e4a36f41SAndroid Build Coastguard Worker
40*e4a36f41SAndroid Build Coastguard Worker###
41*e4a36f41SAndroid Build Coastguard Worker### dontaudit rules
42*e4a36f41SAndroid Build Coastguard Worker###
43*e4a36f41SAndroid Build Coastguard Worker
44*e4a36f41SAndroid Build Coastguard Worker# ntfs-3g wants this permission to read a fork return code, for some reason.
45*e4a36f41SAndroid Build Coastguard Worker# It's unclear why, because it still reads the fork return code correctly,
46*e4a36f41SAndroid Build Coastguard Worker# and nothing breaks. If enforce is set to permissive, the audit goes away.
47*e4a36f41SAndroid Build Coastguard Workerdontaudit fuseblkd_untrusted self:capability sys_admin;
48*e4a36f41SAndroid Build Coastguard Worker
49*e4a36f41SAndroid Build Coastguard Worker###
50*e4a36f41SAndroid Build Coastguard Worker### neverallow rules
51*e4a36f41SAndroid Build Coastguard Worker###
52*e4a36f41SAndroid Build Coastguard Worker
53*e4a36f41SAndroid Build Coastguard Worker# Fuseblk should never be run on block devices holding sensitive data.
54*e4a36f41SAndroid Build Coastguard Workerneverallow fuseblkd_untrusted {
55*e4a36f41SAndroid Build Coastguard Worker  boot_block_device
56*e4a36f41SAndroid Build Coastguard Worker  frp_block_device
57*e4a36f41SAndroid Build Coastguard Worker  metadata_block_device
58*e4a36f41SAndroid Build Coastguard Worker  recovery_block_device
59*e4a36f41SAndroid Build Coastguard Worker  root_block_device
60*e4a36f41SAndroid Build Coastguard Worker  swap_block_device
61*e4a36f41SAndroid Build Coastguard Worker  system_block_device
62*e4a36f41SAndroid Build Coastguard Worker  userdata_block_device
63*e4a36f41SAndroid Build Coastguard Worker  cache_block_device
64*e4a36f41SAndroid Build Coastguard Worker  dm_device
65*e4a36f41SAndroid Build Coastguard Worker}:blk_file no_rw_file_perms;
66*e4a36f41SAndroid Build Coastguard Worker
67*e4a36f41SAndroid Build Coastguard Worker# Only allow entry from vold, and only through fuseblkd_untrusted_exec binaries.
68*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -vold } fuseblkd_untrusted:process transition;
69*e4a36f41SAndroid Build Coastguard Workerneverallow * fuseblkd_untrusted:process dyntransition;
70*e4a36f41SAndroid Build Coastguard Workerneverallow fuseblkd_untrusted { file_type fs_type -fuseblkd_untrusted_exec }:file entrypoint;
71*e4a36f41SAndroid Build Coastguard Worker
72*e4a36f41SAndroid Build Coastguard Worker# Under no circumstances should fuseblkd_untrusted or any other fuseblk filesystem be
73*e4a36f41SAndroid Build Coastguard Worker# given sys_admin access. They are fundementally untrusted, insecure filesystems.
74*e4a36f41SAndroid Build Coastguard Worker# The correct solution here is to compartmentalize permissions correctly so that
75*e4a36f41SAndroid Build Coastguard Worker# a smaller binary can get the required permissions. See fuseblkd.te.
76*e4a36f41SAndroid Build Coastguard Worker# Similar to above, we don't need setgid or setuid permissions.
77*e4a36f41SAndroid Build Coastguard Workerneverallow fuseblkd_untrusted self:capability { setgid setuid sys_admin };
78*e4a36f41SAndroid Build Coastguard Workerneverallow fuseblkd_untrusted self:global_capability_class_set { setgid setuid sys_admin };
79*e4a36f41SAndroid Build Coastguard Worker
80*e4a36f41SAndroid Build Coastguard Worker# Since we can't have sys_admin permissions, we definitely can't have mount/unmount
81*e4a36f41SAndroid Build Coastguard Worker# permissions, since we won't be able to use them. Same with relabel permissions.
82*e4a36f41SAndroid Build Coastguard Workerneverallow fuseblkd_untrusted fuseblk:filesystem { mount unmount relabelto relabelfrom};
83