NetBSD Problem Report #59351

From www@netbsd.org  Fri Apr 25 01:38:41 2025
Return-Path: <www@netbsd.org>
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)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 946FA1A9239
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 25 Apr 2025 01:38:41 +0000 (UTC)
Message-Id: <20250425013840.A9AF51A923E@mollari.NetBSD.org>
Date: Fri, 25 Apr 2025 01:38:40 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: compat_setjmp is busted
X-Send-Pr-Version: www-1.0

>Number:         59351
>Category:       port-arm
>Synopsis:       compat_setjmp is busted
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-arm-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 25 01:40:00 +0000 2025
>Last-Modified:  Mon Apr 28 02:51:07 +0000 2025
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
Arm CompatBSD Longjmation
>Environment:
>Description:
From https://releng.netbsd.org/b5reports/evbarm-earmv7hf/2025/2025.04.24.01.52.38/test.log:

lib/libc/setjmp/t_setjmp (261/986): 10 test cases
    _longjmp_zero: [0.065441s] Passed.
    _setjmp: [0.062947s] Passed.
    compat13_longjmp_zero: [8.192142s] Failed: Test program received signal 11 (core dumped)
    compat13_setjmp: [1.058821s] Failed: Test program received signal 11 (core dumped)
    compat13_sigsetjmp_nosave: [0.063790s] Passed.
    compat13_sigsetjmp_save: [0.988738s] Failed: Test program received signal 11 (core dumped)
    longjmp_zero: [0.062163s] Passed.
    setjmp: [0.061560s] Passed.
    sigsetjmp_nosave: [0.061967s] Passed.
    sigsetjmp_save: [0.061220s] Passed.
[10.743598s]

lib/libc/setjmp/t_sigstack (262/986): 4 test cases
    compat13_setjmp: Apr 24 07:29:22 armv7 ntpd[198]: error resolving pool 2.netbsd.pool.ntp.org: Temporary failure in name resolution (2)
[1.010904s] Failed: Test program received signal 11 (core dumped)
    compat13_sigsetjmp: [0.997175s] Failed: Test program received signal 11 (core dumped)
    setjmp: [0.063601s] Passed.
    sigsetjmp: [0.063928s] Passed.
[2.168248s]

(Don't have the full test output.  The ntpd log message is almost certainly unrelated.)
>How-To-Repeat:
cd /usr/tests/lib/libc/setjmp
atf-run | atf-report
>Fix:
Yes, please!

>Release-Note:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59351 CVS commit: src/tests/lib/libc/setjmp
Date: Fri, 25 Apr 2025 01:56:52 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Apr 25 01:56:52 UTC 2025

 Modified Files:
 	src/tests/lib/libc/setjmp: t_setjmp.c t_sigstack.c

 Log Message:
 t_setjmp, t_sigstack: Mark compat13 setjmp tests xfail on arm.

 (Does it even make sense to have compat_setjmp on arm?  Didn't we
 break ABI compatibility with the oabi->eabi transition, long after
 1.3?)

 PR port-arm/59351: compat_setjmp is busted


 To generate a diff of this commit:
 cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/setjmp/t_setjmp.c
 cvs rdiff -u -r1.20 -r1.21 src/tests/lib/libc/setjmp/t_sigstack.c

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

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-arm/59351: compat_setjmp is busted
Date: Mon, 28 Apr 2025 01:53:19 +0300

 Looks like gimpy accidentally deleted the register restore instruction
 after the call to sigblock in 1.3 of

   lib/libc/compat/arch/arm/gen/compat_setjmp.S

 so it tries to store the sigmask into the sigmask (taken as the
 jumpbuf address):

 	push	{r0, lr}
 	movs	r0, #0x00000000

 	bl	PLT_SYM(_C_LABEL(sigblock))
 	mov	r1, r0

 -->    // register restore here lost in rev 1.3
 	// r0 below should be the original jb argument

 	/* Store signal mask */
 	str	 r1, [r0, #(_JB_SIGMASK * 4)]

 -uwe

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-arm/59351: compat_setjmp is busted
Date: Mon, 28 Apr 2025 03:05:46 +0300

 I think this should fix it (also fixes the incorrect comment about
 sigblock).

 Index: lib/libc/compat/arch/arm/gen/compat_setjmp.S
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/compat/arch/arm/gen/compat_setjmp.S,v
 retrieving revision 1.5
 diff -u -p -r1.5 compat_setjmp.S
 --- lib/libc/compat/arch/arm/gen/compat_setjmp.S	5 Dec 2020 11:18:21 -0000	1.5
 +++ lib/libc/compat/arch/arm/gen/compat_setjmp.S	28 Apr 2025 00:06:08 -0000
 @@ -46,12 +46,13 @@
   */

  ENTRY(setjmp)
 -	/* Block all signals and retrieve the old signal mask */
 +	/* Retrieve the old signal mask */
  	push	{r0, lr}
  	movs	r0, #0x00000000

  	bl	PLT_SYM(_C_LABEL(sigblock))
  	mov	r1, r0
 +	pop	{r0, lr}

  	/* Store signal mask */
  	str	r1, [r0, #(_JB_SIGMASK * 4)]
 @@ -83,7 +84,7 @@ ENTRY(setjmp)
  	stmia	r0, {r4-lr}
  #endif
  	movs	r0, #0
 -	pop	{r3, pc}
 +	RET
  END(setjmp)

  ENTRY(longjmp)

 -uwe

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59351 CVS commit: src/tests/lib/libc/setjmp
Date: Mon, 28 Apr 2025 00:28:27 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Apr 28 00:28:27 UTC 2025

 Modified Files:
 	src/tests/lib/libc/setjmp: t_sigstack.c

 Log Message:
 t_sigstack: Don't do atf_tc_expect_fail then atf_tc_expect_signal.

 atf interprets this sequence, with no intervening atf_tc_fail, to
 mean the xfail failed to fail so it fails.  (Got that?)  That is, it
 is interpreted somewhat like

 	atf_tc_expect_fail(...);
 	... there is supposed to be a failure here ...
 	atf_tc_expect_pass();
 	... remaining checks are expected to pass ...

 where a lack of failures between the xfail and the xpass means the
 expectation was not met.

 But in this case, there are two compounding bugs:

 1. the compat 1.3 setjmp has botched its registers, as uwe@
    discovered, so it is expected to crash on SIGSEGV (PR 59351); and

 2. the compat 1.3 longjmp restores the stack poiter and signal mask
    in the wrong order, so it is expected to fail the test (PR 57946).

 Since the crash in setjmp triggers before the failure after longjmp,
 only do atf_tc_expect_signal; once that is fixed we can re-enable the
 atf_tc_expect_fail for longjmp.

 PR lib/57946: longjmp fails to restore stack first before restoring
 signal mask on most architectures

 PR port-arm/59351: compat_setjmp is busted


 To generate a diff of this commit:
 cvs rdiff -u -r1.21 -r1.22 src/tests/lib/libc/setjmp/t_sigstack.c

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

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.