NetBSD Problem Report #59112

From martin@duskware.de  Fri Feb 28 10:27:26 2025
Return-Path: <martin@duskware.de>
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 4D7A71A923A
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 28 Feb 2025 10:27:26 +0000 (UTC)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: libpthread constructors use malloc
X-Send-Pr-Version: 3.95

>Number:         59112
>Category:       lib
>Synopsis:       libpthread constructors use malloc
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    riastradh
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 28 10:30:00 +0000 2025
>Closed-Date:    
>Last-Modified:  Sat Oct 04 16:21:50 +0000 2025
>Originator:     Martin Husemann
>Release:        NetBSD 10.99.12
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD unpluged.duskware.de 10.99.12 NetBSD 10.99.12 (UNPLUGED) #627: Mon Feb 24 11:21:12 CET 2025 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/evbarm/compile/UNPLUGED evbarm
Architecture: earmv5
Machine: evbarm
>Description:

Side note: I guess this is "the" remaining issue with HAVE_JEMALLOC=530
on arm and mips.

Everything that uses libpthread seems to be broken on armv5 with new
jemalloc.

[/tmp] martin@unpluged > gdb gunzip
GNU gdb (GDB) 15.1
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "armv7--netbsdelf-eabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from gunzip...
Reading symbols from /usr/libdata/debug//usr/bin/gzip.debug...
(gdb) break malloc
Breakpoint 1 at 0x1580
(gdb) run
Starting program: /usr/bin/gunzip 

Breakpoint 1, malloc (size=size@entry=8) at /work/src/external/bsd/jemalloc/lib/../dist/src/jemalloc.c:2773
warning: 2773   /work/src/external/bsd/jemalloc/lib/../dist/src/jemalloc.c: No such file or directory
(gdb) bt
#0  malloc (size=size@entry=8) at /work/src/external/bsd/jemalloc/lib/../dist/src/jemalloc.c:2773
#1  0xbbe0e224 in af_alloc () at /work/src/lib/libc/gen/pthread_atfork.c:85
#2  af_alloc () at /work/src/lib/libc/gen/pthread_atfork.c:79
#3  _pthread_atfork (prepare=0xbbc7a5c0 <pthread_tsd_prefork>, parent=0xbbc7a5b0 <pthread_tsd_postfork>, 
    child=0xbbc7a59c <pthread_tsd_postfork_child>) at /work/src/lib/libc/gen/pthread_atfork.c:120
#4  0xbbc7a5f8 in pthread_tsd_init (tlen=tlen@entry=0xbbc85c20 <__pthread_st_size>) at /work/src/lib/libpthread/pthread_tsd.c:92
#5  0xbbc808a8 in pthread__init () at /work/src/lib/libpthread/pthread.c:214
#6  0xbbe22268 in _libc_init () at /work/src/lib/libc/misc/initfini.c:127
#7  0xbbef2d34 in _rtld_call_initfini_function (mask=<optimized out>, func=0xbbe221fc <_libc_init>)
    at /work/src/libexec/ld.elf_so/rtld.c:152
#8  _rtld_call_init_function (cur_objgen=<optimized out>, mask=<optimized out>, obj=<optimized out>)
    at /work/src/libexec/ld.elf_so/rtld.c:267
#9  _rtld_call_init_function (obj=0xbbe92000, mask=0xbfffe810, cur_objgen=1) at /work/src/libexec/ld.elf_so/rtld.c:241
#10 0xbbef3040 in _rtld_call_init_functions (mask=mask@entry=0xbfffe810) at /work/src/libexec/ld.elf_so/rtld.c:325
#11 0xbbef3b48 in _rtld (sp=<optimized out>, relocbase=<optimized out>) at /work/src/libexec/ld.elf_so/rtld.c:802


>How-To-Repeat:
s/a

>Fix:
n/a

>Release-Note:

>Audit-Trail:
From: Christos Zoulas <christos@zoulas.com>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org,
 gnats-admin@netbsd.org,
 netbsd-bugs@netbsd.org
Subject: Re: lib/59112: libpthread constructors use malloc
Date: Fri, 28 Feb 2025 09:36:55 -0500

 --Apple-Mail=_A6571092-968E-4D31-AE8F-73EC3AFD8DA3
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain;
 	charset=us-ascii

 Does https://www.astron.com/~christos/NetBSD/pthread_atfork.c.diff fix it?

 christos

 --Apple-Mail=_A6571092-968E-4D31-AE8F-73EC3AFD8DA3
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename=signature.asc
 Content-Type: application/pgp-signature;
 	name=signature.asc
 Content-Description: Message signed with OpenPGP

 -----BEGIN PGP SIGNATURE-----
 Comment: GPGTools - http://gpgtools.org

 iF0EARECAB0WIQS+BJlbqPkO0MDBdsRxESqxbLM7OgUCZ8HKBwAKCRBxESqxbLM7
 OqjuAKCxzkwRKbYfqJRcnN8f12yb+kkp5QCgkAz0zbZyFyqqIJptD7M3lZPuMms=
 =qNia
 -----END PGP SIGNATURE-----

 --Apple-Mail=_A6571092-968E-4D31-AE8F-73EC3AFD8DA3--

