termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
35.58k stars 3.73k forks source link

[Bug]: Android 14: libtermux-exec does not work reliably #3758

Closed dead10ck closed 9 months ago

dead10ck commented 9 months ago

Problem description

There seems to be something wrong with the libtermux-exec library that wraps execve to handle shebangs on Android 14. In some contexts, it can run scripts fine, but in others, such as with env or nushell instead of bash, it fails with a no such file error.

Steps to reproduce the behavior.

If you take this example script:

#!/usr/bin/python

print("hello")

It can execute with ./foo.py:

~ $ ./foo.py
hello

But if you try to run it with env, it fails saying it can't find it

~ $ env ./foo.py
env: ‘./foo.py’: No such file or directory

I tried to poke around the libtermux-exec code, and I was able to find the environment variable that enables debug printing. When used, you can see that when it fails with the "no such file" error, it seems that it does not run the wrapper function at all

~ $ TERMUX_ANDROID10_DEBUG=yes ./foo.py
execve(./foo.py):
  ./foo.py
hello
~ $ env TERMUX_ANDROID10_DEBUG=yes ./foo.py
env: ‘./foo.py’: No such file or directory
~ $ TERMUX_ANDROID10_DEBUG=yes env ./foo.py
execve(/data/data/com.termux/files/usr/bin/env):
  env
  ./foo.py
env: ‘./foo.py’: No such file or directory

What is the expected behavior?

No response

System information

sylirre commented 9 months ago

Standard version of termux-exec handles only execve() function from libc. It doesn't handle other exec functions, neither the execve() Linux system call (this one can't be handled through LD_PRELOAD, only by proot).

Try building and installing termux-exec with changes from https://github.com/termux/termux-exec/pull/24.

dead10ck commented 9 months ago

@sylirre I can confirm through strace that only execve is being called, not a variant. You can see from my reproduction example that the case is dead simple, nothing exotic happening.

agnostic-apollo commented 9 months ago

env calls executable passed with execvp(), which is currently not hooked, will be fixed when the termux-exec branch linked is merged.

arndtc commented 3 months ago

I'm still seeing this issue in Android 14, but it is marked as closed. I went to the quoted thread, which appears to be open, so it isn't clear whey this thread is marked as closed, since the issue still isn't resolved.

env and even nice continue to show this issue.

I'm using the build from FDROID, rather than the play-story version. Does that make a difference?

$ termux-info
Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=5677
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.1
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.dev/apt/termux-main/ stable main
# root-repo (sources.list.d/root.list)
deb https://mirror.autkin.net/termux/termux-root root stable
Updatable packages:
All packages up to date
termux-tools version:
1.42.4
Android version:
14
Kernel build information:
Linux localhost 5.10.198-android13-4-00047-g7a2aa337ab82-ab11664978 #1 SMP PREEMPT Wed Apr 3 07:17:30 UTC 2024 aarch64 Android
Device manufacturer:
Google
Device model:
Pixel 6a
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.window versionCode:15
com.termux.widget versionCode:13
com.termux.styling versionCode:1000
com.termux.api versionCode:51
com.termux.boot versionCode:1000
com.termux.tasker versionCode:6
arndtc commented 3 months ago

Okay, so after some additional digging around I found a work around, though this doesn't appear to be an official fix yet.

There is a zip file with a new termux-exec attached to the following comments:

I downloaded this zip and extracted it. I used termux-info to file the particular arch I needed. Then unzipped the file and ran the following: dpkg -i termux-exec_2.0.0_aarch64.deb

This seems to have solved the problems I was seeing.