NetBSD Problem Report #56487

From martin@aprisoft.de  Thu Nov  4 14:43:19 2021
Return-Path: <martin@aprisoft.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id C3FB81A9239
	for <gnats-bugs@gnats.NetBSD.org>; Thu,  4 Nov 2021 14:43:19 +0000 (UTC)
Message-Id: <20211104144309.EF0775CC84B@emmas.aprisoft.de>
Date: Thu,  4 Nov 2021 15:43:09 +0100 (CET)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: binary compat broken for COMPAT_NETBSD32
X-Send-Pr-Version: 3.95

>Number:         56487
>Category:       kern
>Synopsis:       binary compat broken for COMPAT_NETBSD32
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    thorpej
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 04 14:45:00 +0000 2021
>Closed-Date:    Sun Nov 07 19:57:22 +0000 2021
>Last-Modified:  Sun Nov 07 19:57:22 +0000 2021
>Originator:     Martin Husemann
>Release:        NetBSD 9.99.92
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD out-of-the-silent-planet.aprisoft.de 9.99.92 NetBSD 9.99.92 (GENERIC64) #226: Sun Oct 24 08:47:00 CEST 2021 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/evbarm/compile/GENERIC64 evbarm
Architecture: aarch64
Machine: evbarm
>Description:

My test environment chroots for COMPAT_NETBSD32 were broken by recent
sigtramp changes, e.g.:

