termux / proot-distro

An utility for managing installations of the Linux distributions in Termux.
GNU General Public License v3.0
1.67k stars 197 forks source link

Segmentation fault when calling api command inside proot #434

Open ushu3323 opened 3 weeks ago

ushu3323 commented 3 weeks ago

Problem description I can't run succesfully termux-api commands inside proot-distro (using alpine linux), it causes segmentation fault. Works fine on default termux enviroment. I've tested the following commands: "termux-battery-status" "termux-brightness" "termux-volume"

~ $ termux-battery-status
WARNING: linker: /system/vendor/lib/hw/memtrack.clovertrail.so: unused DT entry: type 0xf arg 0x130
WARNING: linker: /system/vendor/lib/libsrv_um.so: unused DT entry: type 0xf arg 0xbe3
WARNING: linker: /system/vendor/lib/hw/memtrack.clovertrail.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /system/vendor/lib/libsrv_um.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /system/vendor/lib/hw/gralloc.clovertrail.so: unused DT entry: type 0xf arg 0x62a
WARNING: linker: /system/vendor/lib/libpvr2d.so: unused DT entry: type 0xf arg 0x79b
WARNING: linker: /system/vendor/lib/hw/gralloc.clovertrail.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /system/vendor/lib/libpvr2d.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
{
  "health": "GOOD",
  "percentage": 99,
  "plugged": "UNPLUGGED",
  "status": "DISCHARGING",
  "temperature": 25.0,
  "current": -69
}
~ $ proot-distro login alpine
localhost:~# termux-battery-status
Segmentation fault
localhost:~# 

Steps to reproduce

