blob: 4d5a63b7cb9aebac91f58694492b5945bb59aa43 [file] [log] [blame]
Clay Murphy882fa882013-10-18 16:43:40 -07001page.title=Validating Security-Enhanced Linux in Android
Clay Murphy51dbe2d2013-07-22 12:54:07 -07002@jd:body
3
4<!--
Stephen Smalleyd330d3e2014-03-14 15:28:51 -04005 Copyright 2014 The Android Open Source Project
Clay Murphy51dbe2d2013-07-22 12:54:07 -07006
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 Murphy882fa882013-10-18 16:43:40 -070019<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 Murphy51dbe2d2013-07-22 12:54:07 -070026
Clay Murphy882fa882013-10-18 16:43:40 -070027<h2 id="introduction">Introduction</h2>
28<p>
29As part of the Android <a href="{@docRoot}devices/tech/security/index.html">security
Stephen Smalleyd330d3e2014-03-14 15:28:51 -040030model</a>, Android uses Security-Enhanced Linux (SELinux) to enforce Mandatory
31Access Control (MAC) over all processes, even processes running
32with root/superuser privileges (a.k.a. Linux capabilities). SELinux enhances
33Android security, and contributions to it have been made by a number of
34companies and organizations; all Android code and contributors are publicly
35available for review on
36<a href="https://android.googlesource.com/">android.googlesource.com</a>. With
37SELinux, Android can better protect and confine system services, control access
38to application data and system logs, reduce the effects of malicious software,
39and protect users from potential flaws in code on mobile devices.
Clay Murphy882fa882013-10-18 16:43:40 -070040</p>
41<p>
42Android includes SELinux in enforcing mode and a corresponding security policy
43that works by default across the <a
44href="https://android.googlesource.com/">Android Open Source
45Project</a>. In enforcing mode, illegitimate
46actions are prevented and all potential violations are logged by the kernel to
Stephen Smalleyd330d3e2014-03-14 15:28:51 -040047<code>dmesg</code>. Android device manufacturers should gather information about
48errors so they may refine their software and SELinux policies before enforcing
49them.
Clay Murphy882fa882013-10-18 16:43:40 -070050</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -070051
Clay Murphy882fa882013-10-18 16:43:40 -070052<h2 id="background">Background</h2>
53<p>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -040054SELinux can operate in one of two global modes: permissive mode, in
55which permission denials are logged but not enforced, and enforcing
56mode, in which permission denials are both logged and
57enforced. SELinux also supports a per-domain permissive mode in which
58specific domains (processes) can be made permissive while placing the
59rest of the system in global enforcing mode. A domain is simply a
60label identifying a process or set of processes in the security
61policy, where all processes labeled with the same domain are treated
62identically by the security policy. Per-domain permissive mode enables
63incremental application of SELinux to an ever-increasing portion of
64the system. Per-domain permissive mode also enables policy
65development for new services while keeping the rest of the system
66enforcing.
Clay Murphy882fa882013-10-18 16:43:40 -070067</p>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -040068
Clay Murphy882fa882013-10-18 16:43:40 -070069<p>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -040070In Android 4.3, SELinux was fully permissive. In Android 4.4, SELinux
71was made enforcing for the domains for several root processes:
72<code>installd</code>, <code>netd</code>, <code>vold</code> and
73<code>zygote</code>. <em>All other processes, including other
74services and all apps, remain in permissive mode to allow further
75evaluation and prevent failures in Android 4.4. Still, an errant
76application could trigger an action in a root process that is not
77allowed, thereby causing the process or the application to crash.</em>
Clay Murphy882fa882013-10-18 16:43:40 -070078</p>
79<p>
80For this reason, device manufacturers should retain the default settings
Stephen Smalleyd330d3e2014-03-14 15:28:51 -040081provided by Android and limit enforcing mode to system services only until
Clay Murphy882fa882013-10-18 16:43:40 -070082they've resolved issues reported in dmesg. That said, device manufacturers may
83need to augment their SELinux implementation to account for their additions and
84other changes to the operating system. See the <em>Customization</em> section for
85instructions.
86</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -070087
Clay Murphy882fa882013-10-18 16:43:40 -070088<h2 id="mac">Mandatory access control</h2>
89<p>
90In conjunction with other Android security measures, Android's access control
91policy greatly limits the potential damage of compromised
92machines and accounts. Using tools like Android's discretionary and mandatory
93access controls gives you a structure to ensure your software runs
94only at the minimum privilege level. This mitigates the effects of
95attacks and reduces the likelihood of errant processes overwriting or even
96transmitting data.
97</p>
98<p>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -040099Starting in Android 4.3, SELinux provides a mandatory access control (MAC)
100umbrella over traditional discretionary access control (DAC) environments.
101For instance, software must typically run as the root user account to write
102to raw block devices. In a traditional DAC-based Linux environment, if the root
103user becomes compromised that user can write to every raw block device. However,
104SELinux can be used to label these devices so the process assigned the root
105privilege can write to only those specified in the associated policy. In this
106way, the process cannot overwrite data and system settings outside of the
107specific raw block device.
Clay Murphy882fa882013-10-18 16:43:40 -0700108</p>
109<p>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400110See the <em>Use Cases</em> section for more examples of threats and ways to
111address them with SELinux.
Clay Murphy882fa882013-10-18 16:43:40 -0700112</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700113
Clay Murphy882fa882013-10-18 16:43:40 -0700114<h2 id="implementation">Implementation</h2>
115<p>
116Android's SELinux implementation is in enforcing mode - rather than the
117non-functional disabled mode or the notification-only permissive mode - to act
118as a reference and facilitate testing and development. Although enforcing mode
119is set globally, please remember this can be overridden on a per-domain basis
120as is in the case of the application domain.
121</p>
122<p>
123SELinux for Android is accompanied by everything you need to enable SELinux
124now. You merely need to integrate the <a
125href="https://android.googlesource.com/kernel/common/">latest Android
126kernel</a> and then incorporate the files found in the
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700127<a
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400128href="https://android.googlesource.com/platform/external/sepolicy/">
129external/sepolicy</a> directory:<br/>
130<a
131href="https://android.googlesource.com/kernel/common/">
132https://android.googlesource.com/kernel/common/</a>
Clay Murphy882fa882013-10-18 16:43:40 -0700133<br/>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700134<a
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400135href="https://android.googlesource.com/platform/external/sepolicy/">
136https://android.googlesource.com/platform/external/sepolicy/</a>
Clay Murphy882fa882013-10-18 16:43:40 -0700137</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700138
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400139<p>
Clay Murphy882fa882013-10-18 16:43:40 -0700140 Those files when compiled comprise the SELinux kernel security policy and cover
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400141the upstream Android operating system. You should not need to modify
142the <root>external/sepolicy</root> files directly. Instead, add your own
143device-specific policy files within the
144<root>/device/manufacturer/device-name/sepolicy directory.
145</p>
146
147<p>
148Then just update your <code>BoardConfig.mk</code> makefile - located in the
149<device-name> directory containing the sepolicy subdirectory - to reference the
150sepolicy subdirectory and any policy file once created, as shown below. The
151BOARD_SEPOLICY variables and their meaning is documented in the
152external/sepolicy/README file.
Clay Murphy882fa882013-10-18 16:43:40 -0700153</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700154
Clay Murphy15c58c42013-07-23 11:54:42 -0700155<pre>
Nick Kralevich4d1a3502014-01-22 16:17:10 -0800156BOARD_SEPOLICY_DIRS += \
Clay Murphy15c58c42013-07-23 11:54:42 -0700157 &lt;root&gt;/device/manufacturer/device-name/sepolicy
158
Nick Kralevich4d1a3502014-01-22 16:17:10 -0800159BOARD_SEPOLICY_UNION += \
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400160 genfs_contexts \
161 file_contexts \
162 sepolicy.te
Clay Murphy15c58c42013-07-23 11:54:42 -0700163</pre>
164
Clay Murphy882fa882013-10-18 16:43:40 -0700165<p>
166After rebuilding your device, it is enabled with SELinux. You can now either
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700167customize your SELinux policies to accommodate your own additions to the Android
168operating system as described in the <em>Customization</em> section or verify
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400169your existing setup as covered in the <em>Validation</em> section.
Clay Murphy882fa882013-10-18 16:43:40 -0700170</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700171
Clay Murphy882fa882013-10-18 16:43:40 -0700172<h2 id="customization">Customization</h2>
173<p>
174Once you've integrated this base level of functionality and thoroughly analyzed
175the results, you may add your own policy settings to cover your customizations
176to the Android operating system. Of course, these policies must still meet the
177<a href="http://source.android.com/compatibility/index.html">Android
178Compatibility
179program</a> requirements and
180not remove the default SELinux settings.
181</p>
182<p>
183Manufacturers should not remove existing security settings. Otherwise, they risk
184breaking the Android SELinux implementation and the applications it governs.
185This includes third-party applications that will likely need to be improved to
186be compliant and operational. Applications must require no modification to
187continue functioning on SELinux-enabled devices.
188</p>
189<p>
190See the <em>Kernel Security Features</em> section of the Android Compatibility
191Definition document for specific requirements:<br/>
192<a
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400193href="http://source.android.com/compatibility/index.html">
194http://source.android.com/compatibility/index.html</a>
Clay Murphy882fa882013-10-18 16:43:40 -0700195</p>
196<p>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400197SELinux uses a whitelist approach, meaning all access must be explicitly allowed
198in policy in order to be granted. Since Android's default SELinux policy already
199supports the Android Open Source Project, OEMs are not required to modify
200SELinux settings in any way. If they do customize SELinux settings, they should
201take great care not to break existing applications. Here is how we recommend
202proceeding:
Clay Murphy882fa882013-10-18 16:43:40 -0700203</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700204
Clay Murphy15c58c42013-07-23 11:54:42 -0700205<ol>
Clay Murphy882fa882013-10-18 16:43:40 -0700206<li>Use the <a href="https://android.googlesource.com/kernel/common/">latest
207Android
208kernel</a>.</li>
209<li>Adopt the <a
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700210href="http://en.wikipedia.org/wiki/Principle_of_least_privilege">principle of
Clay Murphy882fa882013-10-18 16:43:40 -0700211least
212privilege</a>.</li>
213<li>Address only your own additions to Android. The default policy works with
214the
215<a href="https://android.googlesource.com/">Android Open Source Project</a>
216codebase
217automatically.</li>
218<li>Compartmentalize software components into modules that conduct singular
219tasks.</li>
220<li>Create SELinux policies that isolate those tasks from unrelated
221functions.</li>
222<li>Put those policies in *.te files (the extension for SELinux policy source
223files) within the <root>/device/manufacturer/device-name/sepolicy
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400224directory and use BOARD_SEPOLICY variables to include them in your build.</li>
225<li>Make new domains permissive initially. In Android 4.4 and earlier, this
226is done using a permissive declaration. In later versions of Android,
227per-domain permissive mode is specified using the permissive_or_unconfined()
228macro.</li>
229<li>Analyze results and refine your domain definitions.</li>
230<li>Remove the permissive declaration when no further denials appear
231in userdebug builds.</li>
Clay Murphy15c58c42013-07-23 11:54:42 -0700232</ol>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700233
Clay Murphy882fa882013-10-18 16:43:40 -0700234<p>
235Once integrated, OEM Android development should include a step to ensure
236SELinux
237compatibility going forward. In an ideal software development process, SELinux
238policy changes only when the software model changes and not the actual
239implementation.
240</p>
241<p>
242As device manufacturers begin to customize SELinux, they should first audit
243their additions to Android. If they've added a component that conducts a new
244function, the manufacturers will need to ensure the component meets the security
245policy applied by Android, as well as any associated policy crafted by the OEM,
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400246before turning on enforcing mode.
Clay Murphy882fa882013-10-18 16:43:40 -0700247</p>
248<p>
249To prevent unnecessary issues, it is better to be overbroad and over-compatible
250than too restrictive and incompatible, which results in broken device functions.
251Conversely, if a manufacturer's changes will benefit others, it should supply
252the modifications to the default SELinux policy as a
253<a href="http://source.android.com/source/submit-patches.html">patch</a>. If the
254patch is
255applied to the default security policy, the manufacturer will no longer need to
256make this change with each new Android release.
257</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700258
259<h2 id="use-cases">Use Cases</h2> <p>Here are specific examples of exploits to
260consider when crafting your own software and associated SELinux policies:</p>
261
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400262<p><strong>Symlinks</strong> - Because symlinks appear as files, they are often
263read just as that. This can lead to exploits. For instance, some privileged
264components such as <code>init</code> change the permissions of certain files,
265sometimes to be excessively open.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700266
267<p>Attackers might then replace those files with symlinks to code they control,
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400268allowing the attacker to overwrite arbitrary files. But if you know your
269application will never traverse a symlink, you can prohibit it from doing so
270with SELinux.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700271
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400272<p><strong>System files</strong> - Consider the class of system files that
273should only be modified by the system server. Still, since <code>netd</code>,
274<code>init</code>, and <code>vold</code> run as root, they can access those
275system files. So if <code>netd</code> became compromised, it could compromise
276those files and potentially the system server itself.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700277
278<p>With SELinux, you can identify those files as system server data files.
279Therefore, the only domain that has read/write access to them is system server.
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400280Even if <code>netd</code> became compromised, it could not switch domains to the
Clay Murphy15c58c42013-07-23 11:54:42 -0700281system server domain and access those system files although it runs as root.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700282
Clay Murphy15c58c42013-07-23 11:54:42 -0700283<p><strong>App data</strong> - Another example is the class of functions that
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400284must run as root but should not get to access app data. This is incredibly
285useful as wide-ranging assertions can be made, such as certain domains
286unrelated to application data being prohibited from accessing the internet.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700287
Clay Murphy15c58c42013-07-23 11:54:42 -0700288<p><strong>setattr</strong> - For commands such as <code>chmod</code> and
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400289<code>chown</code>, you could identify the set of files where the associated
290domain can conduct <code>setattr</code>. Anything outside of that could be
291prohibited from these changes, even by root. So an application might run
292<code>chmod</code> and <code>chown</code> against those labeled app_data_files
293but not shell_data_files or system_data_files.</p>
294
295<h2 id="related-files">Related Files</h2>
296<p>This section serves to guide you once you&rsquo;ve decided to
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700297customize the SELinux policy settings. See the <em>Customization</em> section
298for steps. We recommend device manufacturers start with the default Android
299SELinux policy and make the minimum possible set of changes to address their
300additions to Android. Existing Android SELinux policy files are found in the
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400301root of the <a
302href="https://android.googlesource.com/platform/external/sepolicy/">
303external/sepolicy</a> directory.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700304
305<p>Android upgraded its SELinux policy version to allow the SELinux mode to be
306set to permissive on a per-domain basis. For example, if you run all of your
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400307applications in a single domain, you could set that domain to be permissive and
308then have all other functions and their domains set to enforcing. Domains are
309associated with applications by the key used to sign each application. The
310mapping of app certificates to domains is specified via the
311mac_permissions.xml and seapp_contexts configuration files.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700312
313<p>Here are the files you must create or edit in order to customize SELinux:</p>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400314<ul>
Clay Murphy15c58c42013-07-23 11:54:42 -0700315<li>
316<p><em>New SELinux policy source (*.te) files</em> - Located in the
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700317&lt;root&gt;/device/manufacturer/device-name/sepolicy directory These files
318define domains and their labels. The new policy files get concatenated with the
319existing policy files during compilation into a single SELinux kernel policy
Clay Murphy882fa882013-10-18 16:43:40 -0700320file.</p>
321<p><strong>Important</strong>:Do not alter the app.te file provided by the
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400322Android Open Source Project. Doing so risks breaking all third-party
323applications.
Clay Murphy882fa882013-10-18 16:43:40 -0700324</p>
325</li>
Clay Murphy15c58c42013-07-23 11:54:42 -0700326<li>
327<p><em>Updated <code>BoardConfig.mk</code> makefile</em> - Located in the
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700328&lt;device-name&gt; directory containing the sepolicy subdirectory. It must be
329updated to reference the sepolicy subdirectory once created if it wasn&rsquo;t
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400330in initial implementation.</p> </li>
Clay Murphy15c58c42013-07-23 11:54:42 -0700331<li>
332<p><em>Updated <code>file_contexts</code></em> - Located in
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700333the sepolicy subdirectory. It labels files and is managed in the userspace. As
334you create new policies, update this file to reference them. In order to apply
Clay Murphy15c58c42013-07-23 11:54:42 -0700335new <code>file_contexts</code>, you must run <code>restorecon</code> on the file
336to be relabeled.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700337</li> </ul>
338
Clay Murphy15c58c42013-07-23 11:54:42 -0700339<p>The remaining files in the sepolicy directory are either auto-generated or
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400340should remain static. The policy rules come in the form: allow <em>domains</em>
341<em>types</em>:<em>classes</em> <em>permissions</em>;, where:</p>
Clay Murphy15c58c42013-07-23 11:54:42 -0700342<ul>
343<li>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400344<p><em>Domain</em> - A label for the process or set of processes.
345</p></li>
Clay Murphy15c58c42013-07-23 11:54:42 -0700346<li>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400347<p><em>Type</em> - A label for the object (e.g. file, socket) or set of objects.
348</p></li>
Clay Murphy15c58c42013-07-23 11:54:42 -0700349<li>
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400350<p><em>Class</em> - The kind of object (e.g. file, socket) being accessed.
351</p></li>
352<li>
353<p><em>Permission</em> - The operation (e.g. read, write) being performed.
354</p></li>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700355
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400356<p>And so an example use of this would follow the structure:<br>
Clay Murphy15c58c42013-07-23 11:54:42 -0700357<code>allow appdomain app_data_file:file rw_file_perms;</code></p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700358
359<p>This says an application is allowed to read and write files labeled
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400360app_data_file. Note that this rule relies upon macros defined in the
361global_macros file, and other helpful macros can also be found in the
362te_macros file. Macros are provided for common groupings of classes,
363permissions and rules, and should be used whenever possible to help reduce the
364likelihood of failures due to denials on related permissions. During
365compilation, those overrides are concatenated to the existing SELinux settings
366and into a single security policy. These overrides add to the base security
367policy rather than subtract from existing settings.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700368
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400369<p>Once the new policy files and <code>BoardConfig.mk</code> updates are in
370place, the new policy settings are automatically built into the final kernel
371policy file.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700372
373<h2 id="validation">Validation</h2> <p>Android strongly encourages OEMs to test
374their SELinux implementations thoroughly. As manufacturers implement SELinux,
375they should initially release their own policies in permissive mode. If
Clay Murphy882fa882013-10-18 16:43:40 -0700376possible, apply the new policy to a test pool of devices first.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700377
378<p>Once applied, make sure SELinux is running in the correct mode on the device
Clay Murphy15c58c42013-07-23 11:54:42 -0700379by issuing the command: <code>getenforce</code></p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700380
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400381<p>This will print the global SELinux mode: either Disabled, Enforcing, or
382Permissive.
Clay Murphy882fa882013-10-18 16:43:40 -0700383Please note, this command shows only the global SELinux mode. To determine the
384SELinux mode for each domain, you must examine the corresponding files.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700385
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400386<p>Then check for errors. Errors are routed as event logs to <code>dmesg</code>
387and viewable locally on the device. Manufacturers should examine the SELinux
388output to <code>dmesg</code> on these devices and refine settings prior to
389public release in permissive mode and eventual switch to enforcing mode. It is
390possible to capture the ongoing denial logs by running
391<code>cat /proc/kmsg</code> or to capture denial logs from the previous boot by
392running <code>cat /proc/last_kmsg</code>.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700393
394<p>With this output, manufacturers can readily identify when system users or
395components are in violation of SELinux policy. Manufacturers can then repair
396this bad behavior, either by changes to the software, SELinux policy, or
397both.</p>
398
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400399<p>Specifically, these log messages indicate what processes would fail
400under enforcing mode and why. Here is an example:</p>
Clay Murphy882fa882013-10-18 16:43:40 -0700401
402<pre>
403denied { connectto } for pid=2671 comm="ping" path="/dev/socket/dnsproxyd"
404scontext=u:r:shell:s0 tcontext=u:r:netd:s0 tclass=unix_stream_socket
405</pre>
406
407<p>Interpret this output like so:</p>
408<ul>
409<li>The { connectto } above represents the action being taken. Together with the
410tclass at the end (unix_stream_socket) it tells you roughly what was being done
411to what. In this case, something was trying to connect to a unix stream
412socket.</li>
413<li>The scontext (u:r:shell:s0) tells you what context initiated the action. In
414this case this is something running as the shell.</li>
415<li>The tcontext (u:r:netd:s0) tells you the context of the actions target. In
416this case, thats a unix_stream_socket owned by netd.</li>
417<li>The comm="ping" at the top gives you an additional hint about what was being
418run at the time the denial was generated. In this case, its a pretty good
419hint.</li>
420</ul>
421
422<p>Android is taking this information, analyzing
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700423it and refining its default security policy so that it works on a wide range of
424Android devices with little customization. With this policy, OEMs must only
425accommodate their own changes to the Android operating system.</p>
426
427<p>Then run the SELinux-enabled devices through the <a
428href="{@docRoot}compatibility/cts-intro.html">Android
429Compatibility Test Suite</a> (CTS).</p> <p>As said, any new policies must still
430meet the <a href="{@docRoot}compatibility/index.html">Android
Clay Murphy882fa882013-10-18 16:43:40 -0700431Compatibility program</a> requirements.</p>
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700432
Stephen Smalleyd330d3e2014-03-14 15:28:51 -0400433<p>Finally, if possible, turn on enforcing mode internally (on devices of
Clay Murphy51dbe2d2013-07-22 12:54:07 -0700434employees) to raise the visibility of failures. Identify any user issues and
435resolve them. </p> <h2 id="help">Help</h2> Device manufacturers are strongly
436encouraged to work with their Android account managers to analyze SELinux
437results and improve policy settings. Over time, Android intends to support
438common manufacturer additions in its default SELinux policy. For more
439information, contact <a
Clay Murphy78beecd2013-11-05 16:27:26 -0800440href="mailto:security@google.com?subject=se-linux">security@android.com</a>.