Home | History | Annotate | Download | only in public
      1 # installer daemon
      2 type installd, domain;
      3 type installd_exec, exec_type, file_type;
      4 typeattribute installd mlstrustedsubject;
      5 allow installd self:global_capability_class_set { chown dac_override fowner fsetid setgid setuid sys_admin };
      6 
      7 # Allow labeling of files under /data/app/com.example/oat/
      8 allow installd dalvikcache_data_file:dir relabelto;
      9 allow installd dalvikcache_data_file:file { relabelto link };
     10 
     11 # Allow movement of APK files between volumes
     12 allow installd apk_data_file:dir { create_dir_perms relabelfrom };
     13 allow installd apk_data_file:file { create_file_perms relabelfrom link };
     14 allow installd apk_data_file:lnk_file { create r_file_perms unlink };
     15 
     16 allow installd asec_apk_file:file r_file_perms;
     17 allow installd apk_tmp_file:file { r_file_perms unlink };
     18 allow installd apk_tmp_file:dir { relabelfrom create_dir_perms };
     19 allow installd oemfs:dir r_dir_perms;
     20 allow installd oemfs:file r_file_perms;
     21 allow installd cgroup:dir create_dir_perms;
     22 allow installd mnt_expand_file:dir { search getattr };
     23 # Check validity of SELinux context before use.
     24 selinux_check_context(installd)
     25 
     26 r_dir_file(installd, rootfs)
     27 # Scan through APKs in /system/app and /system/priv-app
     28 r_dir_file(installd, system_file)
     29 # Scan through APKs in /vendor/app
     30 r_dir_file(installd, vendor_app_file)
     31 # Scan through Runtime Resource Overlay APKs in /vendor/overlay
     32 r_dir_file(installd, vendor_overlay_file)
     33 # Get file context
     34 allow installd file_contexts_file:file r_file_perms;
     35 # Get seapp_context
     36 allow installd seapp_contexts_file:file r_file_perms;
     37 
     38 # Search /data/app-asec and stat files in it.
     39 allow installd asec_image_file:dir search;
     40 allow installd asec_image_file:file getattr;
     41 
     42 # Create /data/user and /data/user/0 if necessary.
     43 # Also required to initially create /data/data subdirectories
     44 # and lib symlinks before the setfilecon call.  May want to
     45 # move symlink creation after setfilecon in installd.
     46 allow installd system_data_file:dir create_dir_perms;
     47 # Also, allow read for lnk_file so that we can process /data/user/0 links when
     48 # optimizing application code.
     49 allow installd system_data_file:lnk_file { create getattr read setattr unlink };
     50 
     51 # Upgrade /data/media for multi-user if necessary.
     52 allow installd media_rw_data_file:dir create_dir_perms;
     53 allow installd media_rw_data_file:file { getattr unlink };
     54 # restorecon new /data/media directory.
     55 allow installd system_data_file:dir relabelfrom;
     56 allow installd media_rw_data_file:dir relabelto;
     57 
     58 # Delete /data/media files through sdcardfs, instead of going behind its back
     59 allow installd tmpfs:dir r_dir_perms;
     60 allow installd storage_file:dir search;
     61 allow installd sdcardfs:dir { search open read write remove_name getattr rmdir };
     62 allow installd sdcardfs:file { getattr unlink };
     63 
     64 # Upgrade /data/misc/keychain for multi-user if necessary.
     65 allow installd misc_user_data_file:dir create_dir_perms;
     66 allow installd misc_user_data_file:file create_file_perms;
     67 allow installd keychain_data_file:dir create_dir_perms;
     68 allow installd keychain_data_file:file {r_file_perms unlink};
     69 
     70 # Create /data/.layout_version.* file
     71 allow installd install_data_file:file create_file_perms;
     72 
     73 # Create files under /data/dalvik-cache.
     74 allow installd dalvikcache_data_file:dir create_dir_perms;
     75 allow installd dalvikcache_data_file:file create_file_perms;
     76 allow installd dalvikcache_data_file:lnk_file getattr;
     77 
     78 # Create files under /data/resource-cache.
     79 allow installd resourcecache_data_file:dir rw_dir_perms;
     80 allow installd resourcecache_data_file:file create_file_perms;
     81 
     82 # Upgrade from unlabeled userdata.
     83 # Just need enough to remove and/or relabel it.
     84 allow installd unlabeled:dir { getattr search relabelfrom rw_dir_perms rmdir };
     85 allow installd unlabeled:notdevfile_class_set { getattr relabelfrom rename unlink setattr };
     86 # Read pkg.apk file for input during dexopt.
     87 allow installd unlabeled:file r_file_perms;
     88 
     89 # Upgrade from before system_app_data_file was used for system UID apps.
     90 # Just need enough to relabel it and to unlink removed package files.
     91 # Directory access covered by earlier rule above.
     92 allow installd system_data_file:notdevfile_class_set { getattr relabelfrom unlink };
     93 
     94 # Manage /data/data subdirectories, including initially labeling them
     95 # upon creation via setfilecon or running restorecon_recursive,
     96 # setting owner/mode, creating symlinks within them, and deleting them
     97 # upon package uninstall.
     98 # Types extracted from seapp_contexts type= fields.
     99 allow installd {
    100     system_app_data_file
    101     bluetooth_data_file
    102     nfc_data_file
    103     radio_data_file
    104     shell_data_file
    105     app_data_file
    106 }:dir { create_dir_perms relabelfrom relabelto };
    107 
    108 allow installd {
    109     system_app_data_file
    110     bluetooth_data_file
    111     nfc_data_file
    112     radio_data_file
    113     shell_data_file
    114     app_data_file
    115 }:notdevfile_class_set { create_file_perms relabelfrom relabelto };
    116 
    117 # Similar for the files under /data/misc/profiles/
    118 allow installd user_profile_data_file:dir create_dir_perms;
    119 allow installd user_profile_data_file:file create_file_perms;
    120 allow installd user_profile_data_file:dir rmdir;
    121 allow installd user_profile_data_file:file unlink;
    122 
    123 # Files created/updated by profman dumps.
    124 allow installd profman_dump_data_file:dir { search add_name write };
    125 allow installd profman_dump_data_file:file { create setattr open write };
    126 
    127 # Create and use pty created by android_fork_execvp().
    128 allow installd devpts:chr_file rw_file_perms;
    129 
    130 # execute toybox for app relocation
    131 allow installd toolbox_exec:file rx_file_perms;
    132 
    133 # Allow installd to publish a binder service and make binder calls.
    134 binder_use(installd)
    135 add_service(installd, installd_service)
    136 allow installd dumpstate:fifo_file  { getattr write };
    137 
    138 # Allow installd to call into the system server so it can check permissions.
    139 binder_call(installd, system_server)
    140 allow installd permission_service:service_manager find;
    141 
    142 # Allow installd to read and write quotas
    143 allow installd block_device:dir { search };
    144 allow installd labeledfs:filesystem { quotaget quotamod };
    145 
    146 # Allow installd to delete from /data/preloads when trimming data caches
    147 # TODO b/34690396 Remove when time-based purge policy for preloads is implemented in system_server
    148 allow installd preloads_data_file:file { r_file_perms unlink };
    149 allow installd preloads_data_file:dir { r_dir_perms write remove_name rmdir };
    150 allow installd preloads_media_file:file { r_file_perms unlink };
    151 allow installd preloads_media_file:dir { r_dir_perms write remove_name rmdir };
    152 
    153 ###
    154 ### Neverallow rules
    155 ###
    156 
    157 # only system_server, installd and dumpstate may interact with installd over binder
    158 neverallow { domain -system_server -dumpstate -installd } installd_service:service_manager find;
    159 neverallow { domain -system_server -dumpstate } installd:binder call;
    160 neverallow installd { domain -system_server -servicemanager userdebug_or_eng(`-su') }:binder call;
    161