Expected behavior Expected to run normally (in this case, termux-battery-status should return a JSON containing info of the device's battery) as shown in the section "Problem Description"

Additional information

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=4408
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.1
TERMUX__USER_ID=0
Packages CPU architecture:
i686
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.dev/apt/termux-main stable main
Updatable packages:
esbuild/stable 0.23.0 i686 [upgradable from: 0.21.1]
libtalloc/stable 2.4.2 i686 [upgradable from: 2.4.1]
libunbound/stable 1.21.0 i686 [upgradable from: 1.20.0-1]
proot/stable 5.1.107-65 i686 [upgradable from: 5.1.107-64]
termux-tools version:
1.43.3
Android version:
7.1.2
Kernel build information:
Linux localhost 3.4.34-lineage-01570-g463c91c87b07 termux/termux-api-package#2 SMP PREEMPT Mon Apr 26 11:00:56 CEST 2021 i686 Android
Device manufacturer:
samsung
Device model:
GT-P5210
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api
sylirre commented 3 weeks ago

Please provide a full output of env. Later may ask for other stuff, but environment variables is the first thing that may affect how Termux API commands work inside proot-distro.

ushu3323 commented 3 weeks ago

Sure! here's the output inside a proot-distro session

localhost:~# env
USER=root
EXTERNAL_STORAGE=/sdcard
SHLVL=1
HOME=/root
OLDPWD=/etc
PAGER=less
BOOTCLASSPATH=/system/framework/telephony-ext.jar:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar
COLORTERM=
TMPDIR=/tmp
PULSE_SERVER=127.0.0.1
TERM=xterm-256color
ANDROID_DATA=/data
LC_COLLATE=C
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/data/data/com.termux/files/usr/bin:/system/bin:/system/xbin
ANDROID_ROOT=/system
LANG=en_US.UTF-8
PWD=/root
CHARSET=UTF-8
MOZ_FAKE_NO_SANDBOX=1

and here is outside a proot-distro session (termux enviroment) just in case

~ $ env
SHELL=/data/data/com.termux/files/usr/bin/bash
HISTCONTROL=ignoreboth
PREFIX=/data/data/com.termux/files/usr
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
PWD=/data/data/com.termux/files/home
LOGNAME=u0_a60
TERMUX_VERSION=0.118.1
EXTERNAL_STORAGE=/sdcard
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
HOME=/data/data/com.termux/files/home
TERMUX_API_VERSION=0.50.1
LANG=en_US.UTF-8
TERMUX_APK_RELEASE=F_DROID
TMPDIR=/data/data/com.termux/files/usr/tmp
SSH_CONNECTION=192.168.1.103 51680 192.168.1.101 8022
ANDROID_DATA=/data
TERM=xterm-256color
USER=u0_a60
SHLVL=1
ANDROID_ROOT=/system
BOOTCLASSPATH=/system/framework/telephony-ext.jar:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar
SSH_CLIENT=192.168.1.103 51680 8022
TERMUX_APP_PID=3604
PATH=/data/data/com.termux/files/usr/bin
SSH_TTY=/dev/pts/2
OLDPWD=/data/data/com.termux/files/home
_=/data/data/com.termux/files/usr/bin/env
ushu3323 commented 3 weeks ago

Sorry to bother, but I've just discovered that the issue is not limited to termux-api; it affects every executable/command that is previously installed in the Termux environment, unless it’s in proot-distro.

sylirre commented 3 weeks ago

Variables look good for Android 7.x.

If you are saying that all Termux commands do not work in proot-distro, try to run this:

Instead of pwd you can put any other command, whatever known to fail under proot-distro. Report whether commands work or not.

Also you can try to start just termux-chroot and try to run Termux api under its interactive shell.

ushu3323 commented 3 weeks ago

Hi, I just tried what you suggested, and it seems to work fine. I think it might be related to Alpine Linux running the commands differently (just a guess). I’ll keep you updated if I find anything that doesn’t work. Here’s the output from the tests based on your suggestion:

~ $ proot pwd
/data/data/com.termux/files/home
~ $ termux-chroot pwd
/data/data/com.termux/files/home
~ $ echo "trying one of the termux-api commands using proot and termux-chroot"
trying one of the termux-api commands using proot and termux-chroot
~ $ proot termux-battery-status
WARNING: linker: /system/vendor/lib/hw/memtrack.clovertrail.so: unused DT entry: type 0xf arg 0x130
WARNING: linker: /system/vendor/lib/libsrv_um.so: unused DT entry: type 0xf arg 0xbe3
WARNING: linker: /system/vendor/lib/hw/memtrack.clovertrail.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /system/vendor/lib/libsrv_um.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /system/vendor/lib/hw/gralloc.clovertrail.so: unused DT entry: type 0xf arg 0x62a
WARNING: linker: /system/vendor/lib/libpvr2d.so: unused DT entry: type 0xf arg 0x79b
WARNING: linker: /system/vendor/lib/hw/gralloc.clovertrail.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /system/vendor/lib/libpvr2d.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
{
  "health": "GOOD",
  "percentage": 40,
  "plugged": "UNPLUGGED",
  "status": "DISCHARGING",
  "temperature": 25.899999618530273,
  "current": -6
}
~ $ termux-chroot termux-battery-status
WARNING: linker: /vendor/lib/hw/memtrack.clovertrail.so: unused DT entry: type 0xf arg 0x130
WARNING: linker: /vendor/lib/libsrv_um.so: unused DT entry: type 0xf arg 0xbe3
WARNING: linker: /vendor/lib/hw/memtrack.clovertrail.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /vendor/lib/libsrv_um.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /vendor/lib/hw/gralloc.clovertrail.so: unused DT entry: type 0xf arg 0x62a
WARNING: linker: /vendor/lib/libpvr2d.so: unused DT entry: type 0xf arg 0x79b
WARNING: linker: /vendor/lib/hw/gralloc.clovertrail.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /vendor/lib/libpvr2d.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
{
  "health": "GOOD",
  "percentage": 40,
  "plugged": "UNPLUGGED",
  "status": "DISCHARGING",
  "temperature": 25.899999618530273,
  "current": -14
}
~ $ echo "Starting termux-chroot and running termux-api commands"
Starting termux-chroot and running termux-api commands
~ $ termux-chroot
~ $ termux-battery-status
WARNING: linker: /vendor/lib/hw/memtrack.clovertrail.so: unused DT entry: type 0xf arg 0x130
WARNING: linker: /vendor/lib/libsrv_um.so: unused DT entry: type 0xf arg 0xbe3
WARNING: linker: /vendor/lib/hw/memtrack.clovertrail.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /vendor/lib/libsrv_um.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /vendor/lib/hw/gralloc.clovertrail.so: unused DT entry: type 0xf arg 0x62a
WARNING: linker: /vendor/lib/libpvr2d.so: unused DT entry: type 0xf arg 0x79b
WARNING: linker: /vendor/lib/hw/gralloc.clovertrail.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
WARNING: linker: /vendor/lib/libpvr2d.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
{
  "health": "GOOD",
  "percentage": 40,
  "plugged": "UNPLUGGED",
  "status": "DISCHARGING",
  "temperature": 25.799999237060547,
  "current": -3
}
~ $