Bug 235604 - ports-mgmt/pkg: bus error / segmentation fault (core dumped)
Summary: ports-mgmt/pkg: bus error / segmentation fault (core dumped)
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-pkg mailing list
Depends on:
Reported: 2019-02-08 16:33 UTC by Oliver Fromme
Modified: 2019-02-11 23:10 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (pkg)

dmesg of the machine (5.62 KB, text/plain)
2019-02-08 16:50 UTC, Oliver Fromme
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Fromme freebsd_committer 2019-02-08 16:33:39 UTC
There is one of my machines on which ports-mgmt/pkg randomly dumps core.
Simple commands like "pkg info" or "pkg which" seem to work without problems, but when installing ports it often crashes (but not always) with either SIGBUS or SIGSEGV. This seems to happen after actual installation of the package, but before recording the dependencies in the database (if there are no dependencies, it does not appear to crash). This has led to the situation that the dependency tree of the pkg database on that machine is now broken (there doesn't seem to be an easy way to fix that, short of removing all ports and start from scratch, which I will do, once the coredump problem is fixed).

I am pretty certain that it is not a hardware problem. The pkg binary is the *only* program that exhibits the problem. I can run buildworld, buildkernel or other CPU / IO hogs for weeks without any issue. There's one special thing about the machine, however: It is a 64bit VM hosted on KVM. I'm not sure if that matters, though. I do have complete access to the VM, but not to the host system.

The problem existed when the machine had FreeBSD 10. I hoped it would be fixed when upgrading, so I first went to stable/11, then to stable/12 (also updating pkg along the way, of course), but it did not change. I'm now at stable/12 r342861 (2019-01-08) with the latest pkg-1.10.5_5.

I can reliably reproduce a SIGBUS with "pkg audit":

$ /usr/local/sbin/pkg audit
0 problem(s) in the installed packages found.
Child process pid=45723 terminated abnormally: Bus error

$ lldb -f /usr/local/sbin/pkg -c pkg.core -bobt
(lldb) target create "/usr/local/sbin/pkg" --core "pkg.core"
Core file '/home/olli/pkg.core' (x86_64) was loaded.
(lldb) bt
* thread #1, name = 'pkg', stop reason = signal SIGBUS
  * frame #0: 0x0000000800334fe0 libpkg.so.4`___lldb_unnamed_symbol608$$libpkg.so.4 + 112
    frame #1: 0x0000000800340200 libpkg.so.4`___lldb_unnamed_symbol660$$libpkg.so.4 + 320
    frame #2: 0x00000008002f06b4 libpkg.so.4`pkg_shutdown + 36
    frame #3: 0x0000000800b524e5 libc.so.7`__cxa_finalize(dso=0x0000000000000000) at atexit.c:239
    frame #4: 0x0000000800ae20e1 libc.so.7`exit(status=0) at exit.c:74
    frame #5: 0x0000000000214122 pkg`___lldb_unnamed_symbol1$$pkg + 290

So it appears that this bus error occurs in the exit code, after the actual work of pkg was done.  I am currently not in a position to debug it any further myself.  I have uploaded the core file, binary and libraries here:

Let me know if you need more information. I could probably also give login access to that machine to a FreeBSD developer if needed.
Comment 1 Oliver Fromme freebsd_committer 2019-02-08 16:50:27 UTC
Created attachment 201846 [details]
dmesg of the machine