SELinux permissive kernel - is it a security risk?


Question

As in title. I am talking of Kernel, not ROM (plenty of questions dealing with ROM on this site).



I have a OnePlus 7 running stock Android 10 and prefer a custom kernel. Of late, OnePlus hasn't released source for kernel and this has played havoc with all custom kernels in OnePlus 7 and other variants. So, I want to flash a kernel
that is independent of the changes One Plus makes.



Only problem is that it is SELinux permissive and therefore I want to understand the security risks before flashing it.



Edit:

As requested in comments (deleted) :



-# zcat /proc/config.gz | grep CONFIG_SECURITY_SELINUX
CONFIG_SECURITY_SELINUX=y
# CONFIG_SECURITY_SELINUX_BOOTPARAM is not set
# CONFIG_SECURITY_SELINUX_DISABLE is not set
CONFIG_SECURITY_SELINUX_DEVELOP=y
CONFIG_SECURITY_SELINUX_AVC_STATS=y
CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=0
- # zcat /proc/config.gz |grep CONFIG_DEFAULT_SECURITY_SELINUX
CONFIG_DEFAULT_SECURITY_SELINUX=y
-# mount | grep selinuxfs
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)

Answer

SELinux is a security framework which restricts (kernel and userspace) processes within their domains according to defined policy. So the ultimate goal is to load a working policy, label filesystems with proper contexts and set SELinux enforcing. It doesn't matter who does this; kernel or some userspace process, though the sooner the better. And permissive is an SELinux mode always ready to be switched to enforcing mode. However switching other way may or may not be allowed by the policy.



In other words, kernel being SELinux permissive by itself is not a risk, if the the ROM overrides that to make it Enforcing. What SELinux permissive kernel gives you is a flexibility to flash ROMs that demand SELinux permissive or for any other app that needs it. But it is always advisable to keep the device in SELinux Enforcing state (getenforce on Terminal Emulator will reveal).



Mostly ROM developers build kernel with CONFIG_SECURITY_SELINUX_DEVELOP=y. From kernel configuration:




With this option enabled, the kernel will start in permissive mode (log everything, deny nothing) unless you specify enforcing=1 on the kernel command line. You can interactively toggle the kernel between enforcing mode and permissive mode (if permitted by the policy) via /selinux/enforce.




Some vendors may disable the said configuration or may add enforcing=1 boot parameter to kernel cmdline when building boot.img, so that SELinux is always enforcing even before the very first userspace process init is started. Going a step further ahead Samsung kernel sources are patched with options SECURITY_SELINUX_ENFORCING and ALWAYS_ENFORCE. Other extreme is that SELinux is disabled at all by building with SECURITY_SELINUX_DISABLE=y and writing to /sys/fs/selinux/disable, or by building with SECURITY_SELINUX_BOOTPARAM=y and passing selinux=0 kernel parameter.



Starting kernel in permissive mode gives the ROM developer and end users freedom to set SELinux mode permissive or enforcing on boot (or even during running OS by writing to /sys/fs/selinux/enforce), and develop a policy according to the requirements. That's how userdebug/eng builds of ROMs are debugged. init can be forced to set SELinux permissive on boot by setting androidboot.selinux=permissive boot parameter.



OEMs switch to user builds when releasing stock ROMs once sepolicy is fully developed. init on user builds always sets SELinux enforcing, so it won't boot with SELinux disabled. Custom ROMs, however, usually remain userdebug which allow root access (adb root and /system/xbib/su) and other relaxations. Some more details can be found in What sepolicy context will allow any other context to access it?



So while disabled or permissive SELinux in kernel or ROM makes the device equally vulnerable, a permissive kernel is usually a good thing (at least for ROM developers and power users). Enforcing kernel is an overkill unless the user is glued to the stock ROM throughout life of a device. However if SELinux is disabled (e.g. built without CONFIG_SECURITY_SELINUX=y), stock ROM will get into bootloop.




  • If kernel is built with CONFIG_IKCONFIG, extract-ikconfig shell script can be used to check build configuration without flashing to device. On running OS zcat /proc/config.gz can be used.

  • ROM build type can be checked with getprop ro.build.type.

  • Kernel commandline boot parameters can be checked by extracting boot.img. On running OS cat /proc/cmdline can be used.


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