NetBSD Problem Report #59343
From www@netbsd.org Wed Apr 23 02:28:25 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 899A61A9239
for <gnats-bugs@gnats.NetBSD.org>; Wed, 23 Apr 2025 02:28:25 +0000 (UTC)
Message-Id: <20250423022824.55E191A923E@mollari.NetBSD.org>
Date: Wed, 23 Apr 2025 02:28:24 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: compat_sigsetjmp.S: missing RESTORE_GP64
X-Send-Pr-Version: www-1.0
>Number: 59343
>Category: port-mips
>Synopsis: compat_sigsetjmp.S: missing RESTORE_GP64
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: port-mips-maintainer
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Apr 23 02:30:00 +0000 2025
>Last-Modified: Thu Apr 24 12:55:02 +0000 2025
>Originator: Taylor R Campbell
>Release: current, 10, 9, 8, 7, 6, ...
>Organization:
The CompatBSD Mipsglobalization
>Environment:
>Description:
The compat13 sigsetjmp function uses SAVE_GP and SAVE_GP64 to save gp on ABIs where gp is callee-saves (n32, n64), so it can restore gp when it returns. Except it doesn't actually restore gp -- it does a tail call to _setjmp or setjmp, but doesn't return gp before (or after, making it a non-tail call).
61 LEAF(sigsetjmp)
62 SETUP_GP
63 SETUP_GP64(t0, sigsetjmp)
64 INT_S a1, _SC_MASK13(a0) # save "savemask"
65 bne a1, 0x0, 1f # do saving of signal mask?
66 PTR_LA t9, _C_LABEL(_setjmp)
67 jr t9
68
69 1: PTR_LA t9, _C_LABEL(setjmp)
70 jr t9
71 END(sigsetjmp)
https://nxr.netbsd.org/xref/src/lib/libc/compat/arch/mips/gen/compat_sigsetjmp.S?r=1.3#61
It's OK for longjmp to not restore gp -- it doesn't return. But setjmp definitely does return.
>How-To-Repeat:
run a binary that uses compat13 sigsetjmp and siglongjmp
>Fix:
RESTORE_GP64
>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59343 CVS commit: src/tests/lib/libc/setjmp
Date: Thu, 24 Apr 2025 01:41:01 +0000
Module Name: src
Committed By: riastradh
Date: Thu Apr 24 01:41:01 UTC 2025
Modified Files:
src/tests/lib/libc/setjmp: t_setjmp.c
Log Message:
t_setjmp: Tidy up.
- KNF.
- Nix trailing whitespace.
- Use RL from h_macros.h.
- Use enum and case.
No functional change intended.
Preparation for extending these tests to the compat13 functions,
prompted by:
PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1
PR port-mips/59342: compat_setjmp.S is confused about delay slots
PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/setjmp/t_setjmp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59343 CVS commit: src/tests/lib/libc/setjmp
Date: Thu, 24 Apr 2025 01:41:48 +0000
Module Name: src
Committed By: riastradh
Date: Thu Apr 24 01:41:48 UTC 2025
Modified Files:
src/tests/lib/libc/setjmp: t_setjmp.c t_sigstack.c
Log Message:
t_setjmp, t_sigstack: Test compat13 setjmp/sigsetjmp too.
PR port-mips/59342: compat_setjmp.S is confused about delay slots
PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/setjmp/t_setjmp.c
cvs rdiff -u -r1.13 -r1.14 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: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59343 CVS commit: src
Date: Thu, 24 Apr 2025 01:42:38 +0000
Module Name: src
Committed By: riastradh
Date: Thu Apr 24 01:42:38 UTC 2025
Modified Files:
src/lib/libc/compat/arch/mips/gen: compat_sigsetjmp.S
src/tests/lib/libc/setjmp: t_setjmp.c t_sigstack.c
Log Message:
mips/compat_sigsetjmp: Add missing RESTORE_GP64.
Otherwise, compat13 sigsetjmp clobbers the caller's gp when it
returns (the first time around, anyway), which leads to a lovely
display of fireworks.
PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/compat/arch/mips/gen/compat_sigsetjmp.S
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/setjmp/t_setjmp.c
cvs rdiff -u -r1.15 -r1.16 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: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59343 CVS commit: src/sys/arch/mips/mips
Date: Thu, 24 Apr 2025 12:54:43 +0000
Module Name: src
Committed By: riastradh
Date: Thu Apr 24 12:54:43 UTC 2025
Modified Files:
src/sys/arch/mips/mips: compat_13_machdep.c
Log Message:
mips: Fix compat_13_sys_sigreturn locking.
This had been broken back in rev. 1.13.20.1 (on the newlock2 branch,
merged into HEAD as 1.14) in 2007.
Should fix:
lib/libc/setjmp/t_setjmp (261/985): 10 test cases
_longjmp_zero: [0.078125s] Passed.
_setjmp: [0.093750s] Passed.
compat13_longjmp_zero: [ 7875.3945352] panic: kernel diagnostic assertion "mutex_owned(l->l_proc->p_lock)" failed: file "/tmp/build/2025.04.24.01.52.38-pmax/src/sys/kern/sys_sig.c", line 590
[ 7875.3984415] cpu0: Begin traceback...
[ 7875.4062540] pid -2135532376 not found
[ 7875.4140665] cpu0: End traceback...
[ 7875.6093790] 0x80b65c90: cpu_reboot+0x3c (0x80b64000,0,0x866e5400,0x805b6440) ra 0x803197c0 sz 24
[ 7875.7109415] 0x80b65ca8: kern_reboot+0xb0 (0x80b64000,0,0x866e5400,0x805b6440) ra 0x80369c80 sz 40
[ 7875.7109415] 0x80b65cd0: vpanic+0x1dc (0x80b64000,0,0x866e5400,0x805b6440) ra 0x804c085c sz 48
[ 7875.7109415] 0x80b65d00: kern_assert+0x3c (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x8038df4c sz 32
[ 7875.7265665] 0x80b65d20: sigprocmask1+0x224 (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x800616f0 sz 48
[ 7875.7265665] 0x80b65d50: compat_13_sys_sigreturn+0x1f0 (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x80055178 sz 376
[ 7875.7265665] 0x80b65ec8: syscall+0x158 (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x800450ac sz 128
[ 7875.7265665] 0x80b65f48: mips1_systemcall+0xec (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x7923d090 sz 0
[ 7875.7265665] PC 0x7923d090: not in kernel space
[ 7875.7265665] 0x80b65f48: 0+0x7923d090 (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0 sz 0
[ 7875.7265665] User-level: pid 17290.17290
https://releng.netbsd.org/b5reports/pmax/2025/2025.04.24.01.52.38/test.log
(Probably won't do anything about `pid -2135532376 not found',
though!)
Prompted by adding tests for compat13 for:
PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1
PR port-mips/59342: compat_setjmp.S is confused about delay slots
PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64
To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/mips/mips/compat_13_machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
(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.