On Sun, Sep 7, 2025 at 11:20 AM Ricardo Branco <[email protected]> wrote:
>
> To reproduce:
>
> $ unshare -mrpf sh
> sh-5.3# Segmentation fault (core dumped)

Works for me.

> It seems related to vfork(), which is called in lots of places.

vfork is VERY efficient. I had cases where programs were sped up 50x
by switching from fork+exec to vfork+exec.

But you do need to know exactly what you are doing when you use it.
You need to understand what is shared and what is not shared
between processes after vfork, and when exactly parent is unblocked.
(For example, with double vfork, you can inadvertently create two
concurrently running processes in one VM!)

> This simple program dumps core on ppc64le:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/wait.h>
> int main(int argc, char *argv[])
> {
>      int child = vfork();
>      printf("Child: %d\n", child);
>
>      if (child) {
>          sleep(1);
>          int ret = waitpid(child,0, 0);
>      }
>      return EXIT_SUCCESS;
> }

Because this program is buggy. It is running libc cleanup code twice.
You must _not_ do that:
...
     if (child == 0) // we are child
         _exit(EXIT_SUCCESS);  //exit immediately, without any cleanup

     // we are parent
     waitpid(child, NULL, 0);
     return EXIT_SUCCESS;
}
_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to