termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.19k stars 3.02k forks source link

[Bug]: valgrind bad system call #17359

Closed babaric-dev closed 6 months ago

babaric-dev commented 1 year ago

Problem description

Self explanatory.

What steps will reproduce the bug?

Install valgrind and run any program:

valgrind --tool=massif ls

Even valgrind itself breaks:

valgrind --tool=massif valgrind

Bad system call

Note this does not happen when running valgrind --help

What is the expected behavior?

Programs run as expected without valgrind (no bad syscall). But this should also be the case when invoking via valgrind

System information

termux-info:

Termux Variables:
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=1167
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
Packages CPU architecture:
x86_64
Subscribed repositories:
# sources.list
deb https://mirrors.zju.edu.cn/termux/apt/termux-main stable main
Updatable packages:
command-not-found/stable 2.2.0-6 x86_64 [upgradable from: 2.2.0-5]
libunbound/stable 1.17.1-2 x86_64 [upgradable from: 1.17.1-1]
unbound/stable 1.17.1-2 x86_64 [upgradable from: 1.17.1-1]
zstd/stable 1.5.5-1 x86_64 [upgradable from: 1.5.5]
termux-tools version:
1.38.3
Android version:
13
Kernel build information:
Linux localhost 5.15.94-windows-subsystem-for-android-20230508+ #1 SMP PREEMPT Thu May 11 14:27:58 UTC 2023 x86_64 Android
Device manufacturer:
Microsoft Corporation
Device model:
Subsystem for Android(TM)
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
xtkoba commented 1 year ago

I cannot confirm this because I do not have access to any x86_64 Android environment.

Sharing strace output of the command may help.

babaric-dev commented 1 year ago

Sorry, but I'm not sure if I want to share the output of strace here.

2096779623 commented 1 year ago

I cannot reproduce it on my aarch64 device.

truboxl commented 1 year ago

Is this on Windows 11?

babaric-dev commented 1 year ago

Yes. Windows 11, unsupported region, vanilla MSIXBundle without any patches, downloaded from Adguard Store, Amazon Appstore removed with adb command.

xtkoba commented 1 year ago

Not sure if this is specific to WSA or reproducible with other environments such as AVD.

babaric-dev commented 1 year ago

Does anyone have an AVD or a Windows Arm machine to test WSA Termux Valgrind on Arm? Please test and report the results thanks.

zavocc commented 1 year ago

WSA can transparently run arm/arm64 binaries /libraries/apps on x86_64 using libhoudini, so installing https://github.com/termux/termux-app/releases/download/v0.118.0/termux-app_v0.118.0+github-debug_arm64-v8a.apk would simply let you use arm64 Termux on Windows Subsystem for Android, this requires however uninstallation of existing Termux app.

truboxl commented 1 year ago

AVD API 30 x86_64 Google APIs

Termux Variables:
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=11878
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_VERSION=0.118.0
Packages CPU architecture:
x86_64
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.dev/apt/termux-main/ stable main
Updatable packages:
All packages up to date
termux-tools version:
1.38.5
Android version:
11
Kernel build information:
Linux localhost 5.4.86-android11-2-00006-gae78026f427c-ab7595864 #1 SMP PREEMPT Thu Jul 29 20:54:47 UTC 2021 x86_64 Android
Device manufacturer:
Google
Device model:
sdk_gphone_x86_64
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so

strace -fv -o valgrind-strace-log.txt valgrind --tool=massif ls

