From nobody Tue Jun 16 22:23:15 2026 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gg1hz1yVgz6hv6Z for ; Tue, 16 Jun 2026 22:23:15 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gg1hy6R3Cz3x5k for ; Tue, 16 Jun 2026 22:23:14 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1781648594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FjqpYxcb2ls+7A8cSa+PkQcykpFL9Khw3p68w1YE+Ck=; b=AtMnCF2kwJO/12jA13S5EfW3gVCA1W241dapiczm/2y47srcO+quhTh86NOTe4fVCNEzcI DurFWNoslP5I7d/QN9Kb36U7Zffkbm/4SJ1e9Wj6Pl9a2HFTN5hyZR7gJa9MhvaqeIvY+L b09nDGl22AjN+2x+At1GNIAJEhwl6PDade6dRbu+VXDlipPVofqKkI7iGxDLrP4xCFBe9i hgKcf6qQ3QnQgBJK+f+FDa/od3QhFYb7JlTevRiOX1/nqebHkNnIumt1PMa9nmDOmVHrwB cu3shBglBUDdJk2PJNNapXYf/P0d2DRLlDWqtPiS2pFpi/QoZTPKDl6pyBvirw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1781648594; a=rsa-sha256; cv=none; b=nSQTTmQ0LIs03G/VEpOQ3oAXAVWDdpPwFz5Odfpf6k1xG6WhjpbeN8gs/CDzDumMxO7pDY fjCWYEf/JZsS/rrvrjBLegP64zc40l8feZ2s0GoYEOfZIisBPhW+11b1WdONAoF/sSiv+J 75W2aLrSFmGUQXGxj0gHji/ArwNQhSekc4GXYWrrwSX37RWFXxVjxVYL9oZH99v70AEhaR P6x1Q4tkVJJ6evIvpNx2mdCOEsQ6j+X+EkufPmqPyeFx5vVjfJAUQYU9WkIJUkRd2teie3 Y6eRQmC94su7GIPoQY64MLVy88xyj3FpFU+arMgCBjWlykMKkDCYySJsdiV0hA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1781648594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FjqpYxcb2ls+7A8cSa+PkQcykpFL9Khw3p68w1YE+Ck=; b=tuVBFpH92FYM43zdkbDkVi8giqmSyee5PAIF+Imjuyb90uH/s+OM05rN4ksu9a+aQ4zVQQ XXw3mICsgYryPLGxoalqgBMQEbRncqK0zT84D+K3uIjvBxcBXj1Ug77X3nkZ4eCq4eCZWR dm7tgzUT6B67RO4+7vvbingZClTjJvmG0N2aZHoIaHsRHilZfYT0bD+15GzluJlo36skJe OlKVmGDeJwnfSIkX4DjEA8InOtUVVw/xLD0OmakxWcMUdY/+UQZgzXfvu0DSImutybHsiY Xrpf+QCxCeH78H++tOUlCYJJp/+DpHbk/VSlL8wiViyAu1pkthWQEANgGXas9g== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4gg1hy5kXfzlcq for ; Tue, 16 Jun 2026 22:23:14 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 65GMNEkE082941 for ; Tue, 16 Jun 2026 22:23:14 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 65GMNEsA082940 for bugs@FreeBSD.org; Tue, 16 Jun 2026 22:23:14 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 295991] lib/libc posix_spawnp(): PATH-search child runs on an undersized rfork_thread stack and underflows into the caller's heap (heavily-linked processes; PHP proc_open) Date: Tue, 16 Jun 2026 22:23:15 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 15.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: bdrewery@FreeBSD.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D295991 Bryan Drewery changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bdrewery@FreeBSD.org --- Comment #2 from Bryan Drewery --- The report is an unreadable AI mess but the point is that there is some ran= dom corruption that shows up with php on exit when loaded with many extensions. Raising the stack size in posix_spawn avoids the problem. This shows up easily with www/nextcloud port running `occ status` in a loop. The proc_open repro isn't reliable as it depends on some random mechanism a= nd how many extensions are loaded. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D289425 and https://github.com/php/php-src/issues/21995 have more details. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D289425#c22 shows some w= ays it manifests at shutdown. The revert of the xsl shutdown function was a hack that attempted to avoid = the root cause but does not. Based on the initial report this AI-generated code avoids the problem by us= ing a 1MB stack size. ``` /* cc -O2 -fPIC -shared -Wall -o /usr/local/libexec/spawnstack.so spawnstac= k.c */ #include #include #include #include #include typedef pid_t (*rfork_thread_t)(int, void *, int (*)(void *), void *); #if __FreeBSD_version >=3D 1600000 typedef pid_t (*pdrfork_thread_t)(int *, int, int, void *, int (*)(void *), void *); #endif static rfork_thread_t sys_rfork_thread; #if __FreeBSD_version >=3D 1600000 static pdrfork_thread_t sys_pdrfork_thread; #endif static size_t guard; static size_t depth; __attribute__((constructor)) static void spawnstack_init(void) { const char *s; char *end; long ps; unsigned long kb; sys_rfork_thread =3D (rfork_thread_t)dlsym(RTLD_NEXT, "rfork_thread= "); #if __FreeBSD_version >=3D 1600000 sys_pdrfork_thread =3D (pdrfork_thread_t)dlsym(RTLD_NEXT, "pdrfork_thread"); #endif ps =3D sysconf(_SC_PAGESIZE); guard =3D ps > 0 ? (size_t)ps : 4096; kb =3D 1024; s =3D getenv("LIBC_SPAWN_STACK_KB"); if (s !=3D NULL && *s !=3D '\0') { unsigned long v =3D strtoul(s, &end, 10); if (*end =3D=3D '\0' && v >=3D 64) kb =3D v; } depth =3D (kb * 1024 + guard - 1) & ~(guard - 1); } static void * spawnstack_alloc(size_t *len) { char *p; *len =3D guard + depth; p =3D mmap(NULL, *len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); if (p =3D=3D MAP_FAILED) return (NULL); (void)mprotect(p, guard, PROT_NONE); return (p + *len); } pid_t rfork_thread(int flags, void *stack, int (*func)(void *), void *arg) { void *top; size_t len; pid_t pid; if ((flags & RFSPAWN) =3D=3D 0 || stack =3D=3D NULL) return (sys_rfork_thread(flags, stack, func, arg)); top =3D spawnstack_alloc(&len); if (top =3D=3D NULL) return (sys_rfork_thread(flags, stack, func, arg)); pid =3D sys_rfork_thread(flags, top, func, arg); (void)munmap((char *)top - len, len); return (pid); } #if __FreeBSD_version >=3D 1600000 pid_t pdrfork_thread(int *fdp, int pdflags, int rfflags, void *stack, int (*func)(void *), void *arg) { void *top; size_t len; pid_t pid; if ((rfflags & RFSPAWN) =3D=3D 0 || stack =3D=3D NULL) return (sys_pdrfork_thread(fdp, pdflags, rfflags, stack, func, arg)); top =3D spawnstack_alloc(&len); if (top =3D=3D NULL) return (sys_pdrfork_thread(fdp, pdflags, rfflags, stack, func, arg)); pid =3D sys_pdrfork_thread(fdp, pdflags, rfflags, top, func, arg); (void)munmap((char *)top - len, len); return (pid); } #endif ``` /usr/local/bin/occ needs LD_PRELOAD added in. ``` #!/bin/sh args=3D for arg in "$@" ; do if [ "${arg#* }" !=3D "${arg}" ] ; then args=3D"${args} '${arg}'" else args=3D"${args} ${arg}" fi done ( cd /home/nextcloud/public_html/nextcloud su -m www -c \ "/usr/bin/env LD_PRELOAD=3D/usr/local/libexec/spawnstack.so /usr/local/bin/php --define apc.enable_cli=3D1 /home/nextcloud/public_html/nextcloud/occ ${args}" ) ``` --=20 You are receiving this mail because: You are the assignee for the bug.=