NetBSD Problem Report #59134
From www@netbsd.org Wed Mar 5 16:24:43 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)
client-signature RSA-PSS (2048 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id BD31D1A923D
for <gnats-bugs@gnats.NetBSD.org>; Wed, 5 Mar 2025 16:24:42 +0000 (UTC)
Message-Id: <20250305162441.96A4A1A923F@mollari.NetBSD.org>
Date: Wed, 5 Mar 2025 16:24:41 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: POSIX-1.2024: pthread_setcancelstate must be async-signal-safe
X-Send-Pr-Version: www-1.0
>Number: 59134
>Category: lib
>Synopsis: POSIX-1.2024: pthread_setcancelstate must be async-signal-safe
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: riastradh
>State: needs-pullups
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Mar 05 16:25:00 +0000 2025
>Closed-Date:
>Last-Modified: Fri Apr 04 20:45:01 +0000 2025
>Originator: Taylor R Campbell
>Release: current, 10, 9, ...
>Organization:
The PthreadBSD Signalcancellation
>Environment:
>Description:
Under POSIX.1-2024, pthread_setcancelstate is required to be async-signal-safe: https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/pthread_setcanceltype.html
However, ours is not: it takes pt_lock, which is an ordinary mutex, and so it can't be async-signal-safe.
>How-To-Repeat:
try to use pthread_setcancelstate from a signal handler
>Fix:
Yes, please!
>Release-Note:
>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59134 CVS commit: src
Date: Mon, 31 Mar 2025 13:57:07 +0000
Module Name: src
Committed By: riastradh
Date: Mon Mar 31 13:57:06 UTC 2025
Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi
src/tests/lib/libpthread: Makefile
Added Files:
src/tests/lib/libpthread: t_cancellation.c
Log Message:
pthread_cancel(3): Add some automatic tests.
PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe
To generate a diff of this commit:
cvs rdiff -u -r1.470 -r1.471 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.1362 -r1.1363 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libpthread/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libpthread/t_cancellation.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/59134 CVS commit: src
Date: Mon, 31 Mar 2025 14:07:10 +0000
Module Name: src
Committed By: riastradh
Date: Mon Mar 31 14:07:10 UTC 2025
Modified Files:
src/lib/libpthread: pthread.c pthread_cancelstub.c pthread_cond.c
pthread_int.h
src/tests/lib/libpthread: t_cancellation.c
Log Message:
pthread_cancel(3): Rework.
Make pthread_setcancelstate(3) async-signal-safe. (As a side effect,
this also makes pthread_setcanceltype(3) async-signal-safe, although
that is not required.)
PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe
To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.45 -r1.46 src/lib/libpthread/pthread_cancelstub.c
cvs rdiff -u -r1.77 -r1.78 src/lib/libpthread/pthread_cond.c
cvs rdiff -u -r1.112 -r1.113 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_cancellation.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Responsible-Changed-From-To: lib-bug-people->riastradh
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Tue, 01 Apr 2025 01:41:33 +0000
Responsible-Changed-Why:
fixed in HEAD, needs pullup-10 and pullup-9 (no API or ABI changes to
libpthread, purely internal changes)
State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 01 Apr 2025 01:41:33 +0000
State-Changed-Why:
mine
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59134 CVS commit: src/lib/libpthread
Date: Wed, 2 Apr 2025 14:23:34 +0000
Module Name: src
Committed By: riastradh
Date: Wed Apr 2 14:23:34 UTC 2025
Modified Files:
src/lib/libpthread: pthread.c pthread_int.h
Log Message:
pthread_cancel(3): Use _Atomic consistently with C11 atomics.
Should fix clang build:
/home/source/ab/HEAD-llvm/src/lib/libpthread/pthread.c:1264:8: error: address argument to atomic operation must be a pointer to _Atomic type ('volatile unsigned int *' invalid)
(atomic_load_relaxed(&self->pt_cancel) &
^ ~~~~~~~~~~~~~~~~
/home/source/ab/HEAD-llvm/src/lib/libpthread/pthread.c:74:2: note: expanded from macro 'atomic_load_relaxed'
atomic_load_explicit(p, memory_order_relaxed)
^ ~
/home/builds/ab/HEAD-llvm/amd64/202504020240Z-dest/usr/include/clang-13.0/stdatomic.h:121:30: note: expanded from macro 'atomic_load_explicit'
#define atomic_load_explicit __c11_atomic_load
PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe
To generate a diff of this commit:
cvs rdiff -u -r1.186 -r1.187 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.113 -r1.114 src/lib/libpthread/pthread_int.h
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/59134 CVS commit: src/lib/libpthread
Date: Fri, 4 Apr 2025 20:40:58 +0000
Module Name: src
Committed By: riastradh
Date: Fri Apr 4 20:40:58 UTC 2025
Modified Files:
src/lib/libpthread: pthread_cancelstub.c
Log Message:
libpthread: Use typeof rather than copying signatures of cancelstubs.
This would have caught my previous mistake with paccept.
Omit needless declarations that are already covered by the
compat/*/*.h header files.
No functional change intended. This is purely an improvement to
build-time error detection.
PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe
PR lib/59247: pthread_cancelstub.c is inadequately tested
To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/lib/libpthread/pthread_cancelstub.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(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.