18192 execve("/data/data/com.termux/files/usr/bin/valgrind", ["valgrind", "--tool=massif", "ls"], ["SHELL=/data/data/com.termux/file"..., "COLORTERM=truecolor", "HISTCONTROL=ignoreboth", "PREFIX=/data/data/com.termux/fil"..., "TERMUX_IS_DEBUGGABLE_BUILD=0", "PWD=/data/data/com.termux/files/"..., "TERMUX_VERSION=0.118.0", "EXTERNAL_STORAGE=/sdcard", "LD_PRELOAD=/data/data/com.termux"..., "HOME=/data/data/com.termux/files"..., "LANG=en_US.UTF-8", "TERMUX_APK_RELEASE=F_DROID", "DEX2OATBOOTCLASSPATH=/apex/com.a"..., "TMPDIR=/data/data/com.termux/fil"..., "ANDROID_DATA=/data", "TERM=xterm-256color", "ANDROID_I18N_ROOT=/apex/com.andr"..., "SHLVL=1", "ANDROID_ROOT=/system", "BOOTCLASSPATH=/apex/com.android."..., "ANDROID_TZDATA_ROOT=/apex/com.an"..., "TERMUX_APP_PID=11878", "PATH=/data/data/com.termux/files"..., "ANDROID_ART_ROOT=/apex/com.andro"..., "_=/data/data/com.termux/files/us"...]) = 0
18192 arch_prctl(ARCH_SET_FS, 0x7ffffa9fab50) = 0
18192 getpid()                          = 18192
18192 mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x70a69455b000
18192 set_tid_address(0x3074c8)         = 18192
18192 faccessat(AT_FDCWD, "/dev/urandom", R_OK) = 0
18192 getrandom("\x2b\x59\xb3\x97\x99\x40\xc0\xee\xea\xbe\x17\x79\xed\x36\x7e\xab\x93\x99\xcd\x9b\x95\x1f\xd8\x1f\xd5\x18\xec\x9a\x44\x52\x6d\xee"..., 40, GRND_NONBLOCK) = 40
18192 mmap(NULL, 1104, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x70a69455a000
18192 prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, 0x70a69455a000, 1104, "arc4random data") = 0
18192 sched_getscheduler(0)             = 0 (SCHED_OTHER)
18192 mmap(NULL, 36864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x70a694551000
18192 mprotect(0x70a694551000, 4096, PROT_NONE) = 0
18192 sigaltstack({ss_sp=0x70a694552000, ss_flags=0, ss_size=32768}, NULL) = 0
18192 prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, 0x70a694552000, 32768, "thread signal stack") = 0
18192 mprotect(0x306000, 4096, PROT_READ) = 0
18192 mprotect(0x306000, 4096, PROT_READ|PROT_WRITE) = 0
18192 mprotect(0x306000, 4096, PROT_READ) = 0
18192 fcntl(0, F_GETFL)                 = 0x8002 (flags O_RDWR|O_LARGEFILE)
18192 fcntl(1, F_GETFL)                 = 0x8002 (flags O_RDWR|O_LARGEFILE)
18192 fcntl(2, F_GETFL)                 = 0x8002 (flags O_RDWR|O_LARGEFILE)
18192 mmap(NULL, 24576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x70a69454b000
18192 mprotect(0x70a69454c000, 16384, PROT_READ|PROT_WRITE) = 0
18192 rt_sigprocmask(SIG_BLOCK, ~[], [RTMIN], 8) = 0
18192 rt_sigprocmask(SIG_SETMASK, [RTMIN], NULL, 8) = 0
18192 arch_prctl(ARCH_SET_FS, 0x70a69454ff80) = 0
18192 prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, 0x70a69454c000, 16384, "stack_and_tls:main") = 0
18192 munmap(0x70a69455b000, 12288)     = 0
18192 newfstatat(AT_FDCWD, "/dev/__properties__", {st_dev=makedev(0, 0x11), st_ino=7342, st_mode=S_IFDIR|0711, st_nlink=2, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=3460, st_atime=1693669049 /* 2023-09-02T15:37:29.532000000+0000 */, st_atime_nsec=532000000, st_mtime=1693669049 /* 2023-09-02T15:37:29.556000000+0000 */, st_mtime_nsec=556000000, st_ctime=1693669049 /* 2023-09-02T15:37:29.556000000+0000 */, st_ctime_nsec=556000000}, 0) = 0
18192 faccessat(AT_FDCWD, "/dev/__properties__/property_info", R_OK) = 0
18192 openat(AT_FDCWD, "/dev/__properties__/property_info", O_RDONLY|O_NOFOLLOW|O_CLOEXEC) = 3
18192 fstat(3, {st_dev=makedev(0, 0x11), st_ino=7343, st_mode=S_IFREG|0444, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=88, st_size=44704, st_atime=1693669049 /* 2023-09-02T15:37:29.548000000+0000 */, st_atime_nsec=548000000, st_mtime=1693669049 /* 2023-09-02T15:37:29.544000000+0000 */, st_mtime_nsec=544000000, st_ctime=1693669049 /* 2023-09-02T15:37:29.544000000+0000 */, st_ctime_nsec=544000000}) = 0
18192 mmap(NULL, 44704, PROT_READ, MAP_SHARED, 3, 0) = 0x70a694540000
18192 close(3)                          = 0
18192 mmap(NULL, 6760, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x70a69455c000
18192 prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, 0x70a69455c000, 6760, "System property context nodes") = 0
18192 openat(AT_FDCWD, "/dev/__properties__/properties_serial", O_RDONLY|O_NOFOLLOW|O_CLOEXEC) = 3
18192 fstat(3, {st_dev=makedev(0, 0x11), st_ino=7513, st_mode=S_IFREG|0444, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=131072, st_atime=1693669049 /* 2023-09-02T15:37:29.624000000+0000 */, st_atime_nsec=624000000, st_mtime=1693669049 /* 2023-09-02T15:37:29.556000000+0000 */, st_mtime_nsec=556000000, st_ctime=1693669049 /* 2023-09-02T15:37:29.556000000+0000 */, st_ctime_nsec=556000000}) = 0
18192 mmap(NULL, 131072, PROT_READ, MAP_SHARED, 3, 0) = 0x70a694520000
18192 close(3)                          = 0
18192 openat(AT_FDCWD, "/dev/__properties__/u:object_r:debug_prop:s0", O_RDONLY|O_NOFOLLOW|O_CLOEXEC) = 3
18192 fstat(3, {st_dev=makedev(0, 0x11), st_ino=7383, st_mode=S_IFREG|0444, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=131072, st_atime=1693669049 /* 2023-09-02T15:37:29.624000000+0000 */, st_atime_nsec=624000000, st_mtime=1693669049 /* 2023-09-02T15:37:29.548000000+0000 */, st_mtime_nsec=548000000, st_ctime=1693669049 /* 2023-09-02T15:37:29.548000000+0000 */, st_ctime_nsec=548000000}) = 0
18192 mmap(NULL, 131072, PROT_READ, MAP_SHARED, 3, 0) = 0x70a694500000
18192 close(3)                          = 0
18192 rt_sigaction(SIGRT_7, {sa_handler=0x22fad0, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x230c10}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
18192 rt_sigaction(SIGRT_4, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x230c10}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
18192 rt_sigaction(SIGRT_6, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x230c10}, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=0}, 8) = 0
18192 open("/sys/kernel/mm/transparent_hugepage/enabled", O_RDONLY) = -1 ENOENT (No such file or directory)
18192 mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x70a694300000
18192 prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, 0x70a694300000, 2097152, "libc_malloc") = 0
18192 munmap(0x70a694300000, 2097152)   = 0
18192 mmap(NULL, 4190208, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x70a694101000
18192 prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, 0x70a694101000, 4190208, "libc_malloc") = 0
18192 munmap(0x70a694101000, 1044480)   = 0
18192 munmap(0x70a694400000, 1048576)   = 0
18192 mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x70a694000000
18192 prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, 0x70a694000000, 2097152, "libc_malloc") = 0
18192 mprotect(0x2b0000, 20480, PROT_READ) = 0
18192 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x70a69455b000
18192 prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, 0x70a69455b000, 4096, "atexit handlers") = 0
18192 mprotect(0x70a69455b000, 4096, PROT_READ) = 0
18192 mprotect(0x70a69455b000, 4096, PROT_READ|PROT_WRITE) = 0
18192 mprotect(0x70a69455b000, 4096, PROT_READ) = 0
18192 faccessat(AT_FDCWD, "/data/data/com.termux/files/usr/bin/ls", R_OK|X_OK) = 0
18192 openat(AT_FDCWD, "/data/data/com.termux/files/usr/bin/ls", O_RDONLY) = 3
18192 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\21\7\0\0\0\0\0"..., 4096) = 4096
18192 close(3)                          = 0
18192 readlinkat(AT_FDCWD, "/proc/self/exe", "/data/data/com.termux/files/usr/"..., 500) = 44
18192 execve("/data/data/com.termux/files/usr/libexec/valgrind/massif-amd64-linux", ["valgrind", "--tool=massif", "ls"], ["SHELL=/data/data/com.termux/file"..., "COLORTERM=truecolor", "HISTCONTROL=ignoreboth", "PREFIX=/data/data/com.termux/fil"..., "TERMUX_IS_DEBUGGABLE_BUILD=0", "PWD=/data/data/com.termux/files/"..., "TERMUX_VERSION=0.118.0", "EXTERNAL_STORAGE=/sdcard", "LD_PRELOAD=/data/data/com.termux"..., "HOME=/data/data/com.termux/files"..., "LANG=en_US.UTF-8", "TERMUX_APK_RELEASE=F_DROID", "DEX2OATBOOTCLASSPATH=/apex/com.a"..., "TMPDIR=/data/data/com.termux/fil"..., "ANDROID_DATA=/data", "TERM=xterm-256color", "ANDROID_I18N_ROOT=/apex/com.andr"..., "SHLVL=1", "ANDROID_ROOT=/system", "BOOTCLASSPATH=/apex/com.android."..., "ANDROID_TZDATA_ROOT=/apex/com.an"..., "TERMUX_APP_PID=11878", "PATH=/data/data/com.termux/files"..., "ANDROID_ART_ROOT=/apex/com.andro"..., "_=/data/data/com.termux/files/us"..., "VALGRIND_LAUNCHER=/data/data/com"...]) = 0
18192 open("/proc/self/maps", O_RDONLY) = 3
18192 read(3, "00200000-00201000 r--p 00000000 "..., 100000) = 1071
18192 read(3, "", 98929)                = 0
18192 close(3)                          = 0
18192 mmap(0x1002001000, 4194304, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0x1002001000
18192 prlimit64(0, RLIMIT_DATA, NULL, {rlim_cur=RLIM64_INFINITY, rlim_max=RLIM64_INFINITY}) = 0
18192 prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
18192 getcwd("/data/data/com.termux/files/home", 499) = 33
18192 open("/data/data/com.termux/files/home/.valgrindrc", O_RDONLY) = -1 ENOENT (No such file or directory)
18192 stat("/data/data/com.termux/files/usr/bin/ls", {st_dev=makedev(0x256, 0x58720), st_ino=1, st_mode=013034450430, st_nlink=1483887136, st_uid=0, st_gid=4294967295, st_blksize=1483887175, st_blocks=140737396969213, st_size=4, st_atime=0, st_atime_nsec=1483887136, st_mtime=1476431857, st_mtime_nsec=206158430240, st_ctime=1483887136, st_ctime_nsec=1483886944}) = 4
18192 --- SIGSYS {si_signo=SIGSYS, si_code=SYS_SECCOMP, si_call_addr=0x58018dcd, si_syscall=__NR_stat, si_arch=AUDIT_ARCH_X86_64} ---
18192 +++ killed by SIGSYS +++
truboxl commented 6 months ago

The more I try look deeper the issue, the more I am convinced upstream never advertise valgrind support for AMD64/Android https://valgrind.org/docs/manual/dist.news.html https://bugs.kde.org/show_bug.cgi?id=379764 https://bugs.kde.org/show_bug.cgi?id=379878 https://bugs.kde.org/show_bug.cgi?id=368529

Its also questionable if valgrind on Android ever work. List of bugs at upstream