termux / termux/termux-exec-package
Launching Termux from unrestricted ADB and ADB-like entrypoint process contexts fails to exempt system linker exec
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 265
- Forks
- 87
- PR merge metrics
- No merged PRs in 30d
Description
@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:
-
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.
-
Reproduced the bug you experienced in MagiskSSH
-
Reproduced the bug consistently in several other entrypoints that are very similar to Magisk and MagiskSSH, including but not limited to KernelSU
-
Found what seems in my opinion to be the exact root cause of the bug
-
Created upstream PRs to attempt to contribute a solution to the bug
-
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.
- 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 isrun-as, which works from normal ADB shell, andrun-asdoes 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.
- 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 installneovimand 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 usebuild-package.shand.debfiles 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
- Connect to ADB shell from somewhere
adb shell
- Alternative entrypoints
[!TIP]
For entrypoints requiring Termux's real userid explicitly, don't forget to usewhoami,id -uandid -gin Termux App beforehand and then replace the number in the examples with the matching number from your installation of Termux
- AOSP
suentrypoint (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-asentrypoint (rooted device not required):
run-as com.termux /data/data/com.termux/files/usr/bin/sh -l -c login
- 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:
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the termux-exec package and the alternative-entrypoint patch linked in the report, then reproduce the issue through ADB, KernelSU, Magisk, or run-as. Use the provided nvim headless command to compare the expected libexec path with the linker path, and review the linked pull requests to see what remains unresolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, c
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100