fsck.te 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Any fsck program run by init
  2. type fsck, domain;
  3. type fsck_exec, system_file_type, exec_type, file_type;
  4. # /dev/__null__ created by init prior to policy load,
  5. # open fd inherited by fsck.
  6. allow fsck tmpfs:chr_file { read write ioctl };
  7. # Inherit and use pty created by android_fork_execvp_ext().
  8. allow fsck devpts:chr_file { read write ioctl getattr };
  9. # Allow stdin/out back to vold
  10. allow fsck vold:fd use;
  11. allow fsck vold:fifo_file { read write getattr };
  12. # Run fsck on certain block devices
  13. allow fsck block_device:dir search;
  14. allow fsck userdata_block_device:blk_file rw_file_perms;
  15. allow fsck cache_block_device:blk_file rw_file_perms;
  16. allow fsck dm_device:blk_file rw_file_perms;
  17. userdebug_or_eng(`
  18. allow fsck system_block_device:blk_file rw_file_perms;
  19. ')
  20. # For the block devices where we have ioctl access,
  21. # allow at a minimum the following common fsck ioctls.
  22. allowxperm fsck dev_type:blk_file ioctl {
  23. BLKDISCARDZEROES
  24. BLKROGET
  25. };
  26. # To determine if it is safe to run fsck on a filesystem, e2fsck
  27. # must first determine if the filesystem is mounted. To do that,
  28. # e2fsck scans through /proc/mounts and collects all the mounted
  29. # block devices. With that information, it runs stat() on each block
  30. # device, comparing the major and minor numbers to the filesystem
  31. # passed in on the command line. If there is a match, then the filesystem
  32. # is currently mounted and running fsck is dangerous.
  33. # Allow stat access to all block devices so that fsck can compare
  34. # major/minor values.
  35. allow fsck dev_type:blk_file getattr;
  36. allow fsck {
  37. proc_mounts
  38. proc_swaps
  39. }:file r_file_perms;
  40. allow fsck rootfs:dir r_dir_perms;
  41. ###
  42. ### neverallow rules
  43. ###
  44. # fsck should never be run on these block devices
  45. neverallow fsck {
  46. boot_block_device
  47. frp_block_device
  48. recovery_block_device
  49. root_block_device
  50. swap_block_device
  51. system_block_device
  52. userdebug_or_eng(`-system_block_device')
  53. vold_device
  54. }:blk_file no_rw_file_perms;
  55. # Only allow entry from init or vold via fsck binaries
  56. neverallow { domain -init -vold } fsck:process transition;
  57. neverallow * fsck:process dyntransition;
  58. neverallow fsck { file_type fs_type -fsck_exec }:file entrypoint;