Skip to content

Launching Termux from unrestricted ADB and ADB-like entrypoint process contexts fails to exempt system linker exec #40

Description

@robertkirkman

@calebROlson I have confirmed that your problem has a root cause specific to ADB and ADB-like setups, not directly related to the original issue you posted in which was someone using an unidentified Termux APK, not ADB, so I am opening a different post here to continue the discussion in a more appropriate location.

After working on it for a while, I have:

  1. Managed to install and test Magisk and MagiskSSH in my AVD; the problem for me was, like you suggested, that I had to specify the newest version of Magisk instead of the script's default.

  2. Reproduced the bug you experienced in MagiskSSH

  3. Reproduced the bug consistently in several other entrypoints that are very similar to Magisk and MagiskSSH, including but not limited to KernelSU

  4. Found what seems in my opinion to be the exact root cause of the bug

  5. Created upstream PRs to attempt to contribute a solution to the bug

  6. Created this guide for using the alternative ADB and ADB-like entrypoints to Termux in the way I would suggest they be used, including steps for how to download and install my PRs into the Termux that is being prepared; you don't have to change to this setup, but this is just what I would use personally instead of the exact way you set it up.


  1. Install the Termux Debug APK from GitHub https://github.com/termux/termux-app/releases

Tip

You must have either root, or a Termux Debug-mode APK (the Termux APK from GitHub, not from F-Droid) because the only su implementation that works as non-root is run-as, which works from normal ADB shell, and run-as does not work on Release-mode Termux APKs, only Debug-mode APKs like the ones from Termux GitHub. If you have root, then the root entrypoints will work on the Release-mode F-Droid Termux APK.

  1. Open Termux from the shortcut normally and prepare it for alternative entrypoints

Note

If you are frustrated/disappointed by the requirement to run some commands that install a huge amount of packages here and a long setup script, rather than your preference to only install neovim and be done, the reason is basically because the root cause of the issue is in a precompiled C code part of Termux, so in order to fully fix the symptoms while the fix PRs are not merged, it's necessary to at the very least install a C compiler and recompile the specific code that is causing the problem, and at that point it's more convenient and reliable overall to just use build-package.sh and .deb files to manage that binary, which significantly bloats the setup time on clean installed Termux.

yes | pkg upgrade -y # very important - copy and paste exactly as written
echo "export PREFIX=$PREFIX"   >> $PREFIX/etc/profile.pre
echo "export HOME=$HOME"       >> $PREFIX/etc/profile.pre
echo "export PATH=$PREFIX/bin" >> $PREFIX/etc/profile.pre
echo "export TMPDIR=$TMPDIR"   >> $PREFIX/etc/profile.pre
echo "export TERM=xterm"       >> $PREFIX/etc/profile.pre
pkg install git
git clone https://github.com/termux/termux-packages.git
cd termux-packages
curl https://github.com/termux/termux-core-package/commit/63bf9286ad86603f9a58de73e4c740926c88f5e3.diff > packages/termux-core/0001-alternative-entrypoint.patch
curl https://patch-diff.githubusercontent.com/raw/termux/termux-core-package/pull/2.diff > packages/termux-core/0002-alternative-entrypoint.patch
curl https://patch-diff.githubusercontent.com/raw/termux/termux-exec-package/pull/39.diff > packages/termux-exec/alternative-entrypoint.patch
scripts/setup-termux.sh
./build-package.sh -I -f termux-core termux-exec
cd output
apt reinstall ./*.deb
  1. Connect to ADB shell from somewhere
adb shell
  1. Alternative entrypoints

Tip

For entrypoints requiring Termux's real userid explicitly, don't forget to use whoami, id -u and id -g in Termux App beforehand and then replace the number in the examples with the matching number from your installation of Termux

  • AOSP su entrypoint (rooted device required):
su u0_a117 /data/data/com.termux/files/usr/bin/sh -l -c login  
  • KernelSU entrypoint (rooted device required):
su u0_a117 -g 10117 -G 9997 -c "/data/data/com.termux/files/usr/bin/sh -l -c login"  
  • Magisk entrypoint (rooted device required):
su u0_a117 -i -g 10117 -G 9997 -c "/data/data/com.termux/files/usr/bin/sh -l -c login"
  • run-as entrypoint (rooted device not required):
run-as com.termux /data/data/com.termux/files/usr/bin/sh -l -c login
  1. Test
pkg install neovim
nvim --headless -c 'echo v:progpath' -c 'q' && echo
  • Expected result:
/data/data/com.termux/files/usr/libexec/nvim/nvim
  • Failure result:
/apex/com.android.runtime/bin/linker64

Tested using two separate Android Studio Android Virtual Devices that had these two installers run on them respectively:

(KernelSU for AVD) https://github.com/robertkirkman/kernelsu-goldfish-builder
(Magisk for AVD) https://gitlab.com/newbit/rootAVD

PRs:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions