NetBSD Problem Report #59323

From www@netbsd.org  Sat Apr 19 01:26:56 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 5A74A1A9239
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 19 Apr 2025 01:26:56 +0000 (UTC)
Message-Id: <20250419012655.134CF1A923D@mollari.NetBSD.org>
Date: Sat, 19 Apr 2025 01:26:55 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: t_sigaction:sigaction_resethand test is failing
X-Send-Pr-Version: www-1.0

>Number:         59323
>Category:       port-sparc
>Synopsis:       t_sigaction:sigaction_resethand test is failing
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-sparc-maintainer
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 19 01:30:01 +0000 2025
>Closed-Date:    
>Last-Modified:  Sat Apr 19 01:35:01 +0000 2025
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, ...
>Organization:
The ResetBSparcD Sigaction
>Environment:
>Description:
FAILED: Child process did not exit cleanly; it either failed to process the signal or SA_RESETHAND is broken; raw exit status was 139

Specifically, as soon as the SIGUSR1 signal is delivered here on return from kill(2), the process gets a SIGSEGV immediately afterward, with pc set to 0 according to gdb:

     64     kill(getpid(), SIGUSR1);

https://nxr.netbsd.org/xref/src/tests/lib/libc/sys/t_sigaction.c?r=1.5#64

Turns out the problem is that SA_RESETHAND has been broken in sparc since the newlock2 merge in 2007 -- it always tries to invoke address 0 as the signal handler, because it _first_ resets the sigaction and _then_ reads the sigaction address to invoke.  Oops.

    543 	sendsig_reset(l, sig);
...
    576 		catcher = (u_int)SIGACTION(p, sig).sa_handler;
    577 		tf->tf_pc = catcher;
    578 		tf->tf_npc = catcher + 4;
    579 		tf->tf_out[0] = sig;
    580 		tf->tf_out[1] = (int)&fp->sf_si;
    581 		tf->tf_out[2] = (int)&fp->sf_uc;
    582 		tf->tf_out[6] = newsp;
    583 		tf->tf_out[7] = (int)ps->sa_sigdesc[sig].sd_tramp - 8;

https://nxr.netbsd.org/xref/src/sys/arch/sparc/sparc/machdep.c?r=1.341#543
>How-To-Repeat:
cd /usr/tests/lib/libc/sys
atf-run t_sigaction | atf-report
>Fix:
read SIGACTION(p, sig).sa_handler _before_ calling sendsig_reset

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 19 Apr 2025 01:33:16 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-10, 9, 8, 7, 6, 5...


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59323 CVS commit: src/sys/arch/sparc/sparc
Date: Sat, 19 Apr 2025 01:32:42 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Apr 19 01:32:42 UTC 2025

 Modified Files:
 	src/sys/arch/sparc/sparc: machdep.c

 Log Message:
 sparc: Load the signal handler _before_ resetting it, not after.

 Should fix SA_RESETHAND.

 PR port-sparc/59323: t_sigaction:sigaction_resethand test is failing


 To generate a diff of this commit:
 cvs rdiff -u -r1.341 -r1.342 src/sys/arch/sparc/sparc/machdep.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.