Reading symbols from /usr/pkg/bin/tcsh...
(No debugging symbols found in /usr/pkg/bin/tcsh)
[New process 6227]
Core was generated by `tcsh'.
Program terminated with signal SIGSYS, Bad system call.
#0  0xf75fb9c8 in __sigtramp_sigcontext_1 () from /usr/lib/libc.so.12
(gdb) bt
#0  0xf75fb9c8 in __sigtramp_sigcontext_1 () from /usr/lib/libc.so.12
#1  0xf75fb9c0 in __vfork14 () from /usr/lib/libc.so.12


>How-To-Repeat:
With a new kernel and new (32bit) userland try to chroot and run some
previously compiled binaries from pkgsrc.

>Fix:
n/a

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: kern-bug-people->thorpej
Responsible-Changed-By: thorpej@NetBSD.org
Responsible-Changed-When: Thu, 04 Nov 2021 14:52:25 +0000
Responsible-Changed-Why:
TAke.


From: Jason Thorpe <thorpej@me.com>
To: Martin Husemann <martin@duskware.de>
Cc: "gnats-bugs@netbsd.org" <gnats-bugs@NetBSD.org>
Subject: Re: kern/56487 (binary compat broken for COMPAT_NETBSD32)
Date: Fri, 5 Nov 2021 07:02:13 -0700

 > On Nov 4, 2021, at 11:44 AM, Martin Husemann <martin@duskware.de> =
 wrote:
 >=20
 > On Thu, Nov 04, 2021 at 04:09:33PM +0100, Martin Husemann wrote:
 >> On Thu, Nov 04, 2021 at 02:52:26PM +0000, thorpej@NetBSD.org wrote:
 >>> Synopsis: binary compat broken for COMPAT_NETBSD32
 >>>=20
 >>> Responsible-Changed-From-To: kern-bug-people->thorpej
 >>> Responsible-Changed-By: thorpej@NetBSD.org
 >>> Responsible-Changed-When: Thu, 04 Nov 2021 14:52:25 +0000
 >>> Responsible-Changed-Why:
 >>> TAke.
 >>=20
 >> This might be ARM specific, there is libc asm code=20
 >> calling compat_16___sigreturn14.
 >=20
 > No, also happens for i386 binaries on amd64.

 This is because syscalls.master for COMPAT_NETBSD32 is wrong for =
 sigreturn14:

         {
                 ns(struct compat_16_netbsd32___sigreturn14_args),
                 .sy_call =3D (sy_call_t *)sys_nomodule
         },              /* 295 =3D compat_16_netbsd32___sigreturn14 */

 (Those functions do exist on aarch64 and amd64.). This was all masked =
 before because sigcontext wasn=E2=80=99t being used by libc.

 -- thorpej

From: Jason Thorpe <thorpej@me.com>
To: Martin Husemann <martin@duskware.de>
Cc: "gnats-bugs@netbsd.org" <gnats-bugs@NetBSD.org>
Subject: Re: kern/56487 (binary compat broken for COMPAT_NETBSD32)
Date: Fri, 5 Nov 2021 07:04:41 -0700

 > On Nov 5, 2021, at 7:02 AM, Jason Thorpe <thorpej@me.com> wrote:
 >=20
 > This is because syscalls.master for COMPAT_NETBSD32 is wrong for =
 sigreturn14:
 >=20
 >        {
 >                ns(struct compat_16_netbsd32___sigreturn14_args),
 >                .sy_call =3D (sy_call_t *)sys_nomodule
 >        },              /* 295 =3D compat_16_netbsd32___sigreturn14 */
 >=20
 > (Those functions do exist on aarch64 and amd64.). This was all masked =
 before because sigcontext wasn=E2=80=99t being used by libc.

 Ah, no, I=E2=80=99m wrong, but only slightly=E2=80=A6 it=E2=80=99s =
 intended that the =E2=80=9Ccompat_16=E2=80=9D module get loaded.  But =
 it=E2=80=99s likely that in the PK_32 case, we need to load a different =
 one, and possibly hook it differently?  What a mess.

 -- thorpej

From: Jason Thorpe <thorpej@me.com>
To: Martin Husemann <martin@duskware.de>
Cc: "gnats-bugs@netbsd.org" <gnats-bugs@NetBSD.org>
Subject: Re: kern/56487 (binary compat broken for COMPAT_NETBSD32)
Date: Fri, 5 Nov 2021 07:14:32 -0700

 > On Nov 5, 2021, at 7:04 AM, Jason Thorpe <thorpej@me.com> wrote:
 >=20
 > Ah, no, I=E2=80=99m wrong, but only slightly=E2=80=A6 it=E2=80=99s =
 intended that the =E2=80=9Ccompat_16=E2=80=9D module get loaded.  But =
 it=E2=80=99s likely that in the PK_32 case, we need to load a different =
 one, and possibly hook it differently?  What a mess.

 It=E2=80=99s even worse=E2=80=A6 the netbsd32_sendsig() functions =
 don=E2=80=99t even attempt to deal with this correctly.

 Ok, I think I grok what needs to be fixed now.

 -- thorpej

From: "Jason R Thorpe" <thorpej@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56487 CVS commit: src/sys/arch/aarch64/include
Date: Fri, 5 Nov 2021 15:18:18 +0000

 Module Name:	src
 Committed By:	thorpej
 Date:		Fri Nov  5 15:18:18 UTC 2021

 Modified Files:
 	src/sys/arch/aarch64/include: signal.h

 Log Message:
 Normally, to support COMPAT_NETBSD32 we need to define
 __HAVE_STRUCT_SIGCONTEXT in order to support the old
 "sigcontext" style of handlers for 32-bit binaries.
 However, we only support 32-bit EABI binaries on AArch64,
 and by happy accident (due to a libc bug introduced in
 2006), 32-bit NetBSD EABI binaries never used "sigcontext"
 style handlers.  So, we don't need to carry any of this
 baggage forward.

 This addresses the AArch64 case of PR kern/56487.


 To generate a diff of this commit:
 cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/include/signal.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->feedback
State-Changed-By: thorpej@NetBSD.org
State-Changed-When: Sat, 06 Nov 2021 20:43:52 +0000
State-Changed-Why:
Should be fixed now.  Please try on as many 64-bit platforms as you
have access to.


From: "Jason R Thorpe" <thorpej@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56487 CVS commit: src/sys
Date: Sat, 6 Nov 2021 20:42:57 +0000

 Module Name:	src
 Committed By:	thorpej
 Date:		Sat Nov  6 20:42:57 UTC 2021

 Modified Files:
 	src/sys/arch/aarch64/aarch64: netbsd32_machdep.c
 	src/sys/arch/amd64/amd64: netbsd32_machdep.c netbsd32_machdep_16.c
 	src/sys/arch/arm/include: netbsd32_machdep.h
 	src/sys/arch/mips/mips: netbsd32_machdep.c netbsd32_machdep_16.c
 	src/sys/arch/sparc64/sparc64: netbsd32_machdep.c netbsd32_machdep_16.c
 	src/sys/compat/netbsd32: netbsd32.h netbsd32_exec.h netbsd32_signal.c

 Log Message:
 COMPAT_NETBSD32 is all about running the 32-bit flavor of native
 binaries on a 64-bit platform[*], as such:
 - Make the logic about which "sendsig" flavor to call MI (as it is in the
   native 64-bit environment) and follow the same rules as the native 32-bit
   environment.
 - Make COMPAT_NETBSD32 x COMPAT_16 work the same as it would in the
   native 32-bit environment by providing a netbsd32_sendsig_sigcontext_16_hook,
   rather than overriding the entire sendsig logic with a netbsd32_sendsig_hook.
 - In netbsd32___sigaction_sigtramp(), make sure the compat_netbsd32_16
   module is loaded if the trampoline version specifies a sigcontext style
   handler, otherwise return EINVAL so that libc can try again with siginfo
   style.

 [*] ...except for arm32, which uses it to mean "run 32-bit OABI binaries
 from the 32-bit EABI environment".  Doing it this way was arguably a mistake,
 but we are stuck with it for now, so support it by providing a machine-
 dependent override for netbsd32_sendsig() that also disables the corresponding
 logic in netbsd32___sigaction_sigtramp().

 Fixes PR kern/56487.


 To generate a diff of this commit:
 cvs rdiff -u -r1.21 -r1.22 src/sys/arch/aarch64/aarch64/netbsd32_machdep.c
 cvs rdiff -u -r1.139 -r1.140 src/sys/arch/amd64/amd64/netbsd32_machdep.c
 cvs rdiff -u -r1.6 -r1.7 src/sys/arch/amd64/amd64/netbsd32_machdep_16.c
 cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/include/netbsd32_machdep.h
 cvs rdiff -u -r1.22 -r1.23 src/sys/arch/mips/mips/netbsd32_machdep.c
 cvs rdiff -u -r1.6 -r1.7 src/sys/arch/mips/mips/netbsd32_machdep_16.c
 cvs rdiff -u -r1.116 -r1.117 src/sys/arch/sparc64/sparc64/netbsd32_machdep.c
 cvs rdiff -u -r1.5 -r1.6 src/sys/arch/sparc64/sparc64/netbsd32_machdep_16.c
 cvs rdiff -u -r1.137 -r1.138 src/sys/compat/netbsd32/netbsd32.h
 cvs rdiff -u -r1.36 -r1.37 src/sys/compat/netbsd32/netbsd32_exec.h
 cvs rdiff -u -r1.52 -r1.53 src/sys/compat/netbsd32/netbsd32_signal.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/56487 (binary compat broken for COMPAT_NETBSD32)
Date: Sun, 7 Nov 2021 08:09:33 +0100

 aarch64:

 Summary for 905 test programs:
     8993 passed test cases.
     48 failed test cases.
     48 expected failed test cases.
     616 skipped test cases.


 amd64:

 Summary for 914 test programs:
     9993 passed test cases.
     49 failed test cases.
     52 expected failed test cases.
     630 skipped test cases.


 ... which is both as good as we can currently get (and same as a few weeks
 ago). On both old tcsh from pkgsrc works again too.

 Martin

State-Changed-From-To: feedback->closed
State-Changed-By: thorpej@NetBSD.org
State-Changed-When: Sun, 07 Nov 2021 19:57:22 +0000
State-Changed-Why:
Confirmed fixed.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.