mbox series

[v2,00/13] getenv/environ thread safety

Message ID cover.1722193092.git.fweimer@redhat.com
Headers show
Series getenv/environ thread safety | expand

Message

Florian Weimer July 28, 2024, 7:02 p.m. UTC
This patch series implements thread-safe getenv, and environment
snapshotting for the execve and posix_spawn function families.

The execve snapshotting is not ideal because it requires stack
allocation.  I have a more complicated version that uses an mmap
fallback for large allocations and avoids the vfork memory leak.
But I hope we won't need it.

Some of the concurrency tests have run for many hours on AArch64 and
POWER systems.  The series has also been built with
build-many-glibcs.py.

Thanks,
Florian

Florian Weimer (13):
  stdlib: Make getenv thread-safe in more cases
  Linux: Assume __NR_execveat is defined in fexecve
  Linux: Introduce __do_fexecve in fexecve
  Linux: Error handling fixes for fexecve
  posix: Consolidate execve family of functions
  posix: Introduce the __arch_spawni function
  stdlib: Add internal __getenvarray function
  support: Add support_count_maps
  posix: New tst-vfork-mappings test case
  posix: Improve thread safety of functions using environ with execveat
  posix: Implement environ snapshotting in __spawni
  posix: Acquire the environment lock during fork
  manual: Updates for thread-safe getenv

 NEWS                                          |   5 +
 manual/argp.texi                              |  20 +-
 manual/conf.texi                              |   2 +-
 manual/filesys.texi                           |   4 +-
 manual/getopt.texi                            |   6 +-
 manual/intro.texi                             |  17 +-
 manual/locale.texi                            |   9 +-
 manual/macros.texi                            |   4 -
 manual/memory.texi                            |  18 +-
 manual/message.texi                           |  37 ++-
 manual/pattern.texi                           |  64 +++--
 manual/process.texi                           |   4 +-
 manual/socket.texi                            | 145 ++++++-----
 manual/startup.texi                           | 122 +++++++--
 manual/sysinfo.texi                           |   2 +-
 manual/syslog.texi                            |  18 +-
 manual/time.texi                              | 150 ++++++-----
 posix/Makefile                                |   2 +
 posix/execve.c                                |  13 +-
 posix/execveat.c                              |  33 ++-
 posix/fexecve.c                               |  13 +-
 posix/fork.c                                  |   9 +
 posix/spawn_int.h                             |   7 +
 posix/spawni.c                                | 103 +++++++-
 posix/tst-fexecve.c                           |  14 ++
 posix/tst-vfork-mappings.c                    | 195 +++++++++++++++
 stdlib/Makefile                               |  31 ++-
 stdlib/environ_single_threaded_no_snapshot.c  |  40 +++
 stdlib/getenv.c                               | 140 ++++++++++-
 stdlib/getenvarray.c                          |  64 +++++
 stdlib/putenv.c                               |   2 +
 stdlib/setenv.c                               | 232 +++++++++++++-----
 stdlib/setenv.h                               |  98 ++++++++
 .../execveat.c => stdlib/tst-environ-execl.c  |  29 ++-
 stdlib/tst-environ-fork.c                     |  38 +++
 .../tst-environ-posix_spawn.c                 |  25 +-
 stdlib/tst-environ-snapshot-skeleton.c        | 218 ++++++++++++++++
 stdlib/tst-environ.c                          |  13 +-
 stdlib/tst-getenv-signal.c                    |  94 +++++++
 stdlib/tst-getenv-thread.c                    |  61 +++++
 stdlib/tst-getenv-unsetenv.c                  |  75 ++++++
 support/Makefile                              |   2 +
 support/support.h                             |   5 +
 support/support_count_maps.c                  |  51 ++++
 support/tst-support_count_maps.c              |  52 ++++
 sysdeps/generic/arch-execveat.h               |  25 ++
 sysdeps/generic/arch-spawni.h                 |  27 ++
 .../mach/hurd/{execveat.c => arch-execveat.h} |  11 +-
 sysdeps/mach/hurd/{spawni.c => arch-spawni.h} |  12 +-
 sysdeps/mach/hurd/fexecve.c                   |  47 ----
 sysdeps/unix/sysv/linux/arch-execveat.h       |  78 ++++++
 .../sysv/linux/{spawni.c => arch-spawni.h}    |  18 +-
 sysdeps/unix/sysv/linux/fexecve.c             |  69 ------
 sysdeps/unix/sysv/linux/syscalls.list         |   1 -
 54 files changed, 1985 insertions(+), 589 deletions(-)
 create mode 100644 posix/tst-vfork-mappings.c
 create mode 100644 stdlib/environ_single_threaded_no_snapshot.c
 create mode 100644 stdlib/getenvarray.c
 create mode 100644 stdlib/setenv.h
 rename sysdeps/unix/sysv/linux/execveat.c => stdlib/tst-environ-execl.c (56%)
 create mode 100644 stdlib/tst-environ-fork.c
 rename sysdeps/mach/hurd/execve.c => stdlib/tst-environ-posix_spawn.c (61%)
 create mode 100644 stdlib/tst-environ-snapshot-skeleton.c
 create mode 100644 stdlib/tst-getenv-signal.c
 create mode 100644 stdlib/tst-getenv-thread.c
 create mode 100644 stdlib/tst-getenv-unsetenv.c
 create mode 100644 support/support_count_maps.c
 create mode 100644 support/tst-support_count_maps.c
 create mode 100644 sysdeps/generic/arch-execveat.h
 create mode 100644 sysdeps/generic/arch-spawni.h
 rename sysdeps/mach/hurd/{execveat.c => arch-execveat.h} (90%)
 rename sysdeps/mach/hurd/{spawni.c => arch-spawni.h} (99%)
 delete mode 100644 sysdeps/mach/hurd/fexecve.c
 create mode 100644 sysdeps/unix/sysv/linux/arch-execveat.h
 rename sysdeps/unix/sysv/linux/{spawni.c => arch-spawni.h} (96%)
 delete mode 100644 sysdeps/unix/sysv/linux/fexecve.c


base-commit: 32328a5a1461ff88c0b1e04954e9c68b3fa7f56d