1. 03 8月, 2013 1 次提交
  2. 18 7月, 2013 1 次提交
    • R
      make posix_spawn (and functions that use it) use CLONE_VFORK flag · b06dc666
      Rich Felker 提交于
      this is both a minor scheduling optimization and a workaround for a
      difficult-to-fix bug in qemu app-level emulation.
      
      from the scheduling standpoint, it makes no sense to schedule the
      parent thread again until the child has exec'd or exited, since the
      parent will immediately block again waiting for it.
      
      on the qemu side, as regular application code running on an underlying
      libc, qemu cannot make arbitrary clone syscalls itself without
      confusing the underlying implementation. instead, it breaks them down
      into either fork-like or pthread_create-like cases. it was treating
      the code in posix_spawn as pthread_create-like, due to CLONE_VM, which
      caused horribly wrong behavior: CLONE_FILES broke the synchronization
      mechanism, CLONE_SIGHAND broke the parent's signals, and CLONE_THREAD
      caused the child's exec to end the parent -- if it hadn't already
      crashed. however, qemu special-cases CLONE_VFORK and emulates that
      with fork, even when CLONE_VM is also specified. this also gives
      incorrect semantics for code that really needs the memory sharing, but
      posix_spawn does not make use of the vm sharing except to avoid
      momentary double commit charge.
      
      programs using posix_spawn (including via popen) should now work
      correctly under qemu app-level emulation.
      b06dc666
  3. 27 4月, 2013 1 次提交
    • R
      remove explicit locking to prevent __synccall setuid during posix_spawn · a0473a0c
      Rich Felker 提交于
      for the duration of the vm-sharing clone used by posix_spawn, all
      signals are blocked in the parent process, including
      implementation-internal signals. since __synccall cannot do anything
      until successfully signaling all threads, the fact that signals are
      blocked automatically yields the necessary safety.
      
      aside from debloating and general simplification, part of the
      motivation for removing the explicit lock is to simplify the
      synchronization logic of __synccall in hopes that it can be made
      async-signal-safe, which is needed to make setuid and setgid, which
      depend on __synccall, conform to the standard. whether this will be
      possible remains to be seen.
      a0473a0c
  4. 25 3月, 2013 1 次提交
  5. 18 2月, 2013 1 次提交
    • R
      consistently use the internal name __environ for environ · 23ccb80f
      Rich Felker 提交于
      patch by Jens Gustedt.
      previously, the intended policy was to use __environ in code that must
      conform to the ISO C namespace requirements, and environ elsewhere.
      this policy was not followed in practice anyway, making things
      confusing. on top of that, Jens reported that certain combinations of
      link-time optimization options were breaking with the inconsistent
      references; this seems to be a compiler or linker bug, but having it
      go away is a nice side effect of the changes made here.
      23ccb80f
  6. 04 2月, 2013 3 次提交
    • R
      base system() on posix_spawn · a8799356
      Rich Felker 提交于
      this avoids duplicating the fragile logic for executing an external
      program without fork.
      a8799356
    • R
      fix unsigned comparison bug in posix_spawn · 4862864f
      Rich Felker 提交于
      read should never return anything but 0 or sizeof ec here, but if it
      does, we want to treat any other return as "success". then the caller
      will get back the pid and is responsible for waiting on it when it
      immediately exits.
      4862864f
    • R
      overhaul posix_spawn to use CLONE_VM instead of vfork · fb6b159d
      Rich Felker 提交于
      the proposed change was described in detail in detail previously on
      the mailing list. in short, vfork is unsafe because:
      
      1. the compiler could make optimizations that cause the child to
      clobber the parent's local vars.
      
      2. strace is buggy and allows the vforking parent to run before the
      child execs when run under strace.
      
      the new design uses a close-on-exec pipe instead of vfork semantics to
      synchronize the parent and child so that the parent does not return
      before the child has finished using its arguments (and now, also its
      stack). this also allows reporting exec failures to the caller instead
      of giving the caller a child that mysteriously exits with status 127
      on exec error.
      
      basic testing has been performed on both the success and failure code
      paths. further testing should be done.
      fb6b159d
  7. 02 2月, 2013 1 次提交
  8. 12 11月, 2012 1 次提交
    • R
      add support for thread scheduling (POSIX TPS option) · 1e21e78b
      Rich Felker 提交于
      linux's sched_* syscalls actually implement the TPS (thread
      scheduling) functionality, not the PS (process scheduling)
      functionality which the sched_* functions are supposed to have.
      omitting support for the PS option (and having the sched_* interfaces
      fail with ENOSYS rather than omitting them, since some broken software
      assumes they exist) seems to be the only conforming way to do this on
      linux.
      1e21e78b
  9. 09 11月, 2012 1 次提交
    • R
      clean up sloppy nested inclusion from pthread_impl.h · efd4d87a
      Rich Felker 提交于
      this mirrors the stdio_impl.h cleanup. one header which is not
      strictly needed, errno.h, is left in pthread_impl.h, because since
      pthread functions return their error codes rather than using errno,
      nearly every single pthread function needs the errno constants.
      
      in a few places, rather than bringing in string.h to use memset, the
      memset was replaced by direct assignment. this seems to generate much
      better code anyway, and makes many functions which were previously
      non-leaf functions into leaf functions (possibly eliminating a great
      deal of bloat on some platforms where non-leaf functions require ugly
      prologue and/or epilogue).
      efd4d87a
  10. 29 10月, 2012 1 次提交
    • R
      system is a cancellation point · 76f28cfc
      Rich Felker 提交于
      ideally, system would also be cancellable while running the external
      command, but I cannot find any way to make that work without either
      leaking zombie processes or introducing behavior that is far outside
      what the standard specifies. glibc handles cancellation by killing the
      child process with SIGKILL, but this could be unsafe in that it could
      leave the data being manipulated by the command in an inconsistent
      state.
      76f28cfc
  11. 20 10月, 2012 1 次提交
    • R
      fix usage of locks with vfork · 599f9736
      Rich Felker 提交于
      __release_ptc() is only valid in the parent; if it's performed in the
      child, the lock will be unlocked early then double-unlocked later,
      corrupting the lock state.
      599f9736
  12. 19 10月, 2012 2 次提交
    • R
      fix parent-memory-clobber in posix_spawn (environ) · 97c8bdd8
      Rich Felker 提交于
      97c8bdd8
    • R
      overhaul system() and popen() to use vfork; fix various related bugs · 44eb4d8b
      Rich Felker 提交于
      since we target systems without overcommit, special care should be
      taken that system() and popen(), like posix_spawn(), do not fail in
      processes whose commit charges are too high to allow ordinary forking.
      
      this in turn requires special precautions to ensure that the parent
      process's signal handlers do not end up running in the shared-memory
      child, where they could corrupt the state of the parent process.
      
      popen has also been updated to use pipe2, so it does not have a
      fd-leak race in multi-threaded programs. since pipe2 is missing on
      older kernels, (non-atomic) emulation has been added.
      
      some silly bugs in the old code should be gone too.
      44eb4d8b
  13. 15 10月, 2012 1 次提交
    • R
      block uid/gid changes during posix_spawn · d5304147
      Rich Felker 提交于
      usage of vfork creates a situation where a process of lower privilege
      may momentarily have write access to the memory of a process of higher
      privilege.
      
      consider the case of a multi-threaded suid program which is calling
      posix_spawn in one thread while another thread drops the elevated
      privileges then runs untrusted (relative to the elevated privilege)
      code as the original invoking user. this untrusted code can then
      potentially modify the data the child process will use before calling
      exec, for example changing the pathname or arguments that will be
      passed to exec.
      
      note that if vfork is implemented as fork, the lock will not be held
      until the child execs, but since memory is not shared it does not
      matter.
      d5304147
  14. 15 9月, 2012 1 次提交
    • R
      use vfork if possible in posix_spawn · d62f4e98
      Rich Felker 提交于
      vfork is implemented as the fork syscall (with no atfork handlers run)
      on archs where it is not available, so this change does not introduce
      any change in behavior or regression for such archs.
      d62f4e98
  15. 07 9月, 2012 1 次提交
    • R
      use restrict everywhere it's required by c99 and/or posix 2008 · 400c5e5c
      Rich Felker 提交于
      to deal with the fact that the public headers may be used with pre-c99
      compilers, __restrict is used in place of restrict, and defined
      appropriately for any supported compiler. we also avoid the form
      [restrict] since older versions of gcc rejected it due to a bug in the
      original c99 standard, and instead use the form *restrict.
      400c5e5c
  16. 07 2月, 2012 1 次提交
  17. 15 10月, 2011 2 次提交
  18. 29 9月, 2011 1 次提交
  19. 14 9月, 2011 2 次提交
  20. 07 8月, 2011 1 次提交
  21. 17 7月, 2011 1 次提交
  22. 30 5月, 2011 1 次提交
  23. 29 5月, 2011 4 次提交
  24. 28 4月, 2011 1 次提交
  25. 21 4月, 2011 1 次提交
    • R
      fix minor bugs due to incorrect threaded-predicate semantics · 870cc679
      Rich Felker 提交于
      some functions that should have been testing whether pthread_self()
      had been called and initialized the thread pointer were instead
      testing whether pthread_create() had been called and actually made the
      program "threaded". while it's unlikely any mismatch would occur in
      real-world problems, this could have introduced subtle bugs. now, we
      store the address of the main thread's thread descriptor in the libc
      structure and use its presence as a flag that the thread register is
      initialized. note that after fork, the calling thread (not necessarily
      the original main thread) is the new main thread.
      870cc679
  26. 18 4月, 2011 1 次提交
  27. 17 4月, 2011 1 次提交
    • R
      overhaul pthread cancellation · feee9890
      Rich Felker 提交于
      this patch improves the correctness, simplicity, and size of
      cancellation-related code. modulo any small errors, it should now be
      completely conformant, safe, and resource-leak free.
      
      the notion of entering and exiting cancellation-point context has been
      completely eliminated and replaced with alternative syscall assembly
      code for cancellable syscalls. the assembly is responsible for setting
      up execution context information (stack pointer and address of the
      syscall instruction) which the cancellation signal handler can use to
      determine whether the interrupted code was in a cancellable state.
      
      these changes eliminate race conditions in the previous generation of
      cancellation handling code (whereby a cancellation request received
      just prior to the syscall would not be processed, leaving the syscall
      to block, potentially indefinitely), and remedy an issue where
      non-cancellable syscalls made from signal handlers became cancellable
      if the signal handler interrupted a cancellation point.
      
      x86_64 asm is untested and may need a second try to get it right.
      feee9890
  28. 13 4月, 2011 1 次提交
    • R
      speed up threaded fork · e2915eee
      Rich Felker 提交于
      after fork, we have a new process and the pid is equal to the tid of
      the new main thread. there is no need to make two separate syscalls to
      obtain the same number.
      e2915eee
  29. 25 3月, 2011 1 次提交
    • R
      overhaul cancellation to fix resource leaks and dangerous behavior with signals · b470030f
      Rich Felker 提交于
      this commit addresses two issues:
      
      1. a race condition, whereby a cancellation request occurring after a
      syscall returned from kernelspace but before the subsequent
      CANCELPT_END would cause cancellable resource-allocating syscalls
      (like open) to leak resources.
      
      2. signal handlers invoked while the thread was blocked at a
      cancellation point behaved as if asynchronous cancellation mode wer in
      effect, resulting in potentially dangerous state corruption if a
      cancellation request occurs.
      
      the glibc/nptl implementation of threads shares both of these issues.
      
      with this commit, both are fixed. however, cancellation points
      encountered in a signal handler will not be acted upon if the signal
      was received while the thread was already at a cancellation point.
      they will of course be acted upon after the signal handler returns, so
      in real-world usage where signal handlers quickly return, it should
      not be a problem. it's possible to solve this problem too by having
      sigaction() wrap all signal handlers with a function that uses a
      pthread_cleanup handler to catch cancellation, patch up the saved
      context, and return into the cancellable function that will catch and
      act upon the cancellation. however that would be a lot of complexity
      for minimal if any benefit...
      b470030f
  30. 20 3月, 2011 1 次提交
  31. 10 3月, 2011 1 次提交
  32. 27 2月, 2011 1 次提交