dlfcn-util: let's make our dlopen() code fail if we enter a container namespace

Now that we dlopen() so many deps, it might happen by accident that we
end up dlopen()ening stuff when we entered a container, which we should
really avoid, to not mix host and container libraries.

Let's add a global variable we can set when we want to block dlopen() to
ever succeed. This is then checked primarily in
dlopen_many_sym_or_warn(), where we'll generate EPERM plus a log
message.

There are a couple of other places we invoke dlopen(), without going
through dlopen_many_sym_or_warn(). This adds the same check there.
This commit is contained in:
Lennart Poettering
2025-11-24 09:19:33 +01:00
parent ab5a79ff5d
commit 2c7bdaf9f1
9 changed files with 113 additions and 31 deletions
+3
View File
@@ -4372,6 +4372,9 @@ static int outer_child(
if (pid == 0) {
fd_outer_socket = safe_close(fd_outer_socket);
/* In the child refuse dlopen(), so that we never mix shared libraries from payload and parent */
block_dlopen();
/* The inner child has all namespaces that are requested, so that we all are owned by the
* user if user namespaces are turned on. */