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:
+7
-6
@@ -1977,21 +1977,22 @@ int membershipdb_by_group_strv(const char *name, UserDBFlags flags, char ***ret)
|
||||
}
|
||||
|
||||
int userdb_block_nss_systemd(int b) {
|
||||
_cleanup_(dlclosep) void *dl = NULL;
|
||||
int (*call)(bool b);
|
||||
int r;
|
||||
|
||||
/* Note that we might be called from libnss_systemd.so.2 itself, but that should be fine, really. */
|
||||
|
||||
dl = dlopen(LIBDIR "/libnss_systemd.so.2", RTLD_NOW|RTLD_NODELETE);
|
||||
if (!dl) {
|
||||
_cleanup_(dlclosep) void *dl = NULL;
|
||||
const char *dle;
|
||||
r = dlopen_safe(LIBDIR "/libnss_systemd.so.2", &dl, &dle);
|
||||
if (r < 0) {
|
||||
/* If the file isn't installed, don't complain loudly */
|
||||
log_debug("Failed to dlopen(libnss_systemd.so.2), ignoring: %s", dlerror());
|
||||
log_debug_errno(r, "Failed to dlopen(libnss_systemd.so.2), ignoring: %s", dle ?: STRERROR(r));
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_debug("Loaded '%s' via dlopen()", LIBDIR "/libnss_systemd.so.2");
|
||||
|
||||
call = dlsym(dl, "_nss_systemd_block");
|
||||
int (*call)(bool b) = dlsym(dl, "_nss_systemd_block");
|
||||
if (!call)
|
||||
/* If the file is installed but lacks the symbol we expect, things are weird, let's complain */
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ELIBBAD),
|
||||
|
||||
Reference in New Issue
Block a user