From: Martin Husemann <martin@duskware.de>
To: Christos Zoulas <christos@zoulas.com>
Cc: gnats-bugs@netbsd.org
Subject: Re: lib/59112: libpthread constructors use malloc
Date: Fri, 28 Feb 2025 16:58:42 +0100

 On Fri, Feb 28, 2025 at 09:36:55AM -0500, Christos Zoulas wrote:
 > Does https://www.astron.com/~christos/NetBSD/pthread_atfork.c.diff fix it?

 Yes, this works!

 Martin

From: Christos Zoulas <christos@zoulas.com>
To: Martin Husemann <martin@duskware.de>
Cc: gnats-bugs@netbsd.org
Subject: Re: lib/59112: libpthread constructors use malloc
Date: Fri, 28 Feb 2025 10:59:25 -0500

 --Apple-Mail=_EDFAE4D6-3230-4FAD-A5F2-6FEF153CF1BB
 Content-Transfer-Encoding: quoted-printable
 Content-Type: text/plain;
 	charset=us-ascii

 I still think we should fix the stack alignment though. I think that is =
 the reason malloc stopped working..

 christos


 --Apple-Mail=_EDFAE4D6-3230-4FAD-A5F2-6FEF153CF1BB
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename=signature.asc
 Content-Type: application/pgp-signature;
 	name=signature.asc
 Content-Description: Message signed with OpenPGP

 -----BEGIN PGP SIGNATURE-----
 Comment: GPGTools - http://gpgtools.org

 iF0EARECAB0WIQS+BJlbqPkO0MDBdsRxESqxbLM7OgUCZ8HdXQAKCRBxESqxbLM7
 OhU3AKCl/R9XGyp9MrxyotQw7+mbflAxbwCcC96zKkLVeLirl+mPjyzcq4STmSU=
 =87qs
 -----END PGP SIGNATURE-----

 --Apple-Mail=_EDFAE4D6-3230-4FAD-A5F2-6FEF153CF1BB--

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59112 CVS commit: src/lib/libc/gen
Date: Fri, 28 Feb 2025 11:00:27 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Fri Feb 28 16:00:27 UTC 2025

 Modified Files:
 	src/lib/libc/gen: pthread_atfork.c

 Log Message:
 PR/59112: Martin Husemann: switch to using mmap instead of malloc


 To generate a diff of this commit:
 cvs rdiff -u -r1.18 -r1.19 src/lib/libc/gen/pthread_atfork.c

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

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/59112: libpthread constructors use malloc
Date: Fri, 28 Feb 2025 17:04:09 +0100

 On Fri, Feb 28, 2025 at 04:00:07PM +0000, Christos Zoulas via gnats wrote:
 >  I still think we should fix the stack alignment though. I think that is
 >  the reason malloc stopped working..

 There is no misaligned stack pointer any more (but I don't completely 
 understand what happened when jemalloc was used before its constructor
 ran and how that would cause the misalignment).

 Martin

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59112 CVS commit: src/lib/libc/gen
Date: Sun, 2 Mar 2025 22:46:24 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sun Mar  2 22:46:24 UTC 2025

 Modified Files:
 	src/lib/libc/gen: arc4random.c pthread_atfork.c

 Log Message:
 libc: New __libc_atfork.

 This uses caller-provided storage for the callback queues.

 Use it in arc4random(3) in order to avoid possible failure modes.

 This is a private symbol, not designed for use outside NetBSD, and
 the API is not intended to be stable (yet) -- I just took the
 existing purely internal structure (struct atfork_callback) and
 reused it for this API without changing any of the calling-side
 logic.  We could change it, e.g. to use a single structure per call,
 to make the API a little less unwieldy, at the cost of
 microscopically more storage and runtime for the users that don't use
 all three callbacks; to be considered in a future change.

 We might reasonably use __libc_atfork in libpthread for use in the
 pthread_tsd_init constructor, in order to be confident it never
 attempts malloc(3), but let's do that in a separate commit just in
 case anything goes awry with that plan.

 PR lib/59112: libpthread constructors use malloc
 PR lib/59117: arc4random has some failure modes it shouldn't


 To generate a diff of this commit:
 cvs rdiff -u -r1.39 -r1.40 src/lib/libc/gen/arc4random.c
 cvs rdiff -u -r1.23 -r1.24 src/lib/libc/gen/pthread_atfork.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/59112 CVS commit: src/lib/libc/include
Date: Mon, 3 Mar 2025 00:57:22 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Mar  3 00:57:21 UTC 2025

 Added Files:
 	src/lib/libc/include: atfork.h

 Log Message:
 __libc_atfork: Add header file missed in previous commit.

 PR lib/59112: libpthread constructors use malloc
 PR lib/59117: arc4random has some failure modes it shouldn't


 To generate a diff of this commit:
 cvs rdiff -u -r0 -r1.1 src/lib/libc/include/atfork.h

 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: martin@NetBSD.org
Responsible-Changed-When: Sat, 04 Oct 2025 16:21:50 +0000
Responsible-Changed-Why:
I was tempted to close the PR as it all works fine for me now,
but I thought you might want to consider pullups?


State-Changed-From-To: open->needs-pullups
State-Changed-By: martin@NetBSD.org
State-Changed-When: Sat, 04 Oct 2025 16:21:50 +0000
State-Changed-Why:
works for me


>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.