blob: 5eeb39f8a97de64bf2835c1635b0578301c38b91 [file] [log] [blame]
Alex Klyubinf5446eb2017-03-23 14:27:32 -07001typeattribute fsck coredomain;
2
dcashmancc39f632016-07-22 13:13:11 -07003init_daemon_domain(fsck)
Paul Crowleyab318e32017-12-12 10:30:09 -08004
5allow fsck metadata_block_device:blk_file rw_file_perms;
Inseob Kim75806ef2024-03-27 17:18:41 +09006
7# /dev/__null__ created by init prior to policy load,
8# open fd inherited by fsck.
9allow fsck tmpfs:chr_file { read write ioctl };
10
11# Inherit and use pty created by android_fork_execvp_ext().
12allow fsck devpts:chr_file { read write ioctl getattr };
13
14# Allow stdin/out back to vold
15allow fsck vold:fd use;
16allow fsck vold:fifo_file { read write getattr };
17
18# Run fsck on certain block devices
19allow fsck userdata_block_device:blk_file rw_file_perms;
20allow fsck cache_block_device:blk_file rw_file_perms;
21allow fsck dm_device:blk_file rw_file_perms;
22allow fsck zoned_block_device:blk_file rw_file_perms;
23userdebug_or_eng(`
24allow fsck system_block_device:blk_file rw_file_perms;
25')
26
27# e2fsck performs a comprehensive search of /proc/mounts to check whether the
28# checked filesystem is currently mounted.
29allow fsck metadata_file:dir getattr;
30allow fsck block_device:dir search;
31allow fsck mirror_data_file:dir search;
32
33# For the block devices where we have ioctl access,
34# allow at a minimum the following common fsck ioctls.
35allowxperm fsck dev_type:blk_file ioctl {
36 BLKDISCARDZEROES
37 BLKROGET
38 BLKREPORTZONE
39};
40
41# To determine if it is safe to run fsck on a filesystem, e2fsck
42# must first determine if the filesystem is mounted. To do that,
43# e2fsck scans through /proc/mounts and collects all the mounted
44# block devices. With that information, it runs stat() on each block
45# device, comparing the major and minor numbers to the filesystem
46# passed in on the command line. If there is a match, then the filesystem
47# is currently mounted and running fsck is dangerous.
48# Allow stat access to all block devices so that fsck can compare
49# major/minor values.
50allow fsck dev_type:blk_file getattr;
51
52allow fsck {
53 proc_mounts
54 proc_swaps
55 sysfs_dm
56}:file r_file_perms;
57allow fsck rootfs:dir r_dir_perms;
58allow fsck sysfs_dm:dir r_dir_perms;
59
60###
61### neverallow rules
62###
63
64# fsck should never be run on these block devices
65neverallow fsck {
66 boot_block_device
67 frp_block_device
68 recovery_block_device
69 root_block_device
70 swap_block_device
71 system_block_device
72 userdebug_or_eng(`-system_block_device')
73 vold_device
74}:blk_file no_rw_file_perms;
75
76# Only allow entry from init or vold via fsck binaries
77neverallow { domain -init -vold } fsck:process transition;
78neverallow * fsck:process dyntransition;
79neverallow fsck { file_type fs_type -fsck_exec }:file entrypoint;