Search code examples
androidselinux

How does Termux get around the SELinux restriction on running programs?


I see that Termux has its executable files in /data/data/com.termux/files/usr. Execution from this location must be prohibited by SELinux policies. How it works?

Thanks.


Solution

  • Actually any Android App can run executable files natively, using the Android's Os class. It provides low-level functionality to the app, which also includes running executables. So, basically, Termux is just a bridge between this API and the user.

    However, Android has updated its policy after Android 10, and apps can't run executables natively.

    Untrusted apps that target Android 10 cannot invoke exec() on files within the app's home directory.

    From the official Termux website

    Applications built with target SDK level 29 (means compatibility with Android 10) will no longer be able to execute data files. All executables must be packaged within the APK file. That's a reasonable restriction. Application must not be able to modify itself. Updates and new features must come within the APK of newer version. However there is a problem: Termux is technically a bridge between Android application and Linux environments.

    Fortunately, we chose to force use compatibility with Android 9 APIs (SDK 28) at the cost of ability to publish updates on Google Play. That is until we will workaround the issue. For now do not worry - it works perfectly.

    And that's also why, Termux updates are not coming on Play Store and you need to download the updates from F-Droid.