Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 1 | page.title=Validating Security-Enhanced Linux in Android |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 2 | @jd:body |
| 3 | |
| 4 | <!-- |
| 5 | Copyright 2010 The Android Open Source Project |
| 6 | |
| 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | you may not use this file except in compliance with the License. |
| 9 | You may obtain a copy of the License at |
| 10 | |
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | |
| 13 | Unless required by applicable law or agreed to in writing, software |
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | See the License for the specific language governing permissions and |
| 17 | limitations under the License. |
| 18 | --> |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 19 | <div id="qv-wrapper"> |
| 20 | <div id="qv"> |
| 21 | <h2>In this document</h2> |
| 22 | <ol id="auto-toc"> |
| 23 | </ol> |
| 24 | </div> |
| 25 | </div> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 26 | |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 27 | <h2 id="introduction">Introduction</h2> |
| 28 | <p> |
| 29 | As part of the Android <a href="{@docRoot}devices/tech/security/index.html">security |
| 30 | model</a>, Android uses Security-Enhanced Linux (SELinux) to apply access |
| 31 | control policies. SELinux enhances Android security, and contributions to it |
| 32 | have been made by a number of companies and organizations; all Android code and |
| 33 | contributors are publicly available for review on |
| 34 | <a href="https://android.googlesource.com/">android.googlesource.com</a>. With SELinux, |
| 35 | Android can |
| 36 | better control access to application data and system logs, reduce the effects of |
| 37 | malicious software, and protect users from potential flaws in code on mobile |
| 38 | devices. |
| 39 | </p> |
| 40 | <p> |
| 41 | Android includes SELinux in enforcing mode and a corresponding security policy |
| 42 | that works by default across the <a |
| 43 | href="https://android.googlesource.com/">Android Open Source |
| 44 | Project</a>. In enforcing mode, illegitimate |
| 45 | actions are prevented and all potential violations are logged by the kernel to |
| 46 | <code>dmesg</code>. Android device manufacturers should gather information about errors so |
| 47 | they may refine their software and SELinux policies before enforcing them. |
| 48 | </p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 49 | |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 50 | <h2 id="background">Background</h2> |
| 51 | <p> |
| 52 | Please note, Android upgraded its SELinux policy version to allow the SELinux |
| 53 | mode to be set on a per-domain basis. For example, if you run all of your |
| 54 | applications on a single domain, you could set that domain to be permissive and |
| 55 | then have all other functions and their domains set to enforcement. Domains are |
| 56 | associated with applications by the key used to sign each application. This |
| 57 | setting is made at the top of each SELinux policy source (*.te) file. |
| 58 | </p> |
| 59 | <p> |
| 60 | Android follows this model of isolating applications to a single domain. With |
| 61 | this, only the root domain and root-level processes (such as <code>initd</code>, |
| 62 | <code>installd</code> and |
| 63 | <code>vold</code>) are now set to enforcing mode. <em>The application domain remains in |
| 64 | permissive mode to allow further evaluation and prevent failures. Still, an |
| 65 | errant application could trigger an action in the root domain that is not |
| 66 | allowed, thereby causing the application to crash.</em> |
| 67 | </p> |
| 68 | <p> |
| 69 | For this reason, device manufacturers should retain the default settings |
| 70 | provided by Android and limit enforcing mode to the root domain only until |
| 71 | they've resolved issues reported in dmesg. That said, device manufacturers may |
| 72 | need to augment their SELinux implementation to account for their additions and |
| 73 | other changes to the operating system. See the <em>Customization</em> section for |
| 74 | instructions. |
| 75 | </p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 76 | |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 77 | <h2 id="mac">Mandatory access control</h2> |
| 78 | <p> |
| 79 | In conjunction with other Android security measures, Android's access control |
| 80 | policy greatly limits the potential damage of compromised |
| 81 | machines and accounts. Using tools like Android's discretionary and mandatory |
| 82 | access controls gives you a structure to ensure your software runs |
| 83 | only at the minimum privilege level. This mitigates the effects of |
| 84 | attacks and reduces the likelihood of errant processes overwriting or even |
| 85 | transmitting data. |
| 86 | </p> |
| 87 | <p> |
| 88 | Starting in Android 4.3, SELinux provides a mandatory access control (MAC) umbrella over traditional |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 89 | discretionary access control (DAC) environments. For instance, software must |
| 90 | typically run as the root user account to write to raw block devices. In a |
| 91 | traditional DAC-based Linux environment, if the root user becomes compromised |
| 92 | that user can write to every raw block device. However, SELinux can be used to |
| 93 | label these devices so the user role assigned the root privilege can write to |
| 94 | only those specified in the associated policy. In this way, root cannot |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 95 | overwrite data and system settings outside of the specific raw block |
| 96 | device. |
| 97 | </p> |
| 98 | <p> |
| 99 | See the <em>Use Cases</em> section for more examples of threats and ways to address |
| 100 | them with SELinux. |
| 101 | </p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 102 | |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 103 | <h2 id="implementation">Implementation</h2> |
| 104 | <p> |
| 105 | Android's SELinux implementation is in enforcing mode - rather than the |
| 106 | non-functional disabled mode or the notification-only permissive mode - to act |
| 107 | as a reference and facilitate testing and development. Although enforcing mode |
| 108 | is set globally, please remember this can be overridden on a per-domain basis |
| 109 | as is in the case of the application domain. |
| 110 | </p> |
| 111 | <p> |
| 112 | SELinux for Android is accompanied by everything you need to enable SELinux |
| 113 | now. You merely need to integrate the <a |
| 114 | href="https://android.googlesource.com/kernel/common/">latest Android |
| 115 | kernel</a> and then incorporate the files found in the |
| 116 | ~<a |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 117 | href="https://android.googlesource.com/platform/external/sepolicy/">platform/external/sepolicy</a> |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 118 | directory (where examples can also be found):<br/> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 119 | <a |
| 120 | href="https://android.googlesource.com/kernel/common/">https://android.googlesource.com/kernel/common/</a> |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 121 | <br/> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 122 | <a |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 123 | href="https://android.googlesource.com/platform/external/sepolicy/">https://android.googlesource.com/platform/external/sepolicy/</a> |
| 124 | </p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 125 | |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 126 | </p> |
| 127 | Those files when compiled comprise the SELinux kernel security policy and cover |
| 128 | the upstream Android operating system. Place those files within the |
| 129 | <root>/device/manufacturer/device-name/sepolicy directory.<br/> |
| 130 | Then just update your <code>BoardConfig.mk</code> makefile - located in the <device-name> |
| 131 | directory containing the sepolicy subdirectory - to reference the sepolicy |
| 132 | subdirectory once created, like so: |
| 133 | </p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 134 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 135 | <pre> |
| 136 | BOARD_SEPOLICY_DIRS := \ |
| 137 | <root>/device/manufacturer/device-name/sepolicy |
| 138 | |
| 139 | BOARD_SEPOLICY_UNION := \ |
| 140 | genfs_contexts \ |
| 141 | file_contexts \ |
| 142 | sepolicy.te |
| 143 | </pre> |
| 144 | |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 145 | <p> |
| 146 | After rebuilding your device, it is enabled with SELinux. You can now either |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 147 | customize your SELinux policies to accommodate your own additions to the Android |
| 148 | operating system as described in the <em>Customization</em> section or verify |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 149 | your |
| 150 | existing setup as covered in the <em>Validation</em> section. |
| 151 | </p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 152 | |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 153 | <h2 id="customization">Customization</h2> |
| 154 | <p> |
| 155 | Once you've integrated this base level of functionality and thoroughly analyzed |
| 156 | the results, you may add your own policy settings to cover your customizations |
| 157 | to the Android operating system. Of course, these policies must still meet the |
| 158 | <a href="http://source.android.com/compatibility/index.html">Android |
| 159 | Compatibility |
| 160 | program</a> requirements and |
| 161 | not remove the default SELinux settings. |
| 162 | </p> |
| 163 | <p> |
| 164 | Manufacturers should not remove existing security settings. Otherwise, they risk |
| 165 | breaking the Android SELinux implementation and the applications it governs. |
| 166 | This includes third-party applications that will likely need to be improved to |
| 167 | be compliant and operational. Applications must require no modification to |
| 168 | continue functioning on SELinux-enabled devices. |
| 169 | </p> |
| 170 | <p> |
| 171 | See the <em>Kernel Security Features</em> section of the Android Compatibility |
| 172 | Definition document for specific requirements:<br/> |
| 173 | <a |
| 174 | href="http://source.android.com/compatibility/index.html">http://source.android.com/compatibility/index.html</a> |
| 175 | </p> |
| 176 | <p> |
| 177 | SELinux uses a whitelist approach, meaning it grants special privileges based |
| 178 | upon role. Since Android's default SELinux policy already supports the Android |
| 179 | Open Source Project, OEMs are not required to modify SELinux settings in any |
| 180 | way. If they do customize SELinux settings, they should take great care not to |
| 181 | break existing applications. Here is how we recommend proceeding: |
| 182 | </p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 183 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 184 | <ol> |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 185 | <li>Use the <a href="https://android.googlesource.com/kernel/common/">latest |
| 186 | Android |
| 187 | kernel</a>.</li> |
| 188 | <li>Adopt the <a |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 189 | href="http://en.wikipedia.org/wiki/Principle_of_least_privilege">principle of |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 190 | least |
| 191 | privilege</a>.</li> |
| 192 | <li>Address only your own additions to Android. The default policy works with |
| 193 | the |
| 194 | <a href="https://android.googlesource.com/">Android Open Source Project</a> |
| 195 | codebase |
| 196 | automatically.</li> |
| 197 | <li>Compartmentalize software components into modules that conduct singular |
| 198 | tasks.</li> |
| 199 | <li>Create SELinux policies that isolate those tasks from unrelated |
| 200 | functions.</li> |
| 201 | <li>Put those policies in *.te files (the extension for SELinux policy source |
| 202 | files) within the <root>/device/manufacturer/device-name/sepolicy |
| 203 | directory.</li> |
| 204 | <li>Release your SELinux implementation in permissive mode first.</li> |
| 205 | <li>Analyze results and refine policy settings.</li> |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 206 | </ol> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 207 | |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 208 | <p> |
| 209 | Once integrated, OEM Android development should include a step to ensure |
| 210 | SELinux |
| 211 | compatibility going forward. In an ideal software development process, SELinux |
| 212 | policy changes only when the software model changes and not the actual |
| 213 | implementation. |
| 214 | </p> |
| 215 | <p> |
| 216 | As device manufacturers begin to customize SELinux, they should first audit |
| 217 | their additions to Android. If they've added a component that conducts a new |
| 218 | function, the manufacturers will need to ensure the component meets the security |
| 219 | policy applied by Android, as well as any associated policy crafted by the OEM, |
| 220 | before turning on enforcement. |
| 221 | </p> |
| 222 | <p> |
| 223 | To prevent unnecessary issues, it is better to be overbroad and over-compatible |
| 224 | than too restrictive and incompatible, which results in broken device functions. |
| 225 | Conversely, if a manufacturer's changes will benefit others, it should supply |
| 226 | the modifications to the default SELinux policy as a |
| 227 | <a href="http://source.android.com/source/submit-patches.html">patch</a>. If the |
| 228 | patch is |
| 229 | applied to the default security policy, the manufacturer will no longer need to |
| 230 | make this change with each new Android release. |
| 231 | </p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 232 | |
| 233 | <h2 id="use-cases">Use Cases</h2> <p>Here are specific examples of exploits to |
| 234 | consider when crafting your own software and associated SELinux policies:</p> |
| 235 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 236 | <p><strong>Symlinks</strong> - Because symlinks appear as files, they are often read |
| 237 | just as that. This can lead to exploits. For instance, some privileged components such |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 238 | as <code>init</code> change the permissions of certain files, sometimes to be excessively |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 239 | open.</p> |
| 240 | |
| 241 | <p>Attackers might then replace those files with symlinks to code they control, |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 242 | allowing the attacker to overwrite arbitrary files. But if you know your application |
| 243 | will never traverse a symlink, you can prohibit it from doing so with SELinux.</p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 244 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 245 | <p><strong>System files</strong> - Consider the class of system files that should only be |
| 246 | modified by the system server. Still, since <code>netd</code>, <code>init</code>, |
| 247 | and <code>vold</code> run as root, they can access those system files. So if |
| 248 | <code>netd</code> became compromised, it could compromise those files and |
| 249 | potentially the system server itself.</p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 250 | |
| 251 | <p>With SELinux, you can identify those files as system server data files. |
| 252 | Therefore, the only domain that has read/write access to them is system server. |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 253 | Even if <code>netd</code> became compromised, it could not switch domains to the |
| 254 | system server domain and access those system files although it runs as root.</p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 255 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 256 | <p><strong>App data</strong> - Another example is the class of functions that |
| 257 | must run as root but should not get to access app data. This is incredibly useful as |
| 258 | wide-ranging assertions can be made, such as certain domains unrelated to application data |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 259 | being prohibited from accessing the internet.</p> |
| 260 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 261 | <p><strong>setattr</strong> - For commands such as <code>chmod</code> and |
| 262 | <code>chown</code>, you could identify the set of files where the associated domain |
| 263 | can conduct <code>setattr</code>. Anything outside of that could be prohibited from |
| 264 | these changes, even by root. So an application might run <code>chmod</code> and |
| 265 | <code>chown</code> against those labeled app_data_files but not shell_data_files or |
| 266 | system_data_files.</p> <h2 id="related-files">Related |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 267 | Files</h2> <p>This section serves to guide you once you’ve decided to |
| 268 | customize the SELinux policy settings. See the <em>Customization</em> section |
| 269 | for steps. We recommend device manufacturers start with the default Android |
| 270 | SELinux policy and make the minimum possible set of changes to address their |
| 271 | additions to Android. Existing Android SELinux policy files are found in the |
| 272 | root of the ~<a |
| 273 | href="https://android.googlesource.com/platform/external/sepolicy/">platform/external/sepolicy</a> |
| 274 | directory.</p> |
| 275 | |
| 276 | <p>Android upgraded its SELinux policy version to allow the SELinux mode to be |
| 277 | set to permissive on a per-domain basis. For example, if you run all of your |
| 278 | applications on a single domain, you could set that domain to be permissive and |
| 279 | then have all other functions and their domains set to enforcement. Domains are |
| 280 | associated with applications by the key used to sign each application. This |
| 281 | setting is made at the top of each SELinux policy source (*.te) file.</p> |
| 282 | |
| 283 | <p>Here are the files you must create or edit in order to customize SELinux:</p> |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 284 | <ul> |
| 285 | <li> |
| 286 | <p><em>New SELinux policy source (*.te) files</em> - Located in the |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 287 | <root>/device/manufacturer/device-name/sepolicy directory These files |
| 288 | define domains and their labels. The new policy files get concatenated with the |
| 289 | existing policy files during compilation into a single SELinux kernel policy |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 290 | file.</p> |
| 291 | <p><strong>Important</strong>:Do not alter the app.te file provided by the |
| 292 | Android Open Source Project. Doing so risks breaking all third-party applications. |
| 293 | </p> |
| 294 | </li> |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 295 | <li> |
| 296 | <p><em>Updated <code>BoardConfig.mk</code> makefile</em> - Located in the |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 297 | <device-name> directory containing the sepolicy subdirectory. It must be |
| 298 | updated to reference the sepolicy subdirectory once created if it wasn’t |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 299 | in initial implementation.</p> </li> |
| 300 | <li> |
| 301 | <p><em>Updated <code>file_contexts</code></em> - Located in |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 302 | the sepolicy subdirectory. It labels files and is managed in the userspace. As |
| 303 | you create new policies, update this file to reference them. In order to apply |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 304 | new <code>file_contexts</code>, you must run <code>restorecon</code> on the file |
| 305 | to be relabeled.</p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 306 | </li> </ul> |
| 307 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 308 | <p>The remaining files in the sepolicy directory are either auto-generated or |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 309 | should remain static. The policy files come in the form: allow, domain, and |
| 310 | context, for a set of actions:</p> |
| 311 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 312 | <ul> |
| 313 | <li> |
| 314 | <p><em>Allow</em> - Gives the role permission to carry out the action described |
| 315 | in the context within the specified domain.</p> </li> |
| 316 | <li> |
| 317 | <p><em>Domain</em> - Domain |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 318 | represents scope of the rule and gets converted to a security identifier (SID) |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 319 | in the kernel.</p> </li> |
| 320 | <li> |
| 321 | <p><em>Context</em> - An identifier for the rule, this is converted |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 322 | to an integer in the kernel.</p> </li> </ul> |
| 323 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 324 | <p>And so the an example use of this would follow the structure:<br> |
| 325 | <code>allow appdomain app_data_file:file rw_file_perms;</code></p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 326 | |
| 327 | <p>This says an application is allowed to read and write files labeled |
| 328 | app_data_file. During compilation, those overrides are concatenated to the |
| 329 | existing SELinux settings and into a single security policy. These overrides add |
| 330 | to the base security policy rather than subtract from existing settings.</p> |
| 331 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 332 | <p>Once the new policy files and <code>BoardConfig.mk</code> updates are in place, the new |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 333 | policy settings get automatically uploaded to the device.</p> |
| 334 | |
| 335 | <h2 id="validation">Validation</h2> <p>Android strongly encourages OEMs to test |
| 336 | their SELinux implementations thoroughly. As manufacturers implement SELinux, |
| 337 | they should initially release their own policies in permissive mode. If |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 338 | possible, apply the new policy to a test pool of devices first.</p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 339 | |
| 340 | <p>Once applied, make sure SELinux is running in the correct mode on the device |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 341 | by issuing the command: <code>getenforce</code></p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 342 | |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 343 | <p>This will print the global SELinux mode: either Disabled, Enforcing, or Permissive. |
| 344 | Please note, this command shows only the global SELinux mode. To determine the |
| 345 | SELinux mode for each domain, you must examine the corresponding files.</p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 346 | |
Clay Murphy | 15c58c4 | 2013-07-23 11:54:42 -0700 | [diff] [blame] | 347 | <p>Then check for errors. Errors are routed as event logs to <code>dmesg</code> |
| 348 | and viewable locally on the device. Manufacturers should examine the SELinux output |
| 349 | to <code>dmesg</code> on these devices and refine settings prior to public release in |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 350 | permissive mode and eventual switch to enforcing mode.</p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 351 | |
| 352 | <p>With this output, manufacturers can readily identify when system users or |
| 353 | components are in violation of SELinux policy. Manufacturers can then repair |
| 354 | this bad behavior, either by changes to the software, SELinux policy, or |
| 355 | both.</p> |
| 356 | |
| 357 | <p>Specifically, these log messages indicate what roles and processes would fail |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 358 | under policy enforcement and why. Here is an example:</p> |
| 359 | |
| 360 | <pre> |
| 361 | denied { connectto } for pid=2671 comm="ping" path="/dev/socket/dnsproxyd" |
| 362 | scontext=u:r:shell:s0 tcontext=u:r:netd:s0 tclass=unix_stream_socket |
| 363 | </pre> |
| 364 | |
| 365 | <p>Interpret this output like so:</p> |
| 366 | <ul> |
| 367 | <li>The { connectto } above represents the action being taken. Together with the |
| 368 | tclass at the end (unix_stream_socket) it tells you roughly what was being done |
| 369 | to what. In this case, something was trying to connect to a unix stream |
| 370 | socket.</li> |
| 371 | <li>The scontext (u:r:shell:s0) tells you what context initiated the action. In |
| 372 | this case this is something running as the shell.</li> |
| 373 | <li>The tcontext (u:r:netd:s0) tells you the context of the action’s target. In |
| 374 | this case, that’s a unix_stream_socket owned by netd.</li> |
| 375 | <li>The comm="ping" at the top gives you an additional hint about what was being |
| 376 | run at the time the denial was generated. In this case, it’s a pretty good |
| 377 | hint.</li> |
| 378 | </ul> |
| 379 | |
| 380 | <p>Android is taking this information, analyzing |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 381 | it and refining its default security policy so that it works on a wide range of |
| 382 | Android devices with little customization. With this policy, OEMs must only |
| 383 | accommodate their own changes to the Android operating system.</p> |
| 384 | |
| 385 | <p>Then run the SELinux-enabled devices through the <a |
| 386 | href="{@docRoot}compatibility/cts-intro.html">Android |
| 387 | Compatibility Test Suite</a> (CTS).</p> <p>As said, any new policies must still |
| 388 | meet the <a href="{@docRoot}compatibility/index.html">Android |
Clay Murphy | 882fa88 | 2013-10-18 16:43:40 -0700 | [diff] [blame^] | 389 | Compatibility program</a> requirements.</p> |
Clay Murphy | 51dbe2d | 2013-07-22 12:54:07 -0700 | [diff] [blame] | 390 | |
| 391 | <p>Finally, if possible, turn on enforcement internally (on devices of |
| 392 | employees) to raise the visibility of failures. Identify any user issues and |
| 393 | resolve them. </p> <h2 id="help">Help</h2> Device manufacturers are strongly |
| 394 | encouraged to work with their Android account managers to analyze SELinux |
| 395 | results and improve policy settings. Over time, Android intends to support |
| 396 | common manufacturer additions in its default SELinux policy. For more |
| 397 | information, contact <a |
| 398 | href="mailto:security@android.com">security@android.com</a> or Geremy Condra (<a |
| 399 | href="mailto:gcondra@google.com">gcondra@google.com</a>) directly. |