termux / termux-packages

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

coreutils segfaults after upgrade (i686) #2603

Closed sehugg closed 6 years ago

sehugg commented 6 years ago

After upgrading the Termux app and doing a pkg update, mv now returns the following:

rm: missing operand
Try 'rm --help' for more information.
Segmentation fault (core dumped)

This happened sometime during the upgrade and it borked many install scripts.

pkg reinstall coreutils did not seem to remedy the situation.

I'm not the best interpreter of strace logs but here are some lines:

write(2, "Try 'rm --help' for more informa"..., 38Try 'rm --help' for more information.
) = 38
mprotect(0xe84c0000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0xe84c0000, 4096, PROT_READ)   = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=NULL} ---

termux-info:

Updatable packages:
All packages up to date
System information:
Linux localhost 3.18.0-17554-g9194949d4df2 #1 SMP PREEMPT Sun Jun 24 19:24:20 PDT 2018 i686 Android
Termux-packages arch:
i686
Android version:
7.1.1
Device manufacturer:
google
Device model:
Samsung Chromebook 3
Grimler91 commented 6 years ago

Are all packages up to date?

Could you share the full strace log?

casept commented 6 years ago

As of the latest coreutils update I'm experiencing the same issue on an arm device:

$ termux-info
Updatable packages:
All packages up to date
System information:
Linux localhost 3.4.113-lineageos-g31d25d7 #1 SMP PREEMPT Sat Jun 23 16:51:30 CEST 2018 armv7l Android
Termux-packages arch:
arm
Android version:
7.1.2
Device manufacturer:
samsung
Device model:
SM-G900F

The output of strace when running apt install coreutils (yes, the error occurs even when installing the package itself) is here.

All packages are up-to-date.

darkgeek commented 6 years ago

I can confirm I have the same problem on my armv7 device.

u0_a91@localhost:~$ termux-info
Updatable packages:
All packages up to date
System information:
Linux localhost 3.4.113-lineageos-g8a3199a9a3f #1 SMP PREEMPT Mon Jun 18 15:15:27 CEST 2018 armv7l Android
Termux-packages arch:
arm
Android version:
8.1.0
Device manufacturer:
OnePlus
Device model:
A0001
arswb commented 6 years ago

after latest update there also get an apt-key error:

Err:1 https://termux.net stable InRelease
  Unknown error executing apt-key
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://termux.net stable InRelease: Unknown error executing apt-key
Grimler91 commented 6 years ago

@arswb I don't see anything that indicate that the error is related. Try running apt update again.

arswb commented 6 years ago

just the same, I tried it a few times. and in the download process, my phone always vibrates. the download process also takes a long time. this is not about my network.

screenshot_20180703-014445

Grimler91 commented 6 years ago

I can't reproduce the error on my arm android 7.1.2 device, so that's interesting. termux-info output:

Updatable packages:
texlive-bin/stable 20180414-2 arm [upgradable from: 20180414]
System information:
Linux localhost 3.4.113-Deathly-1.0 #2 SMP PREEMPT Fri Feb 23 21:24:29 CET 2018 armv7l Android
Termux-packages arch:
arm
Android version:
7.1.2
Device manufacturer:
samsung
Device model:
SM-T800
Grimler91 commented 6 years ago

@arswb what happens if you run apt-key or apt-key adv --keyserver pgp.mit.edu --recv A46BE53C? (A46BE53C is my key).

arswb commented 6 years ago

when I do the termux-info command, it takes a long time, about half a minute, and my phone vibrates several times.

the output


$ termux-info
Updatable packages:
All packages up to date
System information:
Linux localhost 3.18.19-12327063 #1 SMP PREEMPT Thu Jun 7 09:58:59 KST 2018 armv7l Android
Termux-packages arch:
arm
Android version:
6.0.1
Device manufacturer:
samsung
Device model:
SM-G532G
``
Grimler91 commented 6 years ago

