public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/29115] New: vfork()-based posix_spawn() has more failure modes than fork()-based one
@ 2022-05-02 12:08 izbyshev at ispras dot ru
  2022-05-02 12:09 ` [Bug libc/29115] " izbyshev at ispras dot ru
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: izbyshev at ispras dot ru @ 2022-05-02 12:08 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29115

            Bug ID: 29115
           Summary: vfork()-based posix_spawn() has more failure modes
                    than fork()-based one
           Product: glibc
           Version: 2.35
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: izbyshev at ispras dot ru
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Modern vfork()-based posix_spawn() can be used as an efficient alternative to
fork()/exec() to avoid performance and overcommit issues. A common expectation
is that whenever posix_spawn() feature set is sufficient for application needs
of tweaking the child attributes, it can be used instead of fork()/exec().

However, it turns out that vfork() can have failure modes than fork() doesn't
have. One such case is due to Linux not allowing processes in different time
namespaces to share address space.

$ cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <spawn.h>
#include <unistd.h>

int main(int argc, char *argv[], char *envp[]) {
  if (getenv("TEST_FORK")) {
    pid_t pid = fork();
    if (pid < 0) {
        perror("fork");
        return 127;
    }
    if (pid == 0) {
        execve(argv[1], argv + 1, envp);
        perror("execve");
        return 127;
    }
  } else {
      int err = posix_spawn(0, argv[1], 0, 0, argv + 1, envp);
      if (err) {
        printf("posix_spawn: %s\n", strerror(err));
        return 127;
      }
  }
  printf("OK\n");
  return 0;
}

$ gcc test.c

$ unshare -UrT ./a.out /bin/true
posix_spawn: Operation not permitted

(The actual clone() error is EINVAL, but it's reported incorrectly due to bug
29109).

$ TEST_FORK=1 unshare -UrT ./a.out /bin/true
OK

I'm not aware of other failure modes, but more might appear in the future.

Does this qualify as a glibc bug? Should glibc's posix_spawn() implementation,
for example, retry with fork() on vfork() failure (which would require a
redesign of error reporting from the child process because it currently relies
on address space sharing)?

Or do applications are expected to deal with that somehow? In this case, what
is the recommended way to do that, given that it's not possible to reliably
detect "retriable" posix_spawn() failures?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-08-08 15:37 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-02 12:08 [Bug libc/29115] New: vfork()-based posix_spawn() has more failure modes than fork()-based one izbyshev at ispras dot ru
2022-05-02 12:09 ` [Bug libc/29115] " izbyshev at ispras dot ru
2022-05-02 16:17 ` adhemerval.zanella at linaro dot org
2022-05-02 16:26 ` adhemerval.zanella at linaro dot org
2022-05-02 16:55 ` izbyshev at ispras dot ru
2022-05-02 17:17 ` adhemerval.zanella at linaro dot org
2022-05-02 18:04 ` adhemerval.zanella at linaro dot org
2022-05-02 20:38 ` carlos at redhat dot com
2022-05-02 20:43 ` fweimer at redhat dot com
2022-05-02 20:56 ` izbyshev at ispras dot ru
2022-05-02 21:02 ` carlos at redhat dot com
2022-05-02 21:06 ` fweimer at redhat dot com
2022-05-02 21:15 ` carlos at redhat dot com
2022-05-02 21:24 ` carlos at redhat dot com
2022-05-02 21:51 ` adhemerval.zanella at linaro dot org
2022-08-08 14:08 ` adhemerval.zanella at linaro dot org
2022-08-08 14:13 ` fweimer at redhat dot com
2022-08-08 14:15 ` fweimer at redhat dot com
2022-08-08 15:37 ` izbyshev at ispras dot ru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).