Alex Klyubin | f5446eb | 2017-03-23 14:27:32 -0700 | [diff] [blame] | 1 | typeattribute fsck_untrusted coredomain; |
Inseob Kim | 75806ef | 2024-03-27 17:18:41 +0900 | [diff] [blame^] | 2 | |
| 3 | # Inherit and use pty created by android_fork_execvp_ext(). |
| 4 | allow fsck_untrusted devpts:chr_file { read write ioctl getattr }; |
| 5 | |
| 6 | # Allow stdin/out back to vold |
| 7 | allow fsck_untrusted vold:fd use; |
| 8 | allow fsck_untrusted vold:fifo_file { read write getattr }; |
| 9 | |
| 10 | # Run fsck on vold block devices |
| 11 | allow fsck_untrusted block_device:dir search; |
| 12 | allow fsck_untrusted vold_device:blk_file rw_file_perms; |
| 13 | |
| 14 | allow fsck_untrusted proc_mounts:file r_file_perms; |
| 15 | |
| 16 | # To determine if it is safe to run fsck on a filesystem, e2fsck |
| 17 | # must first determine if the filesystem is mounted. To do that, |
| 18 | # e2fsck scans through /proc/mounts and collects all the mounted |
| 19 | # block devices. With that information, it runs stat() on each block |
| 20 | # device, comparing the major and minor numbers to the filesystem |
| 21 | # passed in on the command line. If there is a match, then the filesystem |
| 22 | # is currently mounted and running fsck is dangerous. |
| 23 | # Allow stat access to all block devices so that fsck can compare |
| 24 | # major/minor values. |
| 25 | allow fsck_untrusted dev_type:blk_file getattr; |
| 26 | |
| 27 | ### |
| 28 | ### neverallow rules |
| 29 | ### |
| 30 | |
| 31 | # Untrusted fsck should never be run on block devices holding sensitive data |
| 32 | neverallow fsck_untrusted { |
| 33 | boot_block_device |
| 34 | frp_block_device |
| 35 | metadata_block_device |
| 36 | recovery_block_device |
| 37 | root_block_device |
| 38 | swap_block_device |
| 39 | system_block_device |
| 40 | userdata_block_device |
| 41 | cache_block_device |
| 42 | dm_device |
| 43 | }:blk_file no_rw_file_perms; |
| 44 | |
| 45 | # Only allow entry from vold via fsck binaries |
| 46 | neverallow { domain -vold } fsck_untrusted:process transition; |
| 47 | neverallow * fsck_untrusted:process dyntransition; |
| 48 | neverallow fsck_untrusted { file_type fs_type -fsck_exec }:file entrypoint; |
| 49 | |
| 50 | # fsck_untrusted should never have sys_admin permissions. If it requires sys_admin |
| 51 | # permissions, that is a code mistake that needs to be fixed, not a permission that |
| 52 | # should be granted. Same with setgid and setuid. |
| 53 | neverallow fsck_untrusted self:global_capability_class_set { setgid setuid sys_admin }; |
| 54 | |
| 55 | ### |
| 56 | ### dontaudit rules |
| 57 | ### |
| 58 | |
| 59 | # Ignores attempts to access sysfs. fsck binaries seem to like trying to go |
| 60 | # here, but nothing bad happens if they can't, and they shouldn't be allowed. |
| 61 | dontaudit fsck_untrusted sysfs:file rw_file_perms; |
| 62 | dontaudit fsck_untrusted sysfs_dm:file rw_file_perms; |
| 63 | dontaudit fsck_untrusted sysfs_dm:dir rw_dir_perms; |
| 64 | |
| 65 | # Ignore attempts to access tmpfs. fsck don't need to do this. |
| 66 | dontaudit fsck_untrusted tmpfs:lnk_file read; |