@arswb Please open another issue as this might be unrelated to this issue.

arswb commented 6 years ago

i tried it

$ apt-key adv --keyserver pgp.mit.edu --recv A46BE53C
Segmentation fault
Segmentation fault
$
Grimler91 commented 6 years ago

Alright, seems suspicious

Could someone run a segfault command in gdb and see if it gives any more information? (gdb --args faulty-command followed by run and backtrace).

If rm is the only/one of few binaries that don't work then it should be possible to mv it temporarily using busybox: busybox mv $PREFIX/bin/rm $PREFIX/bin/rm_old. After you start a new shell apt and all other programs will then use the busybox version of rm instead of the broken one.

arswb commented 6 years ago

finally i downgrade coreutils package, i download it from xeffyr repo and yes, everything is back to normal.

arswb commented 6 years ago

this is a problem? @Grimler91

(gdb) file /data/data/com.termux/files/usr/bin/apt-key
"/data/data/com.termux/files/usr/bin/apt-key": not in executable format: File format not recognized
Grimler91 commented 6 years ago

@arswb no, that means that the file apt-key isn't a binary file and gdb therefore can't attach to it. It is apparently a bash script, so this is the expected behaviour.

arswb commented 6 years ago

@Grimler91 sorry, i'm not understand about that. :rofl:

peterNordin commented 6 years ago

I am also having the same problems.

$ termux-info Updatable packages: All packages up to date System information: Linux localhost 3.10.108-lineageOS #1 SMP PREEMPT Wed Jun 27 10:16:07 UTC 2018 armv7l Android Termux-packages arch: arm Android version: 7.1.2 Device manufacturer: Motorola Device model: Moto G4 Plus

gdb --args rm: (gdb) run Starting program: /data/data/com.termux/files/usr/bin/rm /data/data/com.termux/files/usr/bin/rm: missing operand Try '/data/data/com.termux/files/usr/bin/rm --help' for more information.

Program received signal SIGSEGV, Segmentation fault. 0x7f5df1d0 in ?? () (gdb) bt

0 0x7f5df1d0 in ?? ()

1 0x7f5c1338 in ?? ()

Backtrace stopped: previous frame identical to this frame (corrupt stack?)

josephbreihan commented 6 years ago

I just updated to the latest Termux beta 0.64. Coreutils packages are crashing, Erlang crashes, and I get the same key errors detailed above.

System information: Linux localhost 3.18.0-18034-g6bbde26a08bb #1 SMP PREEMPT Tue Jun 26 12:28:26 PDT 2018 i686 Android Termux-packages arch: i686 Android version: 7.1.1 Device manufacturer: google Device model: ASUS Chromebook Flip C302 Package: coreutils Version: 8.30 Maintainer: Fredrik Fornwall @fornwall Installed-Size: 1528 kB Homepage: https://www.gnu.org/software/coreutils/ Download-Size: 426 kB APT-Manual-Installed: yes APT-Sources: https://termux.net stable/main i686 Packages Description: Basic file, shell and text manipulation utilities from the GNU project

Package: erlang Version: 21.0.1 Maintainer: Fredrik Fornwall @fornwall Installed-Size: 99.6 MB Depends: openssl, ncurses, libutil Homepage: https://www.erlang.org/ Download-Size: 33.2 MB APT-Manual-Installed: yes APT-Sources: https://termux.net stable/main i686 Packages Description: General-purpose concurrent functional programming language developed by Ericsson

% rm rm: missing operand Try 'rm --help' for more information. [1] 26754 segmentation fault (core dumped) rm

% erl erl_child_setup closed
Crash dump is being written to: erl_crash.dump...done

% pkg update Hit:1 https://termux.net stable InRelease Err:1 https://termux.net stable InRelease Unknown error executing apt-key Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date. W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://termux.net stable InRelease: Unknown error executing apt-key W: Failed to fetch https://termux.net/dists/stable/InRelease Unknown error executing apt-key W: Some index files failed to download. They have been ignored, or old ones used instead. Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

