public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/29109] New: posix_spawn() always returns 1 (EPERM) on clone() failure
@ 2022-05-01 14:52 izbyshev at ispras dot ru
  2022-05-01 14:53 ` [Bug libc/29109] " izbyshev at ispras dot ru
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: izbyshev at ispras dot ru @ 2022-05-01 14:52 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 29109
           Summary: posix_spawn() always returns 1 (EPERM) on clone()
                    failure
           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: ---

The reproducer below uses time namespaces to easily trigger clone() failure
(requires Linux >= 5.6).

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

#include <stdio.h>
#include <string.h>
#include <spawn.h>

int main(int argc, char *argv[], char *envp[]) {
  if (argc <= 1)
    return 1;
  int err = posix_spawn(0, argv[1], 0, 0, argv + 1, envp);
  if (err) {
    printf("posix_spawn: %d (%s)\n", err, strerror(err));
    return 127;
  }
  return 0;
}

$ gcc test.c
$ strace -e clone,clone3 unshare -UrT ./a.out /bin/true
clone3({flags=CLONE_VM|CLONE_VFORK, exit_signal=SIGCHLD, stack=0x7f322965f000,
stack_size=0x9000}, 88) = -1 EINVAL (Invalid argument)
posix_spawn: 1 (Operation not permitted)
+++ exited with 127 +++

The bug is that while __clone_internal() reports errors via errno, __spawnix()
treats it as a raw syscall[1], simply negating its return value (which is
always -1 on error).

[1]
https://sourceware.org/git?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/spawni.c;h=d703485e3fb898dc65986d3e1cd9c1e7b8593abe;hb=glibc-2.35#l412

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

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

end of thread, other threads:[~2022-05-06 14:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-01 14:52 [Bug libc/29109] New: posix_spawn() always returns 1 (EPERM) on clone() failure izbyshev at ispras dot ru
2022-05-01 14:53 ` [Bug libc/29109] " izbyshev at ispras dot ru
2022-05-01 23:30 ` adhemerval.zanella at linaro dot org
2022-05-02 13:21 ` fweimer at redhat dot com
2022-05-02 13:30 ` adhemerval.zanella at linaro dot org
2022-05-02 13:39 ` izbyshev at ispras dot ru
2022-05-02 13:46 ` adhemerval.zanella at linaro dot org
2022-05-06 14:09 ` adhemerval.zanella at linaro dot org
2022-05-06 14:34 ` cvs-commit at gcc dot gnu.org

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).