Skip to content

eBPF-based security platform

harden: load no code that a host configuration file names

Daniel Borkmanna4b15ae0e51b
diff --git a/Documentation/architecture.rst b/Documentation/architecture.rst
index aa268628..a541f4a7 100644
--- a/Documentation/architecture.rst
+++ b/Documentation/architecture.rst
@@ -337,8 +337,13 @@ attached or on a file system that takes no xattrs at creation.
Process hardening. ``util/harden.c`` runs at startup on the target:
``PR_SET_DUMPABLE`` off, ``PR_SET_NO_NEW_PRIVS``, ``PR_SET_PTRACER`` to
nobody, ``RLIMIT_CORE`` zero, sensitive buffers locked in memory and
-scrubbed after use. The zeroing allocator in ``util/malloc.c`` wipes
-freed memory; the libc allocators are poisoned project-wide.
+scrubbed after use. No host file may name code for it to load:
+OpenSSL reads no configuration file, so none can activate a provider
+module, and host names resolve through glibc's built-in ``files`` and
+``dns`` services alone, so ``nsswitch.conf`` cannot add a module
+either; ``/etc/hosts`` and ``/etc/resolv.conf``, a local resolver stub
+included, still apply. The zeroing allocator in ``util/malloc.c``
+wipes freed memory; the libc allocators are poisoned project-wide.
7) Target state
---------------
diff --git a/util/harden.c b/util/harden.c
index aa4e0168..bf587240 100644
--- a/util/harden.c
+++ b/util/harden.c
@@ -8,10 +8,13 @@
#include <errno.h>
#include <fcntl.h>
+#include <nss.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <unistd.h>
+#include <openssl/crypto.h>
+
#include "harden.h"
/*
@@ -32,6 +35,14 @@ void harden_stdio(void)
}
}
+/*
+ * No host file may name code for the process to load: an OpenSSL
+ * configuration file can activate a provider module, and nsswitch.conf
+ * can name an NSS module for the host lookups libcurl makes, both
+ * dlopen()ed from paths root controls whatever secure-exec mode does to
+ * the environment. glibc's own files and dns services answer host
+ * lookups without a module, in a static binary too.
+ */
void harden_self(void)
{
struct rlimit no_core = { 0, 0 };
@@ -40,4 +51,6 @@ void harden_self(void)
prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
prctl(PR_SET_PTRACER, 0, 0, 0, 0);
setrlimit(RLIMIT_CORE, &no_core);
+ OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL);
+ __nss_configure_lookup("hosts", "files dns");
}