NetBSD Problem Report #52342

From www@NetBSD.org  Mon Jun 26 08:00:49 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 4A5E67A175
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 26 Jun 2017 08:00:49 +0000 (UTC)
Message-Id: <20170626080047.92A167A283@mollari.NetBSD.org>
Date: Mon, 26 Jun 2017 08:00:47 +0000 (UTC)
From: u-bc8k@aetey.se
Reply-To: u-bc8k@aetey.se
To: gnats-bugs@NetBSD.org
Subject: linux ABI exit(non-zero) returns zero status to the parent process
X-Send-Pr-Version: www-1.0

>Number:         52342
>Category:       kern
>Synopsis:       linux ABI exit(non-zero) returns zero status to the parent process
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 26 08:05:00 +0000 2017
>Last-Modified:  Mon Jun 26 14:15:01 +0000 2017
>Originator:     u-bc8k
>Release:        7.1
>Organization:
Aetey
>Environment:
NetBSD XXXX 7.1 NetBSD 7.1 (GENERIC.201703111743Z) amd64
>Description:
/a/linux-i386/binary/doing/syscall/exit_1; echo "$?"

prints "0"

(ktrace shows "CALL  exit(1)" as the last syscall from the linux binary)

The most visible practical outcome is that shell scripts break.

>How-To-Repeat:
/a/linux-i386/binary/doing/syscall/exit_1; echo "$?"

It does not seem to make a difference whether the parent (the shell) is a native (NetBSD amd64) or a Linux i386 binary.

Not tested with 64-bit linux binaries.

>Fix:

>Audit-Trail:
From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: re: kern/52342: linux ABI exit(non-zero) returns zero status to the parent process
Date: Mon, 26 Jun 2017 21:36:48 +1000

 FWIW, my june 12 netbsd-7 branch system works fine for this:

 space-bird ~> uname -sr
 NetBSD 7.1_STABLE
 space-bird ~> file /emul/linux/usr/bin/false /emul/linux32/usr/bin/false
 /emul/linux/usr/bin/false:   ELF 64-bit LSB executable, x86-64, version 1 =
 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, Build=
 ID[sha1]=3D87be6d24cdaaa0afd60da1ad48c016f5ea709410, stripped
 /emul/linux32/usr/bin/false: ELF 32-bit LSB executable, Intel 80386, versi=
 on 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, =
 BuildID[sha1]=3D9d82388dd6116aa6920afeba401ac10b80906fff, stripped
 space-bird ~> /emul/linux/usr/bin/false || echo good
 good
 space-bird ~> /emul/linux32/usr/bin/false || echo good
 good

 can you ktrace your binaries and see what happens?


 .mrg.

From: u-bc8k@aetey.se
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: kern/52342: linux ABI exit(non-zero) returns zero status to the
 parent process
Date: Mon, 26 Jun 2017 14:49:22 +0200

 Thanks for paying attention.

 On Mon, Jun 26, 2017 at 11:40:01AM +0000, matthew green wrote:
 >  space-bird ~> file /emul/linux/usr/bin/false /emul/linux32/usr/bin/false
 >  /emul/linux/usr/bin/false:   ELF 64-bit LSB executable, x86-64, version 1 =
 >  (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, Build=
 >  ID[sha1]=3D87be6d24cdaaa0afd60da1ad48c016f5ea709410, stripped
 >  /emul/linux32/usr/bin/false: ELF 32-bit LSB executable, Intel 80386, versi=
 >  on 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, =
 >  BuildID[sha1]=3D9d82388dd6116aa6920afeba401ac10b80906fff, stripped
 >  space-bird ~> /emul/linux/usr/bin/false || echo good
 >  good
 >  space-bird ~> /emul/linux32/usr/bin/false || echo good
 >  good
 >  
 >  can you ktrace your binaries and see what happens?

 Sure:

 -----------------------
 $ file cat
 cat: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, stripped
 $ ./cat /nosuchfile && echo BAD
 cat: /nosuchfile: No such file or directory
 BAD
 $ ktrace ./cat /nosuchfile
 cat: /nosuchfile: No such file or directory
 $ kdump
   9256      1 ktrace   EMUL  "netbsd"
   9256      1 ktrace   CALL  execve(0x7f7ffffffe7f,0x7f7fffffdcc0,0x7f7fffffdcd8)
   9256      1 ktrace   NAMI  "./cat"
   9256      1 cat      NAMI  "/emul/linux32"
   9256   9256 cat      EMUL  "linux32"
   9256   9256 cat      RET   execve -1 errno -2 No such file or directory
   9256   9256 cat      CALL  open(0xbffffe56,0,0)
   9256   9256 cat      NAMI  "/nosuchfile"
   9256   9256 cat      RET   open -1 errno -2 No such file or directory
   9256   9256 cat      CALL  netbsd32_write(2,0x80485bc,5)
   9256   9256 cat      GIO   fd 2 wrote 5 bytes
        "cat: "
   9256   9256 cat      RET   netbsd32_write 5
   9256   9256 cat      CALL  netbsd32_write(2,0xbffffe56,0xb)
   9256   9256 cat      GIO   fd 2 wrote 11 bytes
        "/nosuchfile"
   9256   9256 cat      RET   netbsd32_write 11/0xb
   9256   9256 cat      CALL  netbsd32_write(2,0x80485b8,2)
   9256   9256 cat      GIO   fd 2 wrote 2 bytes
        ": "
   9256   9256 cat      RET   netbsd32_write 2
   9256   9256 cat      CALL  netbsd32_write(2,0x8048898,0x19)
   9256   9256 cat      GIO   fd 2 wrote 25 bytes
        "No such file or directory"
   9256   9256 cat      RET   netbsd32_write 25/0x19
   9256   9256 cat      CALL  netbsd32_write(2,0x80485b4,1)
   9256   9256 cat      GIO   fd 2 wrote 1 bytes
        "\n"
   9256   9256 cat      RET   netbsd32_write 1
   9256   9256 cat      CALL  exit(1)
 $ uname -a
 NetBSD XXXX 7.1 NetBSD 7.1 (GENERIC.201703111743Z) amd64
 -----------------------

 My guess is that your test binaries do not use exit() but rather
 exit_group(). The use of old-style syscalls apparently is rare
 nowadays but as long as exit() is supported it would be nice if it
 behaves.


From: matthew green <mrg@eterna.com.au>
To: u-bc8k@aetey.se
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org, gnats-bugs@NetBSD.org
Subject: re: kern/52342: linux ABI exit(non-zero) returns zero status to the parent process
Date: Mon, 26 Jun 2017 23:46:32 +1000

 > My guess is that your test binaries do not use exit() but rather
 > exit_group(). The use of old-style syscalls apparently is rare
 > nowadays but as long as exit() is supported it would be nice if it
 > behaves.

 indeed - ktrace shows exit_group() for the false(1) binary.

 hmm, even a static binary using _exit(2) shows exit_group()
 system call.  how does one get exit system call to be used?


 .mrg.

From: u-bc8k@aetey.se
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: kern/52342: linux ABI exit(non-zero) returns zero status to the
 parent process
Date: Mon, 26 Jun 2017 16:12:31 +0200

 On Mon, Jun 26, 2017 at 01:50:01PM +0000, matthew green wrote:
 >  indeed - ktrace shows exit_group() for the false(1) binary.
 >  
 >  hmm, even a static binary using _exit(2) shows exit_group()
 >  system call.  how does one get exit system call to be used?

 a bit of assembler:

 ebx <== exit status
 eax <== "1" which is __NR_exit

 int 0x80

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.