How to troubleshoot SELinux issues?


Question

On standard GNU/Linux computers, SELinux comes with a set of tools allowing the administrator to troubleshoot permission issues.



Such tools allow to:




  • Temporarily switch a single domain in permissive mode, thus reducing the security impact on the whole device compared to a global permissive mode (and yes, per-domain permissive mode is supported in Android's SELinux): semanage

  • List existing SELinux users, roles and categories (AFAIK categories are used for multi-users devices): semanage, seinfo, chcat

  • Query the SELinux policy: sesearch



I did not find any of these tools in my device.



Is there any equivalent or a way to install them?


Answer

As I feared, Google is against letting people tweak SELinux. This is stated explicitely in the Android Compatibility Definition Document:




SELinux or any other security features implemented below the Android
framework:




  • [...]


  • SHOULD NOT be user or developer configurable.





However, the good news is that there is indeed a FOSS project porting SELinux tools to Android: setools-android. This tools ports the usual seinfo and sesearch commands as can be found in the upstream SELinux Tools project, but it also adds the sepolicy-inject command which allows to modify the current policy or set a domain in permissive mode.



This however suffer from a big issue: unlike on standard computers, modifications made to the /sepolicy file which stores SELinux policy are not persistent and will be lost upon device restart.



In fact, this file as part of the root directory is stored in a RAM disk image which, in turn, is stored in the device's boot image and extracted during the device's boot sequence. To apply permanent modification to this file it is therefore necessary to modify the version stored within the device's boot image.



While the operation may still be possible from the device itself (as far as I know SuperSU for instance updates the boot image as part of its installation procedure), for my use-case I find it more convenient to do the operation from an external computer connected to the phone (here is my detailed procedure). Tools running on the device still remain useful though when frequent checks and updates of the SELinux policy are required (typically during development stages) and for automation (if a project needs a SuperSU-like installer for instance).


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes