| <html devsite><head> |
| <title>Android 中的安全增强型 Linux</title> |
| <meta name="project_path" value="/_project.yaml"/> |
| <meta name="book_path" value="/_book.yaml"/> |
| </head> |
| <body> |
| <!-- |
| Copyright 2017 The Android Open Source Project |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <p>Android 安全模型部分基于应用沙盒的概念。每个应用都在自己的沙盒内运行。在 Android 4.3 之前的版本中,这些沙盒是通过为每个应用创建独一无二的 Linux UID(在应用安装时创建)来定义的。从 Android 4.3 版起,安全增强型 Linux (SELinux) 开始用于进一步定义 Android 应用沙盒的边界。</p> |
| |
| <aside class="note"><strong>注意</strong>:要详细了解 Android 8.0 SELinux,请参阅 <a href="/security/selinux/images/SELinux_Treble.pdf">SELinux for Android 8.0</a>。</aside> |
| |
| <p>作为 Android <a href="/security/index.html">安全模型</a>的一部分,Android 使用 SELinux 对所有进程强制执行强制访问控制 (MAC),其中包括以 Root/超级用户权限运行的进程(也称为 Linux 功能)。SELinux 能够限制特权进程并能够自动创建安全政策,从而可提升 Android 的安全性。</p> |
| |
| <p>很多公司和组织都为 SELinux 做出了贡献;<a href="https://android.googlesource.com/" class="external">android.googlesource.com</a>(也称为 Android 开放源代码项目 (AOSP))上公开了他们所做的贡献,以供所有人查看。借助 SELinux,Android 可以更好地保护和限制系统服务、控制对应用数据和系统日志的访问、降低恶意软件的影响,并保护用户免遭移动设备上的代码可能存在的缺陷的影响。</p> |
| |
| <p>Android 中包含 SELinux(处于强制模式)和默认适用于整个 AOSP 的相应安全政策。在强制模式下,非法操作会被阻止,并且尝试进行的所有违规行为都会被内核记录到 <code>dmesg</code> 和 <code>logcat</code> 中。Android 设备制造商应收集与错误相关的信息,以便在实施其软件和 SELinux 政策之前先对其进行优化。</p> |
| |
| <h2 id="background">背景</h2> |
| <p>SELinux 按照默认拒绝的原则运行:任何未经明确允许的行为都会被拒绝。SELinux 可按两种全局模式之一运行:</p> |
| <ul> |
| <li><em></em>宽容模式:权限拒绝事件会被记录下来,但不会被强制执行。</li> |
| <li><em></em>强制模式:权限拒绝事件会被记录下来<strong>并</strong>强制执行。</li> |
| </ul> |
| |
| <p>此外,SELinux 还支持基于域的宽容模式。在这种模式下,可将特定域(进程)设为宽容模式,同时使系统的其余部分处于强制全局模式。<em></em>域简单来说就是安全政策中用于标识一个进程或一组进程的标签,安全政策会以相同的方式对待所有具有相同域标签的进程。借助基于域的宽容模式,可逐渐将 SELinux 应用于系统中越来越多的部分,还可以为新服务制定政策(同时确保系统的其余部分处于强制模式)。</p> |
| |
| <p>基于 Android 4.3(宽容模式)和 Android 4.4(部分强制模式)的 Android 5.0 版本,开始全面强制执行 SELinux。 |
| 通过此项变更,Android 已从对有限的一组关键域(<code>installd</code>、<code>netd</code>、<code>vold</code> 和 <code>zygote</code>)强制执行 SELinux 转为对所有域(超过 60 个域)强制执行 SELinux。具体而言:</p> |
| |
| <ul> |
| <li>在 Android 5.x 及更高版本中,所有域均处于强制模式。</li> |
| <li><code>init</code> 以外的任何进程都不应在 <code>init</code> 域中运行。</li> |
| <li>如果出现任何常规拒绝事件(对于 <code>block_device</code>、<code>socket_device</code>、<code>default_service</code> 等),都表示设备需要一个特殊域。</li> |
| </ul> |
| <p>因此,制造商需要更好地了解并扩展其 SELinux 实现,以便提供兼容的设备。</p> |
| |
| <h2 id="supporting_documentation">其他资源</h2> |
| |
| <p>如需关于构建实用 SELinux 政策的帮助,请参阅以下资源:</p> |
| |
| <ul><li><a href="https://events.linuxfoundation.org/sites/events/files/slides/abs2014_seforandroid_smalley.pdf" class="external"> |
| Security Enhancements for Linux(针对 Linux 的安全增强功能)</a></li> |
| |
| <li><a href="http://www.cs.columbia.edu/~lierranli/coms6998-7Spring2014/papers/SEAndroid-NDSS2013.pdf" class="external"> |
| Security Enhanced (SE) Android: Bringing Flexible MAC to Android(安全增强 (SE) Android:在 Android 中引入灵活 MAC)</a></li> |
| |
| <li><a href="http://freecomputerbooks.com/books/The_SELinux_Notebook-4th_Edition.pdf" class="external"> |
| The SELinux Notebook, 4th Edition(SELinux 手册第 4 版)</a></li> |
| |
| <li><a href="http://selinuxproject.org/page/ObjectClassesPerms" class="external"> |
| SELinux Object Classes and Permissions Reference(SELinux 对象类和权限参考)</a></li> |
| |
| <li><a href="https://www.nsa.gov/resources/everyone/digital-media-center/publications/research-papers/assets/files/implementing-selinux-as-linux-security-module-report.pdf" class="external"> |
| Implementing SELinux as a Linux Security Module(将 SELinux 作为 Linux 安全模块实现)</a></li> |
| |
| <li><a href="https://www.nsa.gov/resources/everyone/digital-media-center/publications/research-papers/assets/files/configuring-selinux-policy-report.pdf" class="external"> |
| Configuring the SELinux Policy(配置 SELinux 政策)</a></li> |
| |
| <li><a href="https://www.gnu.org/software/m4/manual/index.html" class="external"> |
| GNU M4 - GNU Macro Processor Manual(GNU M4 - GNU 宏处理器手册)</a></li> |
| </ul> |
| |
| </body></html> |