public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "izbyshev at ispras dot ru" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/29115] New: vfork()-based posix_spawn() has more failure modes than fork()-based one
Date: Mon, 02 May 2022 12:08:51 +0000	[thread overview]
Message-ID: <bug-29115-131@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2022-05-02 12:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02 12:08 izbyshev at ispras dot ru [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-29115-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).