Bug 200613 - qemu-bsd-user fails to handle semctl() calls in databases/firebird25-client
Summary: qemu-bsd-user fails to handle semctl() calls in databases/firebird25-client
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: arm Any
: --- Affects Some People
Assignee: Sean Bruno
URL:
Keywords:
Depends on:
Blocks: 200147
  Show dependency treegraph
 
Reported: 2015-06-03 15:18 UTC by Sean Bruno
Modified: 2016-01-04 18:28 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Bruno freebsd_committer freebsd_triage 2015-06-03 15:18:27 UTC
This is a bug against the qemu-bsd-user code that manifests itself in the build of firebird25-client.

A build will fail during the interpretation of many semctl() calls, specifically here in this strace output:

37453 stat("/etc/nsswitch.conf",0x9fffd048) = 0
37453 open("/etc/group",0x100000,0666) = 6
37453 fstat(6,0x9fffcdd0) = 0
37453 lseek(6,1140466088,0,0,1,1) = 0
37453 lseek(6,1140466088,0,0,0,1140711936) = 0
37453 read(6,0x45462000,4096) = 442
37453 read(6,0x45462000,4096) = 0
37453 close(6) = 0
37453 fchown(5,-1,-1) = 0
37453 fchmod(5,0660) = 0
37453 mmap(0,1056,3,1,5,0) = 0x45854000
37453 flock(5,6,1,101745,0,101745) = 0
37453 ftruncate(5,6,1056,0,5,0) = 0
37453 flock(3,2,0,0,0,1140261692) = 0
37453 stat("/tmp/firebird/fb_trace",0x9fffcf98) = 0
37453 flock(3,8,14,101745,1140672848,2) = 0
37453 semget(15784722,0,0,1161877824,1,-1610625940) = -1 errno=2 (No such file or directory)
37453 semget(15784722,4,1974,1,1,-1610625940) = 131075
37453 stat("/usr/local/etc/firebird/security2.fdb",0x9fffcc40) = -1 errno=2 (No such file or directory)
37453 __semctl(131075,0,8,-1610624728,1,-1610624704) = -1 errno=34 (Result too large)
37453 openat(-100, "/usr/local/share/firebird/firebird.msg",0,0) = -1 errno=2 (No such file or directory)
37453 stat("/usr/share/nls/C/libc.cat",0x9fffcab8) = -1 errno=2 (No such file or directory)
37453 stat("/usr/share/nls/libc/C",0x9fffcab8) = -1 errno=2 (No such file or directory)
37453 stat("/usr/local/share/nls/C/libc.cat",0x9fffcab8) = -1 errno=2 (No such file or directory)
37453 stat("/usr/local/share/nls/libc/C",0x9fffcab8) = -1 errno=2 (No such file or directory)
37453 gettimeofday(-1610625896,0,-1321761,0,1139220212,0) = 0
37453 open("/usr/local/etc/firebird/firebird.log",0x209,0666) = -1 errno=2 (No such file or directory)
37453 gettimeofday(-1610624768,0,0,-1610624629,-1610624744,16) = 0
37453 open("/usr/local/etc/firebird/firebird.log",0x209,0666) = -1 errno=2 (No such file or directory)
37453 clock_gettime(13,-1610628040,4256,0,1140711936,1140711968) = 0
37453 socket(1,268435458,0) = 6
37453 connect(6,0x9fffc3cc,106) = -1 errno=2 (No such file or directory)
37453 connect(6,0x9fffc3cc,106) = -1 errno=2 (No such file or directory)
37453 connect(6,0x9fffc3cc,106) = -1 errno=2 (No such file or directory)
37453 close(6) = 0
37453 socket(1,268435458,0) = 6
37453 connect(6,0x9fffc3cc,106) = -1 errno=2 (No such file or directory)
37453 connect(6,0x9fffc3cc,106) = -1 errno=2 (No such file or directory)
37453 connect(6,0x9fffc3cc,106) = -1 errno=2 (No such file or directory)
37453 close(6) = 0
37453 sendto(-1,-1610626824,74,0,0,0) = -1 errno=9 (Bad file descriptor)
37453 socket(1,268435458,0) = 6
37453 connect(6,0x9fffc3cc,106) = -1 errno=2 (No such file or directory)
37453 connect(6,0x9fffc3cc,106) = -1 errno=2 (No such file or directory)
37453 connect(6,0x9fffc3cc,106) = -1 errno=2 (No such file or directory)
37453 close(6) = 0
37453 sendto(-1,-1610626824,74,0,0,0) = -1 errno=9 (Bad file descriptor)
37453 ioctl(2, 0x402c7413 { IOR GRP:0x74('t') CMD:19 LEN:44 }, 0x9fffd10c, ...) = 0
37453 ioctl(2, 0x402c7413 { IOR GRP:0x74('t') CMD:19 LEN:44 }, 0x9fffd10c, ...) = 0
37453 write(2,0x9fffd160,43)ConfigStorage: mutex init error, status = 1 = 43
37453 write(2,0x290a48,1)
 = 1
