grub/grub-core/osdep
Patrick Steinhardt 2da5f067f4 unix exec: avoid atexit handlers when child exits
The `grub_util_exec_redirect_all` helper function can be used to
spawn an executable and redirect its output to some files. After calling
`fork()`, the parent will wait for the child to terminate with
`waitpid()` while the child prepares its file descriptors, environment
and finally calls `execvp()`. If something in the children's setup
fails, it will stop by calling `exit(127)`.

Calling `exit()` will cause any function registered via `atexit()` to be
executed, which is usually the wrong thing to do in a child. And
actually, one can easily observe faulty behaviour on musl-based systems
without modprobe(8) installed: executing `grub-install --help` will call
`grub_util_exec_redirect_all` with "modprobe", which obviously fails if
modprobe(8) is not installed. Due to the child now exiting and invoking
the `atexit()` handlers, it will clean up some data structures of the
parent and cause it to be deadlocked in the `waitpid()` syscall.

The issue can easily be fixed by calling `_exit(127)` instead, which is
especially designed to be called when the atexit-handlers should not be
executed.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2020-09-21 12:02:37 -04:00
..
apple Make newly-created files other than grub.cfg world-readable. 2013-12-24 17:36:10 +01:00
aros Fix canonicalize_file_name clash. 2015-03-04 01:00:19 +01:00
basic Clarify several translatable messages. 2013-12-21 01:41:16 +01:00
bsd Make newly-created files other than grub.cfg world-readable. 2013-12-24 17:36:10 +01:00
devmapper fix detection of non-LUKS CRYPT 2016-11-05 15:28:50 +03:00
freebsd Ignore EPERM when modifying kern.geom.debugflags 2014-01-19 14:38:07 +00:00
generic * grub-core/osdep/generic/blocklist.c: Add missing include to string.h. 2013-10-19 02:24:40 +02:00
haiku haiku/getroot.c (grub_util_find_partition_start_os): Avoid division by zero. 2015-01-21 17:42:15 +01:00
hurd Clarify several translatable messages. 2013-12-21 01:41:16 +01:00
linux sparc64: Don't use devspec to determine the OBP path 2020-09-21 11:32:45 -04:00
sun Move stat () and device mode checking into OS-dependent files as 2013-10-19 16:29:20 +02:00
unix unix exec: avoid atexit handlers when child exits 2020-09-21 12:02:37 -04:00
windows windows: correct LBA in generated EFI HDD media paths 2015-12-19 11:32:49 +03:00
blocklist.c Split out blocklist retrieving from setup.c to 2013-10-15 17:02:26 +02:00
compress.c Rewrite grub-install, grub-mkrescue, grub-mkstandalone and grub-mknetdir 2013-11-16 20:21:16 +01:00
config.c Rewrite grub-install, grub-mkrescue, grub-mkstandalone and grub-mknetdir 2013-11-16 20:21:16 +01:00
cputime.c Move cpu time retrieval to separate grub_util_get_cpu_time_ms 2013-10-15 13:13:53 +02:00
dl.c Move OS-dependent mprotect for module loading to grub-core/osdep/*/dl.c 2013-12-08 18:08:23 +01:00
emuconsole.c * grub-core/osdep/windows/emuconsole.c: New file. 2013-10-14 21:33:55 +02:00
emunet.c * grub-core/net/drivers/emu/emunet.c: Move to .. 2013-10-08 18:42:46 +02:00
exec.c * grub-core/osdep/exec.c: Use unix version on cygwin. 2013-12-14 21:39:03 +01:00
getroot.c Add haiku-specific functions. 2013-10-19 16:39:38 +02:00
hostdisk.c Add haiku-specific functions. 2013-10-19 16:39:38 +02:00
init.c Move set_program_name and init_nls to host_init. On windows 2013-10-13 20:03:42 +02:00
ofpath.c * util/ieee1275/ofpath.c: Move to ... 2013-10-08 18:25:49 +02:00
password.c Move password-querying (util-version) routines to grub-core/osdep. 2013-10-08 17:51:39 +02:00
platform.c Implement windows flavour of EFI install routines. 2013-12-14 23:35:58 +01:00
platform_unix.c Rewrite grub-install, grub-mkrescue, grub-mkstandalone and grub-mknetdir 2013-11-16 20:21:16 +01:00
random.c * grub-core/osdep/random.c: Use unix/random.c on haiku. Haiku uses 2013-10-19 02:30:05 +02:00
relpath.c Split make_system_path_relative_to_its_root into separate file 2013-10-19 16:21:08 +02:00
sleep.c Move sleep routines to grub-core/osdep. 2013-10-08 17:38:46 +02:00