NetBSD Problem Report #61051

From www@netbsd.org  Mon Nov 23 14:52:02 2026
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 "YR1" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 418F81A923B
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 23 Nov 2026 14:52:02 +0000 (UTC)
Message-Id: <20261123145200.4F9CF1A923D@mollari.NetBSD.org>
Date: Mon, 23 Nov 2026 14:52:00 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: async-signal-safe function list audit
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         61051
>Category:       lib
>Synopsis:       async-signal-safe function list audit
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 23 14:55:00 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
Asynchrooty Promises LLC
>Environment:
>Description:

	The sigaction(2) man page has a big list of library functions
	that are async-signal-safe.  PR lib/59146 (POSIX.1-2024:
	async-signal-safety audit) is for review of whether we meet the
	standard, but for non-standard extensions, are we missing
	anything or have we added anything we shouldn't?

	Prompted by Rust users wondering about chroot(2):
	https://github.com/rust-lang/rust/pull/163067#issuecomment-7097087125

	I compared syscalls.master to the list in the sigaction(2) man
	page and found the following discrepancies jump out at me.
	Omitted: internal syscalls starting with _ (like __acl_*,
	__clone, __futex, _ksem_*, &c.), syscalls that we are not
	really committed to (like epoll_*).

	[ ] acct(2)

	    Verdict?
	    acct:			( ) safe	( ) unsafe

	[ ] afssys(2)

	    Verdict?
	    acct:			( ) safe	( ) unsafe

	[ ] aio_* -- these are already commented out in the man page,
	    not sure what to think about that.  I think the API is
	    supposed to make sense from a SIGIO signal handler but it's
	    always been a second-class citizen without real kernel
	    support, so...

	    Verdict?
	    aio_cancel:			( ) safe	( ) unsafe
	    aio_error:			( ) safe	( ) unsafe
	    aio_fsync:			( ) safe	( ) unsafe
	    aio_read:			( ) safe	( ) unsafe
	    aio_return:			( ) safe	( ) unsafe
	    aio_suspend:		( ) safe	( ) unsafe
	    aio_write:			( ) safe	( ) unsafe

	[ ] adjtime(2), ntp_adjtime(2)

	    Verdict?
	    acct:			( ) safe	( ) unsafe

	[ ] chflags(2) is much like the safe chmod(2), and I think
	    unlikely to be changed.

	    Verdict?
	    chflags:			( ) safe	( ) unsafe

	[ ] chroot(2) is much like the safe chdir(2), and I think
	    unlikely to be changed.

	    Verdict?
	    chroot:			( ) safe	( ) unsafe

	[ ] clock_* -- these are mostly staright syscalls and
	    clock_gettime is already required to be async-signal-safe

	    Verdict?
	    clock_getcpuclockid2:	( ) safe	( ) unsafe
	    clock_getres:		( ) safe	( ) unsafe
	    clock_nanosleep:		( ) safe	( ) unsafe
	    clock_settime:		( ) safe	( ) unsafe
	    gettimeofday:		( ) safe	( ) unsafe
	    settimeofday:		( ) safe	( ) unsafe

	[ ] dup3(3) is much like dup2(3).  It does have a nontrivial
	    compat100 wrapper for some semantics that changed between
	    10.0 and 11.0 but I have no idea why and the commit message
	    is totally useless and there's no reference to a PR or
	    discussion:

	    https://mail-index.netbsd.org/source-changes/2024/05/19/msg151468.html

	    And the compat wrapper looks async-signal-safe anyway:

	    https://nxr.netbsd.org/xref/src/lib/libc/compat/sys/compat_dup3.c?r=1.4

	    Verdict?
	    dup3:			( ) safe	( ) unsafe

	[ ] eventfd(2) creates a file descriptor much like pipe(2),
	    which is async-signal-safe in POSIX; eventfd_read(3) and
	    eventfd_write(3) are just thin wrappers around read(2) and
	    write(2), which are async-signal-safe in POSIX

	    Verdict?
	    eventfd:			( ) safe	( ) unsafe
	    eventfd_read:		( ) safe	( ) unsafe
	    eventfd_write:		( ) safe	( ) unsafe

	[ ] extattr_* (not to be confused with *xattr functions!)

	    Verdict?
	    extattr_delete_fd:		( ) safe	( ) unsafe
	    extattr_delete_file:	( ) safe	( ) unsafe
	    extattr_delete_link:	( ) safe	( ) unsafe
	    extattr_get_fd:		( ) safe	( ) unsafe
	    extattr_get_file:		( ) safe	( ) unsafe
	    extattr_get_link:		( ) safe	( ) unsafe
	    extattr_list_fd:		( ) safe	( ) unsafe
	    extattr_list_file:		( ) safe	( ) unsafe
	    extattr_list_link:		( ) safe	( ) unsafe
	    extattr_set_fd:		( ) safe	( ) unsafe
	    extattr_set_file:		( ) safe	( ) unsafe
	    extattr_set_link:		( ) safe	( ) unsafe

	[ ] extattrctl(2)

	    Verdict?
	    extattrctl:			( ) safe	( ) unsafe

	[ ] f* fd-relative directory lookup syscalls -- fchmod(2) and
	    fchown(2) are already async-signal-safe as are the various
	    absolute or wd-relative ones like access(2)

	    Verdict?

	    faccessat:			( ) safe	( ) unsafe
	    fchdir:			( ) safe	( ) unsafe
	    fchflags:			( ) safe	( ) unsafe
	    fchmodat:			( ) safe	( ) unsafe
	    fchownat:			( ) safe	( ) unsafe
	    fchroot:			( ) safe	( ) unsafe
	    fexecve:			( ) safe	( ) unsafe
	    fstatat:			( ) safe	( ) unsafe
	    fstatfs:			( ) safe	( ) unsafe
	    fstatvfs1:			( ) safe	( ) unsafe

	[ ] fsync_range(2) is basically like fsync(2) which is required
	    to be async-signal-safe

	    Verdict?
	    fsync_range:		( ) safe	( ) unsafe

	[ ] utimes-like functions -- the standard ones (futimens,
	    utimensat, utimes) are required to be safe; presumably the
	    others should be too?

	    Verdict?
	    futimens:			(*) safe	( ) unsafe
	    futimes:			( ) safe	( ) unsafe
	    lutimens:			( ) safe	( ) unsafe
	    lutimes:			( ) safe	( ) unsafe
	    utimens:			( ) safe	( ) unsafe
	    utimensat:			(*) safe	( ) unsafe
	    utimes:			(*) safe	( ) unsafe

	[ ] getcontext(2), setcontext(2), makecontext(2),
	    swapcontext(2) -- really shouldn't affect or be affected by
	    any global state outside the parameters, and these are
	    likely to be used in applications to abort from signal
	    handlers (like longjmp) or potentially swap coroutines in
	    signal handlers

	    Verdict?
	    getcontext:			( ) safe	( ) unsafe
	    makecontext:		( ) safe	( ) unsafe
	    setcontext:			( ) safe	( ) unsafe
	    swapcontext:		( ) safe	( ) unsafe

	[ ] getdents(2) [modern], getdirentries(2) [obsolete] --
	    straight syscalls, but too internal to promise anything
	    about?

	    Verdict?
	    getdents:			( ) safe	( ) unsafe
	    getdirentries:		( ) safe	( ) unsafe

	[ ] gethostname(2) and similar

	    Verdict?
	    getdomainname:		( ) safe	( ) unsafe
	    gethostid:			( ) safe	( ) unsafe
	    gethostname:		( ) safe	( ) unsafe

	[ ] itimer functions -- since timer_gettime/settime are
	    async-signal-safe, presumably these should be too

	    Verdict?
	    getitimer:			( ) safe	( ) unsafe
	    setitimer:			( ) safe	( ) unsafe

	[ ] getpagesize -- to be replaced by sysconf(3) which is
	    supposed to be async-signal-safe (except PR lib/59225:
	    sysconf(3) is not async-signal-safe for some inputs,
	    https://gnats.NetBSD.org/59225)

	    Verdict?
	    getpagesize:		( ) safe	( ) unsafe

	[ ] uid/gid/sid queries?  getuid/setuid/getgid/setgid and the
	    euid/egid versions, as well as getpgrp and setpgrp and
	    getgroups, are already required by POSIX.

	    Verdict?
	    getpgid:			( ) safe	( ) unsafe
	    getsid:			( ) safe	( ) unsafe
	    issetugid:			( ) safe	( ) unsafe
	    setegid:			(*) safe	( ) unsafe
	    seteuid:			(*) safe	( ) unsafe
	    setgroups:			( ) safe	( ) unsafe
	    setregid:			( ) safe	( ) unsafe
	    setreuid:			( ) safe	( ) unsafe

	[ ] Scheduling priority?

	    Verdict?
	    getpriority:		( ) safe	( ) unsafe
	    setpriority:		( ) safe	( ) unsafe

	[ ] Entropy?  I'm inclined to say we shouldn't promise anything
	    about getrandom(2) because it was a mistake, but should
	    promise getentropy(3) is async-signal-safe.

	    Verdict?
	    getrandom:			( ) safe	( ) unsafe
	    getentropy:			( ) safe	( ) unsafe

	[ ] Resource limits and usage

	    getrlimit:			( ) safe	( ) unsafe
	    setrlimit:			( ) safe	( ) unsafe
	    getrusage:			( ) safe	( ) unsafe

	[ ] getsockopt2(2) is just an extension of getsockopt(2) which
	    POSIX requires safe.

	    getsockopt2:		( ) safe	( ) unsafe

	[ ] fh calls -- too internal to promise?

	    fhopen:			( ) safe	( ) unsafe
	    fhstat:			( ) safe	( ) unsafe
	    fhstatfs:			( ) safe	( ) unsafe
	    fhstatvfs1:			( ) safe	( ) unsafe
	    getfh:			( ) safe	( ) unsafe

	[ ] stat[v]fs/[v]fsstat

	    Verdict?
	    fstatfs:			( ) safe	( ) unsafe
	    fstatvfs1:			( ) safe	( ) unsafe
	    getfsstat:			( ) safe	( ) unsafe
	    getvfsstat:			( ) safe	( ) unsafe
	    statfs:			( ) safe	( ) unsafe
	    statvfs1:			( ) safe	( ) unsafe

	[ ] ioctl -- kinda has to be for various other things like
	    tcsetattr to work, no?

	    Verdict?
	    ioctl:			( ) safe	( ) unsafe

	[ ] kevent(2) -- surely this should be just as safe as
	    select(2) and poll(2), no?

	    Verdict?
	    kevent:			( ) safe	( ) unsafe

	[ ] killpg(2) -- should be just as safe as kill(2), no?

	    killpg:			( ) safe	( ) unsafe

	[ ] kqueue(2) -- should be just as safe as pipe(2), no?

	    Verdict?
	    kqueue:			( ) safe	( ) unsafe
	    kqueue1:			( ) safe	( ) unsafe

	[ ] ktrace?

	    Verdict?
	    fktrace:			( ) safe	( ) unsafe
	    ktrace:			( ) safe	( ) unsafe

	[ ] vfork -- yikes

	    Verdict?
	    vfork:			( ) safe	( ) unsafe

	[ ] *xattr functions (not to be confused with extattr_*
	    functions!)

	    Verdict?
	    fgetxattr:			( ) safe	( ) unsafe
	    flistxattr:			( ) safe	( ) unsafe
	    fremovexattr:		( ) safe	( ) unsafe
	    fsetxattr:			( ) safe	( ) unsafe
	    getxattr:			( ) safe	( ) unsafe
	    lgetxattr:			( ) safe	( ) unsafe
	    listxattr:			( ) safe	( ) unsafe
	    llistxattr:			( ) safe	( ) unsafe
	    lremovexattr:		( ) safe	( ) unsafe
	    lsetxattr:			( ) safe	( ) unsafe
	    removexattr:		( ) safe	( ) unsafe
	    setxattr:			( ) safe	( ) unsafe

	Others that didn't come up from reviewing the syscall list:

	[ ] pthread_mutex_unlock was added so that it can be safely
	    used in a pthread_atfork handler.

	    But this is essentially wrong: it would be reasonable for
	    an implementation to spin for a lock that another thread
	    holds for access to the queue; since the other thread can't
	    exist in the child, the only sensible thing to do is
	    pthread_mutex_init instead, and we've been doing that
	    throughout the tree.

	    On the other hand, we've been promising
	    pthread_mutex_unlock is async-signal-safe for a long time:
	    https://mail-index.netbsd.org/source-changes/2014/07/19/msg056519.html

	    Verdict?
	    pthread_mutex_unlock:	( ) safe	( ) unsafe
	    pthread_mutex_init:		( ) safe	( ) unsafe

	TBD -- feel free to edit the PR to organize these and put a
	preliminary assessment above (or delete if they're already done
	in a group above):

-.Xr lchflags 2 ,
-.Xr lchmod 2 ,
-.Xr lchown 2 ,
-.Xr lfs_bmapv 2 ,
-.Xr lfs_markv 2 ,
-.Xr lfs_segclean 2 ,
-.Xr lfs_segwait 2 ,
-.Xr lgetxattr 2 ,
-.Xr linkat 2 ,
-.Xr lio_listio 2 ,
-.Xr listxattr 2 ,
-.Xr llistxattr 2 ,
-.Xr lpathconf 2 ,
-.Xr lremovexattr 2 ,
-.Xr lutimes 2 ,
-.Xr madvise 2 ,
-.Xr memfd_create 2 ,
-.Xr mincore 2 ,
-.Xr minherit 2 ,
-.Xr mkdirat 2 ,
-.Xr mkfifoat 2 ,
-.Xr mknod 2 ,
-.Xr mknodat 2 ,
-.Xr mlock 2 ,
-.Xr mlockall 2 ,
-.Xr mmap 2 ,
-.Xr modctl 2 ,
-.Xr mount 2 ,
-.Xr mprotect 2 ,
-.Xr mq_close 2 ,
-.Xr mq_getattr 2 ,
-.Xr mq_notify 2 ,
-.Xr mq_open 2 ,
-.Xr mq_receive 2 ,
-.Xr mq_send 2 ,
-.Xr mq_setattr 2 ,
-.Xr mq_timedreceive 2 ,
-.Xr mq_timedsend 2 ,
-.Xr mq_unlink 2 ,
-.Xr mremap 2 ,
-.Xr msgctl 2 ,
-.Xr msgget 2 ,
-.Xr msgrcv 2 ,
-.Xr msgsnd 2 ,
-.Xr msgsys 2 ,
-.Xr msync 2 ,
-.Xr munlock 2 ,
-.Xr munlockall 2 ,
-.Xr munmap 2 ,
-.Xr nanosleep 2 ,
-.Xr nfssvc 2 ,
-.Xr ntp_adjtime 2 ,
-.Xr ntp_gettime 2 ,
-.Xr obreak 2 ,
-.Xr openat 2 ,
-.Xr ovadvise 2 ,
-.Xr paccept 2 ,
-.Xr pipe2 2 ,
-.Xr pollts 2 ,
-.Xr posix_fadvise 2 ,
-.Xr posix_fallocate 2 ,
-.Xr posix_spawn 2 ,
-.Xr pread 2 ,
-.Xr preadv 2 ,
-.Xr profil 2 ,
-.Xr pselect 2 ,
-.Xr pset_assign 2 ,
-.Xr pset_create 2 ,
-.Xr pset_destroy 2 ,
-.Xr ptrace 2 ,
-.Xr pwrite 2 ,
-.Xr pwritev 2 ,
-.Xr quota 2 ,
-.Xr quotactl 2 ,
-.Xr rasctl 2 ,
-.Xr readlinkat 2 ,
-.Xr readv 2 ,
-.Xr reboot 2 ,
-.Xr recvmmsg 2 ,
-.Xr removexattr 2 ,
-.Xr renameat 2 ,
-.Xr revoke 2 ,
-.Xr sa_enable 2 ,
-.Xr sa_preempt 2 ,
-.Xr sa_register 2 ,
-.Xr sa_setconcurrency 2 ,
-.Xr sa_stacks 2 ,
-.Xr sa_yield 2 ,
-.Xr sched_yield 2 ,
-.Xr semconfig 2 ,
-.Xr semget 2 ,
-.Xr semop 2 ,
-.Xr semsys 2 ,
-.Xr semtimedop 2 ,
-.Xr sendmmsg 2 ,
-.Xr setcontext 2 ,
-.Xr setdomainname 2 ,
-.Xr setegid 2 ,
-.Xr seteuid 2 ,
-.Xr setgroups 2 ,
-.Xr sethostid 2 ,
-.Xr sethostname 2 ,
-.Xr setitimer 2 ,
-.Xr setpriority 2 ,
-.Xr setregid 2 ,
-.Xr setreuid 2 ,
-.Xr setrlimit 2 ,
-.Xr settimeofday 2 ,
-.Xr setxattr 2 ,
-.Xr shmat 2 ,
-.Xr shmctl 2 ,
-.Xr shmdt 2 ,
-.Xr shmget 2 ,
-.Xr shmsys 2 ,
-.Xr sigaction 2 ,
-.Xr sigaltstack 2 ,
-.Xr sigblock 2 ,
-.Xr sigqueueinfo 2 ,
-.Xr sigreturn 2 ,
-.Xr sigsetmask 2 ,
-.Xr sigstack 2 ,
-.Xr sigvec 2 ,
-.Xr statfs 2 ,
-.Xr statvfs1 2 ,
-.Xr swapctl 2 ,
-.Xr swapon 2 ,
-.Xr symlinkat 2 ,
-.Xr sync 2 ,
-.Xr sysarch 2 ,
-.Xr syscall 2 ,
-.Xr timer_create 2 ,
-.Xr timer_delete 2 ,
-.Xr timerfd_create 2 ,
-.Xr timerfd_gettime 2 ,
-.Xr timerfd_settime 2 ,
-.Xr truncate 2 ,
-.Xr uname 2 ,
-.Xr undelete 2 ,
-.Xr unlinkat 2 ,
-.Xr unmount 2 ,
-.Xr utimensat 2 ,
-.Xr utimes 2 ,
-.Xr utrace 2 ,
-.Xr uuidgen 2 ,
-.Xr vfork 2 ,
-.Xr wait4 2 ,
-.Xr wait6 2 ,
-.Xr write 2 ,
-.Xr writev 2 ,

>How-To-Repeat:

	manual inspection

>Fix:

	Yes, please!

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.