37453 sigprocmask(3,-1610624728,0,1,-1610624680,1073746316) = 0
37453 thr_self(0x9fffd10c) = 0
37453 thr_kill(101745, 0x6)Abort (core dumped)
root@11armv6-default:/wrkdirs/usr/ports/databas
Comment 1 Stacey Son freebsd_committer freebsd_triage 2015-06-05 15:09:36 UTC
databases/firebird25-client seems to be a x86 only port...

root@crack:/usr/ports/databases/firebird25-client # uname -p
armv6
root@crack:/usr/ports/databases/firebird25-client # make
===>  firebird25-client-2.5.3_2 is only for i386 amd64, while you are running armv6.
*** Error code 1

Stop.
make: stopped

How do I reproduce this?
Comment 2 Sean Bruno freebsd_committer freebsd_triage 2015-06-05 15:11:48 UTC
(In reply to Stacey Son from comment #1)
Because the server/client seem to use the same distributions (at least the ports seem to intermingle), one needs to modify the server Makefile:

% svn diff databases/firebird25-server
Index: databases/firebird25-server/Makefile
===================================================================
--- databases/firebird25-server/Makefile	(revision 388437)
+++ databases/firebird25-server/Makefile	(working copy)
@@ -55,7 +55,7 @@
 # Don't strip binary files
 STRIP=
 
-ONLY_FOR_ARCHS=	i386 amd64
+ONLY_FOR_ARCHS=	i386 amd64 amd64
 CONFLICTS+=	firebird-client-2.0* firebird-server-2.0* \
 		firebird-client-2.1* firebird-server-2.1*
Comment 3 Stacey Son freebsd_committer freebsd_triage 2015-06-13 19:22:03 UTC
(In reply to Sean Bruno from comment #2)

-ONLY_FOR_ARCHS=	i386 amd64
+ONLY_FOR_ARCHS=	i386 amd64 amd64

Sean, I assume you meant arm.
Comment 4 Sean Bruno freebsd_committer freebsd_triage 2015-06-13 20:17:28 UTC
(In reply to Stacey Son from comment #3)
bah, I sure did.
Comment 5 Stacey Son freebsd_committer freebsd_triage 2015-06-14 02:37:42 UTC
firebird25-client has not been ported to arm and contains some machine dependent code, namely in Firebird-2.5.3.26780-0/src/common/classes/fb_atomic.h:

Here is the compiler error:

../src/include/../common/classes/fb_atomic.h:382:4: error: invalid instruction
                        "lock; xaddl %0, %1"
                        ^
<inline asm>:1:2: note: instantiated into assembly here
        lock; xaddl r1, [r0]
              ^~~~~

Here is the code:

// Assembler version for x86 and AMD64. Note it uses xaddl thus it requires i486
class AtomicCounter
{
public:
        typedef AtomicType counter_type;

        explicit AtomicCounter(AtomicType value = 0) : counter(value) {}
        ~AtomicCounter() {}

        AtomicType exchangeAdd(AtomicType value)
        {
                register counter_type result;
                __asm __volatile (
#if SIZEOF_VOID_P == 8
                        "lock; xaddq %0, %1"
#else
                        "lock; xaddl %0, %1"
#endif
                         : "=r" (result), "=m" (counter)
                         : "0" (value), "m" (counter));
                return result;
        }
Comment 6 Sean Bruno freebsd_committer freebsd_triage 2015-06-15 19:45:23 UTC
(In reply to Stacey Son from comment #5)
right, that's fixed by the patch in the dependent bug on this one.  

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=200147
Comment 7 Sean Bruno freebsd_committer freebsd_triage 2015-07-03 02:15:14 UTC
A far easier test is to run "ipcs -a" :

# /usr/local/bin/qemu-arm-static -strace /usr/bin/ipcs -a
52926 __sysctl({ 0 3 }, 2, 0x9fffe844, 0x9fffe84c, 0x4001af29, 0x0000000c) = 0
52926 __sysctl({ 6 2147482995 }, 2, 0x40025224, 0x9fffe840, 0x00000000, 0x00000000) = 0
52926 mmap(0,32768,3,4098,-1,0) = 0x42000000
52926 __sysctl({ 1 37 }, 2, 0x400251a0, 0x9fffe6b4, 0x00000000, 0x00000000) = 0
52926 issetugid() = 0
52926 lstat("/etc",0x9fffe528) = 0
52926 lstat("/etc/libmap.conf",0x9fffe528) = 0
52926 openat(-100, "/etc/libmap.conf",0x100000,0) = 3
52926 fstat(3,0x9fffe5d8) = 0
52926 mmap(0,102,1,2,3,0) = 0x42008000
52926 close(3) = 0
52926 lstat("/usr",0x9fffd8b8) = 0
52926 lstat("/usr/local",0x9fffd8b8) = 0
52926 lstat("/usr/local/etc",0x9fffd8b8) = 0
52926 lstat("/usr/local/etc/libmap.d",0x9fffd8b8) = -1 errno=2 (No such file or directory)
52926 munmap(0x42008000,102) = 0
52926 openat(-100, "/var/run/ld-elf.so.hints",0x100000,0) = 3
52926 read(3,0x9fffdf34,128) = 128
52926 lseek(3,0,128,0,0,0) = 128
52926 read(3,0x42006000,45) = 45
52926 close(3) = 0
52926 access("/lib/libkvm.so.6",0) = 0
52926 openat(-100, "/lib/libkvm.so.6",0x300000,0) = 3
52926 fstat(3,0x9fffdfe0) = 0
52926 mmap(0,4096,1,262146,3,0) = 0x42009000
52926 mmap(0,65536,0,135170,-1,0) = 0x4200a000
52926 mmap(1107337216,32768,5,393234,3,0) = 0x4200a000
52926 mmap(1107398656,4096,3,262162,3,0) = 0x42019000
52926 munmap(0x42009000,4096) = 0
52926 close(3) = 0
52926 access("/lib/libc.so.7",0) = 0
52926 openat(-100, "/lib/libc.so.7",0x300000,0) = 3
52926 fstat(3,0x9fffdfe0) = 0
52926 mmap(0,4096,1,262146,3,0) = 0x4201a000
52926 mmap(0,1597440,0,135170,-1,0) = 0x4201b000
52926 mmap(1107406848,1441792,5,393234,3,0) = 0x4201b000
52926 mmap(1108877312,32768,3,262162,3,0) = 0x42182000
52926 mmap(1108910080,94208,3,4114,-1,0) = 0x4218a000
52926 munmap(0x4201a000,4096) = 0
52926 close(3) = 0
52926 mmap(0,36864,3,4098,-1,1073803280) = 0x421a1000
52926 munmap(0x421a3000,28672) = 0
52926 mmap(0,69632,3,4098,-1,1107340751) = 0x421aa000
52926 sysarch(ARM_SET_TP, 0x42007200) = 0
52926 sigprocmask(1,1073896084,-1610619352,1073834052,-1610618936,1073893932) = 0
52926 sigprocmask(3,1073896100,0,1073834052,0,1073893840) = 0
52926 __sysctl({ 1 37 }, 2, 0x4218ad84, 0x9fffe204, 0x00000000, 0x00000000) = 0
52926 __sysctl({ 6 10 }, 2, 0x4219fa28, 0x9fffe1fc, 0x00000000, 0x00000000) = 0
52926 readlink("/etc/malloc.conf",0x9fffddf7,1024) = -1 errno=2 (No such file or directory)
52926 issetugid() = 0
52926 break(78464,78464,1108897260,0,1024,1) = -1 errno=22 (Invalid argument)
52926 mmap(0,4194304,3,4098,-1,-1610621449) = 0x421bb000
52926 munmap(0x421bb000,4194304) = 0
52926 mmap(0,8384512,3,4098,-1,3) = 0x425bb000
52926 munmap(0x425bb000,2379776) = 0
52926 munmap(0x42c00000,1810432) = 0
52926 __sysctl({ 6 3 }, 2, 0x9fffdc20, 0x9fffdc2c, 0x00000000, 0x00000000) = 0
52926 sigprocmask(1,1073896084,-1610620472,1073834052,-1610620392,1073746316) = 0
52926 sigprocmask(3,1073896100,0,1073834052,0,1073893840) = 0
52926 sigprocmask(1,1073896084,-1610620472,1073834052,0,0) = 0
52926 sigprocmask(3,1073896100,0,1073834052,0,1073893840) = 0
52926 sigprocmask(1,1073896084,-1610620472,1073834052,0,0) = 0
52926 sigprocmask(3,1073896100,0,1073834052,0,0) = 0
52926 __sysctl({ 0 3 }, 2, 0x9fffe370, 0x9fffe36c, 0x0000ac9e, 0x0000000f) = 0
52926 __sysctl({ 1 30 2147482824 }, 3, 0x00013224, 0x9fffe3f4, 0x00000000, 0x00000000) = 0
52926 __sysctl({ 0 3 }, 2, 0x9fffe370, 0x9fffe36c, 0x0000acae, 0x0000000f) = 0
52926 __sysctl({ 1 30 2147482823 }, 3, 0x00013228, 0x9fffe3f4, 0x00000000, 0x00000000) = 0
52926 __sysctl({ 0 3 }, 2, 0x9fffe370, 0x9fffe36c, 0x0000acbe, 0x0000000f) = 0
52926 __sysctl({ 1 30 2147482822 }, 3, 0x0001322c, 0x9fffe3f4, 0x00000000, 0x00000000) = 0
52926 __sysctl({ 0 3 }, 2, 0x9fffe370, 0x9fffe36c, 0x0000acce, 0x0000000f) = 0
52926 __sysctl({ 1 30 2147482821 }, 3, 0x00013230, 0x9fffe3f4, 0x00000000, 0x00000000) = 0
52926 __sysctl({ 0 3 }, 2, 0x9fffe370, 0x9fffe36c, 0x0000acde, 0x0000000f) = 0
52926 __sysctl({ 1 30 2147482820 }, 3, 0x00013234, 0x9fffe3f4, 0x00000000, 0x00000000) = 0
52926 __sysctl({ 0 3 }, 2, 0x9fffe370, 0x9fffe36c, 0x0000acee, 0x0000000f) = 0
52926 __sysctl({ 1 30 2147482819 }, 3, 0x00013238, 0x9fffe3f4, 0x00000000, 0x00000000) = 0
52926 sigprocmask(1,1073896084,-1610620352,1073834052,1073893932,1073742884) = 0
52926 sigprocmask(3,1073896100,0,1073834052,77740,52) = 0
52926 mmap(0,4194304,3,4098,-1,12) = 0x42dba000
52926 munmap(0x42dba000,4194304) = 0
52926 mmap(0,8384512,3,4098,-1,12) = 0x431ba000
52926 munmap(0x431ba000,2383872) = 0
52926 munmap(0x43800000,1806336) = 0
52926 __sysctl({ 0 3 }, 2, 0x9fffe370, 0x9fffe36c, 0x0000ac12, 0x0000000f) = 0
52926 __sysctl({ 1 30 2147482818 }, 3, 0x43403e00, 0x9fffe3f4, 0x00000000, 0x00000000) = -1 errno=12 (Cannot allocate memory)
52926 write(2,0x9fffde50,6)ipcs:  = 6
52926 write(2,0x9fffde78,29)sysctlbyname: kern.ipc.msqids = 29
52926 write(2,0x421708ca,2):  = 2
52926 stat("/usr/share/nls/C/libc.cat",0x9fffe2b0) = -1 errno=2 (No such file or directory)
52926 stat("/usr/share/nls/libc/C",0x9fffe2b0) = -1 errno=2 (No such file or directory)
52926 stat("/usr/local/share/nls/C/libc.cat",0x9fffe2b0) = -1 errno=2 (No such file or directory)
52926 stat("/usr/local/share/nls/libc/C",0x9fffe2b0) = -1 errno=2 (No such file or directory)
52926 write(2,0x9fffde50,23)Cannot allocate memory
 = 23
52926 sigprocmask(1,1073896084,-1610620488,1073834052,0,0) = 0
52926 sigprocmask(3,1073896100,0,1073834052,-1610619996,1073893056) = 0
52926 sigprocmask(1,1073896084,-1610621632,1073834052,0,0) = 0
52926 sigprocmask(3,1073896100,0,1073834052,-1610619996,1073893056) = 0
52926 sigprocmask(1,1073896084,-1610621632,1073834052,1107337268,-1610678267) = 0
52926 sigprocmask(3,1073896100,0,1073834052,-1610619996,1073893056) = 0
52926 sigprocmask(1,1073896084,-1610621632,1073834052,1107406900,6) = 0
52926 sigprocmask(3,1073896100,0,1073834052,2,1107309568) = 0
52926 exit(1)
Comment 8 Sean Bruno freebsd_committer freebsd_triage 2015-07-03 02:15:57 UTC
52926 __sysctl({ 1 30 2147482818 }, 3, 0x43403e00, 0x9fffe3f4, 0x00000000, 0x00000000) = -1 errno=12 (Cannot allocate memory)

^^ looks like one of our problems here.  Probably a missed endian/size change.
Comment 9 commit-hook freebsd_committer freebsd_triage 2016-01-04 18:26:54 UTC
A commit references this bug:

Author: sbruno
Date: Mon Jan  4 18:26:26 UTC 2016
New revision: 405260
URL: https://svnweb.freebsd.org/changeset/ports/405260

Log:
  Bump to 2.5.50.g20160103, catchup with latest bug fixes.

  Fix dereference of wrong pointer arg in ipc/semctl syscall.
  Fix return from mmap() to setEINVAL and MAP_FAILED when len is 0

  PR:		203852 200613
  Submitted by:	mikael.urankar@gmail.com

Changes:
  head/emulators/qemu-sbruno/Makefile
  head/emulators/qemu-sbruno/distinfo