You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixed: Abort execve() with a debug error if argv[0] length is >= 128 on Android < 6 instead of letting process fail post execve() without an error
For Android `< 6`, the length must not be `>= 128` for the `argv[0]` string of an `execve()` call or library path of a `dlopen()` call.
The `soinfo_alloc()` function in `linker.cpp` of Android `/system/bin/linker*` that loaded the `soinfo` of a library/executable had a `SOINFO_NAME_LEN=128` limit on the path/name passed to it before aae859cc, after which it was increased to `PATH_MAX`. Earlier, if path passed was `>= 128`, then `library name "<library_name>" too long` error would occur.
Before dcaef371, the `__linker_init_post_relocation()` function also passed `argv[0]` as executable path to `soinfo_alloc()` function to load its `soinfo`, instead of the actual absolute path of the executable. So before aae859cc, if either length was `>= 128`, then the process would abort with exit code `1`. Note that the `execve()` call itself will not fail, failure occurs before `main()` is called. The limit also applies to the interpreter defined in scripts, as interpreter is passed as `argv[0]` during execution.
Both fixes are only available in Android `>= 6`. For earlier versions like Android 5, the path for executables and libraries must be kept below the limit. However, for executables, to allow execution, the `argv[0]` can be shortened even if executable path is longer, or by first changing current working directory to executable's parent directory and then executing it with a relative path.
See also `TERMUX__PREFIX_DIR___MAX_LEN`, `TERMUX__PREFIX__BIN_FILE___SAFE_MAX_LEN`, `FILE_HEADER__BINPRM_BUF_SIZE` and `TERMUX__FILE_HEADER__BUFFER_SIZE`.
```
LD_DEBUG=3 /data/data/com.termux/files/usr/libexec/installed-tests/termux-exec/lib/termux-exec_nos_c_tre/scripts/termux/api/termux_exec/ld_preload/direct/exec/files/print-args-binary arg1; echo $?
1
linker W [ android linker & debugger ]
linker D DEBUG: library name "/data/data/com.termux/files/usr/libexec/installed-tests/termux-exec/lib/termux-exec_nos_c_tre/scripts/termux/api/termux_exec/ld_preload/direct/exec/files/print-args-binary" too long
```
```
(exec -a print-args-binary /data/data/com.termux/files/usr/libexec/installed-tests/termux-exec/lib/termux-exec_nos_c_tre/scripts/termux/api/termux_exec/ld_preload/direct/exec/files/print-args-binary arg1); echo $?
arg1
0
```
```
(cd /data/data/com.termux/files/usr/libexec/installed-tests/termux-exec/lib/termux-exec_nos_c_tre/scripts/termux/api/termux_exec/ld_preload/direct/exec/files && ./print-args-binary arg1); echo $?
arg1
0
```
- https://cs.android.com/android/_/android/platform/bionic/+/dcaef371
- https://cs.android.com/android/_/android/platform/bionic/+/aae859cc
- termux/termux-app#213
Credits to @Grimler91 for finding that it was path length that was causing execution failure for binaries.
Copy file name to clipboardExpand all lines: lib/termux-exec_nos_c_tre/include/termux/termux_exec__nos__c/v1/termux/api/termux_exec/ld_preload/direct/exec/ExecIntercept.h
* linker D DEBUG: library name "/data/data/com.termux/files/usr/libexec/installed-tests/termux-exec/lib/termux-exec_nos_c_tre/scripts/termux/api/termux_exec/ld_preload/direct/exec/files/print-args-binary" too long
94
+
* ```
95
+
*
96
+
* ```
97
+
* (exec -a print-args-binary /data/data/com.termux/files/usr/libexec/installed-tests/termux-exec/lib/termux-exec_nos_c_tre/scripts/termux/api/termux_exec/ld_preload/direct/exec/files/print-args-binary arg1); echo $?
0 commit comments