Re: [PATCH] Replace vfork() with fork() to fix unshare crash on ppc64le

Ben Collins <[email protected]>
Newsgroups gmane.linux.debian.ports.powerpc,gmane.linux.busybox
Message-ID <2025090915-mellow-mink-e5ceec@boujee-and-buff>
On Tue, Sep 09, 2025 at 03:50:48PM -0500, tshah wrote:
> Hello,
> 
> This patch address the issue:
> https://lists.busybox.net/pipermail/busybox/2025-September/091718.html. The
> patch replaces the use of vfork() with fork() on MMU-enabled targets in the
> xvfork() macro.
> This change is necessary to resolve a segmentation fault observed on ppc64le
> when running: "unshare -mrpf sh".
> 
> According to POSIX, there is an udefined behaviour if the child process
> created by vfork() either modifies the data other than a variable of type
> pid_t or calls any other functions before successfully calling exec (3) or
> _exit(2) family functions.
> From the strace logs,it looks like the child after vfork performed syscalls
> like writing uid_map, gid_map, mounting, etc, which violates the minimal
> action requirements of vfork() resulting in a SIGSEGV maybe due to race
> conditions.

From my understanding of the problem, vfork() usage, even on non-MMU, is
broken because of the way busybox manipulates globals, affecting the
parent stack.

The fact that it crashes on ppc64le is likely just because of some
architectural differences that make it more likely to happen, but it's
still buggy the way busybox uses it, either way.

The fact the xvfork() is a macro leads me to believe someone (in 2004)
noticed this problem, and using the macro papered over it just enough to
"fix" it.

That being said, it seems everywhere else in busybox uses fork() on MMU
systems, so I guess it makes sense to do the same for xvfork().

-- 
 Ben Collins
 https://libjwt.io
 https://github.com/benmcollins
 --
 3EC9 7598 1672 961A 1139  173A 5D5A 57C7 242B 22CF
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEPsl1mBZylhoRORc6XVpXxyQrIs8FAmjAgoUACgkQXVpXxyQr
Is9gFw/+JsYgh/Mf+yKQwz/96Ti7xzsL4VyCFIn/drjxiF6smUcEz5D2/USEIRz2
xVw3iwl0DGVUmOsjpkkX3xbRc9FbqZb4eSY6WR4Fu+MS8sWDH1qeJD3t8escIB8s
xDqHaARPk4vWDEVAVs+QRyeTuRcbQiAYjIXMR1VFI4oxVaU5MX/gU9BfsaInbj89
AzjKtXzZDGLLtYO0byuqmTCLwoCO4PV2ebMFdvQo6bpegErRnSyXIKtnic3FMa6j
5a7yO/ZYnB/ltOBBcoR7O3LqrVkXqsog+fCO913U7JLGISylJhw9jKmdCL+HXQYv
t8J8fqUyBvZ7k2w9ll2G6Qvps2t+mdl7Q6nDPytxt0DXZtdpA4lu6363TMxyLjR9
NUckA2AGvavzIlJ4B0vUBthdvaohVxHMo6a4g/S4F00y3/7Ro6ajHaumjRFu+NNR
MgfO6YueGsym9GTSvQU+uJOPJUKH/lPzGGIf38fRzcsKjDJUeR4EL7ehZnsco579
wgK751daqDMHfZ2aOxlZZ8RhRoAa/kyY16BkWieMzTHC5pOX4KVXj9UMvzFGjBUM
zhIbaBv/RkT8kf/GC50MuyoTFNnHN2Smc5ZQVtesAyXz3NhrQZn15f0bHKxZXtqP
vONy06fQGsKyVH6J33ecC9EW/bfpi3svNQ5BisKsQvgqHYUi4Ds=
=4sbt
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.