process-util: also disable dlopen() in safe_fork()

This commit is contained in:
Lennart Poettering
2025-11-20 14:43:22 +01:00
parent 9252e26f4c
commit a08f2ea02d
4 changed files with 29 additions and 2 deletions

View File

@@ -22,6 +22,7 @@
#include "argv-util.h"
#include "cgroup-util.h"
#include "dirent-util.h"
#include "dlfcn-util.h"
#include "env-file.h"
#include "errno-util.h"
#include "escape.h"
@@ -1695,6 +1696,15 @@ int pidref_safe_fork_full(
r, "Failed to rename process, ignoring: %m");
}
/* let's disable dlopen() in the child, as a paranoia safety precaution: children should not live for
* long and only do minimal work before exiting or exec()ing. Doing dlopen() is not either. If people
* want dlopen() they should do it before forking. This is a safety precuation in particular for
* cases where the child does namespace shenanigans: we should never end up loading a module from a
* foreign environment. Note that this has no effect on NSS! (i.e. it only has effect on uses of our
* dlopen_safe(), which we use comprehensively in our codebase, but glibc NSS doesn't bother, of
* course.) */
block_dlopen();
if (flags & (FORK_DEATHSIG_SIGTERM|FORK_DEATHSIG_SIGINT|FORK_DEATHSIG_SIGKILL))
if (prctl(PR_SET_PDEATHSIG, fork_flags_to_signal(flags)) < 0) {
log_full_errno(prio, errno, "Failed to set death signal: %m");