stuart-little commented 6 years ago

I have very similar issues on Android 5.1:

When this started happening I did a clean install. All was fine until I installed coreutils; that's when I first got the killed-by-signal error during the dpkg cleanup.

Before installing coreutils I installed other packages successfully and without issue, like emacs and git, and upgraded dpkg, also without problems (that was the first reported update after the fresh termux install).

its-pointless commented 6 years ago

Program received signal SIGSEGV, Segmentation fault. 0x7f5e46be in freadahead (fp=0xb6f48788 <__sF>) at /home/builder/.termux-build/coreutils/src/lib/freadahead.c:51 51 /home/builder/.termux-build/coreutils/src/lib/freadahead.c: No such file or directory. (gdb) bt

0 0x7f5e46be in freadahead (fp=0xb6f48788 <__sF>) at /home/builder/.termux-build/coreutils/src/lib/freadahead.c:51

1 0x7f5c6454 in close_stdin () at /home/builder/.termux-build/coreutils/src/lib/closein.c:87

2 0xb6f10a3c in __cxa_finalize () from /system/lib/libc.so

3 0xb6ed530e in exit () from /system/lib/libc.so

4 0x7f5a349c in _usage_rm (status=1) at /home/builder/.termux-build/coreutils/src/src/rm.c:187

5 0x7f5a38e6 in single_binary_main_rm (argc=1, argv=0xbefff4f4) at /home/builder/.termux-build/coreutils/src/src/rm.c:339

6 0x7f55f2a4 in launch_program (prog_name=, prog_argc=1, prog_argv=0xbefff4f4) at /home/builder/.termux-build/coreutils/src/src/coreutils.c:127

7 0x7f55e802 in main (argc=1, argv=0xbefff4f4) at /home/builder/.termux-build/coreutils/src/src/coreutils.c:144

(gdb)

stuart-little commented 6 years ago

I'd also like to confirm that the (temporary) solution proposed by @arswb works in a pinch, until the dust settles on this:

There is a copy of v. 8.29 of the coreutils package in the arm branch of the xeffyr repo.

its-pointless commented 6 years ago

okay iv got it working ... lib/closein.c if (freadahead (stdin) > 0) { / Only attempt flush if stdin is seekable, as fflush is entitled to fail on non-seekable streams. / if (fseeko (stdin, 0, SEEK_CUR) == 0 && fflush (stdin) != 0) fail = true; } this doesn't work on 32bit.

its-pointless commented 6 years ago

what i think the issue is the difference between versions 2.29 and 2.30 is this addition to stdio-impl.h / Up to this commit from 2015-10-12 https://android.googlesource.com/platform/bionic.git/+/f0141dfab10a4b332769d52fa76631a64741297a the innards of FILE were public, and fp_ub could be defined like for OpenBSD, see https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/fileext.h and https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/local.h. After this commit, the innards of FILE are hidden. /

define fp_ ((struct { unsigned char *_p; \

                     int _r; \
                     int _w; \
                     int _flags; \
                     int _file; \
                     struct { unsigned char *_base; size_t _size; } _bf; \
                     int _lbfsize; \
                     void *_cookie; \
                     void *_close; \
                     void *_read; \
                     void *_seek; \
                     void *_write; \
                     struct { unsigned char *_base; size_t _size; } _ext; \
                     unsigned char *_up; \
                     int _ur; \
                     unsigned char _ubuf[3]; \
                     unsigned char _nbuf[1]; \
                     struct { unsigned char *_base; size_t _size; } _lb; \
                     int _blksize; \
                     fpos_t _offset; \
                     /* More fields, not relevant here.  */ \
                   } *) fp)

else

define fp_ fp

endif

tomty89 commented 6 years ago

