Home | History | Annotate | Download | only in selinux
      1 <html devsite><head>
      2     <title> SELinux </title>
      3     <meta name="project_path" value="/_project.yaml"/>
      4     <meta name="book_path" value="/_book.yaml"/>
      5   </head>
      6   <body>
      7   <!--
      8       Copyright 2017 The Android Open Source Project
      9 
     10       Licensed under the Apache License, Version 2.0 (the "License");
     11       you may not use this file except in compliance with the License.
     12       You may obtain a copy of the License at
     13 
     14           http://www.apache.org/licenses/LICENSE-2.0
     15 
     16       Unless required by applicable law or agreed to in writing, software
     17       distributed under the License is distributed on an "AS IS" BASIS,
     18       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     19       See the License for the specific language governing permissions and
     20       limitations under the License.
     21   -->
     22 
     23 <p>Android  (AOSP)  Android AOSP  90-95% 5-10% </p>
     24 
     25 <h2 id="device_bringup"></h2>
     26 
     27 <p></p>
     28 
     29 <h3 id="run_in_permissive_mode"></h3>
     30 
     31 <p><a href="index.html#background"></a></p>
     32 
     33 <ol>
     34   <li>
     35   </li><li>
     36 </li></ol>
     37 
     38 <p><a href="validate.html#switching_to_permissive"></a> BoardConfig.mk <code>platform/device/&lt;vendor&gt;/&lt;target&gt;/BoardConfig.mk</code> <code>make clean</code> <code>make bootimage</code></p>
     39 
     40 <p></p>
     41 
     42 <p><code>adb getenforce</code></p>
     43 
     44 <p></p>
     45 
     46 <h3 id="enforce_early"></h3>
     47 
     48 <p> <a href="https://en.wikipedia.org/wiki/Eating_your_own_dog_food">dogfooding</a></p>
     49 
     50 <h3 id="remove_or_delete_existing_policy"></h3>
     51 
     52 <p></p>
     53 
     54 <ul>
     55   <li></li><li> <a href="#overuse_of_negation"></a>
     56   </li><li> <a href="#policy_size_explosion"></a>
     57   </li><li>Dead </li></ul>
     58 
     59 <h3 id="address_denials_of_core_services"></h3>
     60 
     61 <p></p>
     62 
     63 <pre class="no-pretty-print">
     64 avc: denied { open } for pid=1003 comm=mediaserver path="/dev/kgsl-3d0
     65 dev="tmpfs" scontext=u:r:mediaserver:s0 tcontext=u:object_r:device:s0
     66 tclass=chr_file permissive=1
     67 avc: denied { read write } for pid=1003 name="kgsl-3d0" dev="tmpfs"
     68 scontext=u:r:mediaserver:s0
     69 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
     70 </pre>
     71 
     72 <p> <code>/dev/kgsl-3d0</code> <code>tcontext</code>  <code>device</code><code>/dev</code> <a href="https://android.googlesource.com/platform/external/sepolicy/+/marshmallow-dev/file_contexts#31">device</a> <a href="validate.html#using_audit2allow">audit2allow</a> </p>
     73 
     74 <p> <a href="https://android.googlesource.com/device/lge/hammerhead/+/marshmallow-dev/sepolicy/file_contexts#1">gpu_device</a> <a href="https://android.googlesource.com/platform/external/sepolicy/+/marshmallow-dev/mediaserver.te#24">mediaserver  gpu_device </a></p>
     75 
     76 <p></p>
     77 
     78 <ol>
     79   <li> <a href="https://android.googlesource.com/device/lge/hammerhead/+/marshmallow-dev/sepolicy/file_contexts#31"></a>
     80   </li><li> <a href="https://android.googlesource.com/device/lge/hammerhead/+/marshmallow-dev/sepolicy/file_contexts#80"></a>
     81   </li><li> <a href="https://android.googlesource.com/device/lge/hammerhead/+/marshmallow-dev/sepolicy/file_contexts#21"></a>
     82   </li><li> <a href="https://android.googlesource.com/device/lge/hammerhead/+/marshmallow-dev/sepolicy/file_contexts#89"></a>
     83   </li><li> <a href="https://android.googlesource.com/device/lge/hammerhead/+/marshmallow-dev/sepolicy/file_contexts#8">nfc</a>
     84   </li><li>gps_device</li><li> <a href="https://android.googlesource.com/device/lge/hammerhead/+/marshmallow-dev/sepolicy/file_contexts#139">/sys </a>
     85   </li><li>/proc </li></ol>
     86 
     87 <p> <a href="customize.html#neverallow">neverallow</a> </p>
     88 
     89 <h3 id="label_new_services_and_address_denials"></h3>
     90 
     91 <p> init  SELinux foo SELinux </p>
     92 
     93 <p> <code>init.&lt;target&gt;.rc</code> </p>
     94 
     95 <pre class="no-pretty-print">
     96 service foo /system/bin/foo
     97     class core
     98 </pre>
     99 
    100 <ol>
    101   <li>foo<br />
    102 
    103       <p> <code>device/&lt;oem&gt;/&lt;target&gt;/sepolicy/foo.te</code></p>
    104 
    105 <pre class="no-pretty-print">
    106 # foo service
    107 type foo, domain;
    108 type foo_exec, exec_type, file_type;
    109 
    110 init_daemon_domain(foo)
    111 </pre>
    112 
    113       <p> foo SELinux </p>
    114   </li>
    115 
    116   <li> <code>/system/bin/foo</code> <br />
    117 
    118       <p> <code>device/&lt;oem&gt;/&lt;target&gt;/sepolicy/
    119          file_contexts</code></p>
    120 
    121 <pre class="no-pretty-print">
    122 /system/bin/foo   u:object_r:foo_exec:s0
    123 </pre>
    124 
    125       <p> SELinux </p>
    126   </li>
    127 
    128   <li></li>
    129 
    130   <li> SELinux <br />
    131 
    132       <p><a href="validate.html#using_audit2allow">audit2allow</a> </p>
    133   </li>
    134 </ol>
    135 
    136 <h3 id="enforcing_mode"></h3>
    137 
    138 <p></p>
    139 
    140 <h2 id="common_mistakes"></h2>
    141 
    142 <p></p>
    143 
    144 <h3 id="overuse_of_negation"></h3>
    145 
    146 <p></p>
    147 
    148 <p><code>allow { domain -untrusted_app } scary_debug_device:chr_file rw_file_perms</code></p>
    149 
    150 <p></p>
    151 
    152 <p> <code>untrusted_app</code>  <code>isolated_app</code>  AOSP <code>scary_debug_device</code></p>
    153 
    154 <h3 id="debugging_features_in_production"></h3>
    155 
    156 <p></p>
    157 
    158 <p> eng/userdebug  SELinux  <code>adb root</code>  <code>adb setenforce 0</code></p>
    159 
    160 <p> <a href="https://android.googlesource.com/device/lge/hammerhead/+/marshmallow-dev/sepolicy/platform_app.te#3">userdebug_or_eng</a> </p>
    161 
    162 <h3 id="policy_size_explosion"></h3>
    163 
    164 <p><a href="http://arxiv.org/abs/1510.05497"> Wild  SEAndroid </a> 5-10% 20% Dead </p>
    165 
    166 <p></p>
    167 
    168 <ul>
    169   <li> ramdisk 
    170   </li><li>
    171   </li><li>
    172 </li></ul>
    173 
    174 <p> 50%  40% AOSP  Shamu  Flounder </p>
    175 
    176 <p><img alt=" 1" src="images/selinux_device_policy_reduction.png"/></p>
    177 <p class="img-caption"><strong> 1</strong>. </p>
    178 
    179 <p> audit2allow Dead </p>
    180 
    181 <h3 id="granting_the_dac_override_capability"> dac_override </h3>
    182 
    183 <p><code> dac_override</code>  unix user/group/world  <code>dac_override</code> <a href="https://android-review.googlesource.com/#/c/174530/5/update_engine.te@11"> unix </a> initvold  installd unix  <a href="http://danwalsh.livejournal.com/69478.html">Dan Walsh </a></p>
    184 
    185 <h2 id="additional_resources"></h2>
    186 
    187 <p><a href="http://seandroid.bitbucket.org/ForMoreInformation.html">SEAndroid </a></p>
    188 
    189 <p>AOSP  <a href="index.html">Android  SELinux</a> </p>
    190 
    191 <p><a href="http://seandroid.bitbucket.org/"></a></p>
    192 
    193 </body></html>