That code was introduced to gnulib in 2007 and used in coreutils 8.29 anyway. http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commit;h=7042775894700f8be0e6bc2a5ff3c49fc77296bc

Something to do with the recent NDK upgrade / clang switch?

its-pointless commented 6 years ago

no 2.29 still compiles and works fine

` return fp_->_r

Is the line it crashes on. Its the changes in stdio-impl.h with android. HASUB is defined there. It used to be android got the same treatment as BSD but its changed here. the innards of FILE were public, and fp_ub could be defined like for OpenBSD, this change is the cause as far I can work out.

its-pointless commented 6 years ago

So yeah https://android.googlesource.com/platform/bionic.git/+/f0141dfab10a4b332769d52fa76631a64741297a/libc/stdio/local.h Bionic libc hides symbols in 64bit so its appropriate to use the new stdio-impl.h but it doesn't hide them for 32bit.

tomty89 commented 6 years ago

Is any of the headers you mentioned so far part of the API/NDK?

Suppose NDK 17 ships a broken version bionic build, could it possibly break a program build when it was just being linked against during the build process? I don't suppose the reporters all happened to have upgraded to the broken bionic (i.e. Android upgrade) recently?

no 2.29 still compiles and works fine

What do you mean by this? Were you actually referring to coreutils 8.29? You mean its build with NDK 17 and clang works? Then it should be some changes in 8.30 causing/triggering it?

Has anyone tested a build of coreutils 8.30 with NDK 16 and/or gcc?

Grimler91 commented 6 years ago

I've built 8.30 with r17 and gcc, please try it: arm i686.

I still can't reproduce it on arm so it doesn't happen on all 32bit devices.

its-pointless commented 6 years ago

I tried with gcc and gcc 8 and all segfault

2608 Fixes it

its-pointless commented 6 years ago

2.29 works everytime on all compilers i have.

its-pointless commented 6 years ago

https://github.com/its-pointless/gcc_termux/ Debug versions with fix just uploaded....

tomty89 commented 6 years ago

Maybe it's because the struct in the new stdio-impl.h in coreutils doesn't have special handle for __LP64__ like the one in local.h in bionic? (Hence if the bionic in a certain Android build is built with __LP64__ defined there wouldn't be a problem?)

...
struct __sbuf {
  unsigned char* _base;
#if defined(__LP64__)
  size_t _size;
#else
  int _size;
#endif
};
struct __sFILE {
  unsigned char* _p; /* current position in (some) buffer */
  int _r;            /* read space left for getc() */
  int _w;            /* write space left for putc() */
#if defined(__LP64__)
  int _flags; /* flags, below; this FILE is free if 0 */
  int _file;  /* fileno, if Unix descriptor, else -1 */
#else
  short _flags; /* flags, below; this FILE is free if 0 */
  short _file;  /* fileno, if Unix descriptor, else -1 */
#endif
...

Btw better file a bug report upstream...

fosslinux commented 6 years ago

I can repro, arm 32 bit Moto E4. Does anyone know how to downgrade?

Maybe downgrade in the repository?

fornwall commented 6 years ago

This has now been fixed in version 8.30-1 of the coreutils package, which is available for installation.

@tomty89 or @its-pointless Can you submit a bug report/patch upstream? For the moment I just disabled their definition in 86af1159d0d487368aab2494904e89b86f042fe2, as Termux already has patched that in.

stuart-little commented 6 years ago

@sstt011:

I seem to be 32 bit too (uname -m returns armv7l). I managed to downgrade to 8.29 as indicated briefly in my previous message in this thread and the post by @arswb (the one that mentions downgrading). In more detail:

ThoJer commented 6 years ago

How can I update to 8.30-1

its-pointless commented 6 years ago

if apt update isn't working just apt remove coreutils apt update apt install coreutils

stuart-little commented 6 years ago

This is just to confirm that the upgrade to 8.30-1 went through all right here (Android 5.1 on armv7l). No trace of the issues from before.