]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
security: prevents process creation
authorPhilippe Antoine <contact@catenacyber.fr>
Fri, 13 May 2022 12:52:06 +0000 (14:52 +0200)
committerVictor Julien <vjulien@oisf.net>
Thu, 27 Oct 2022 08:04:20 +0000 (10:04 +0200)
with setrlimit NPROC.

So that, if Suricata wants to execve or such to create a new process
the OS will forbid it so that RCE exploits are more painful to write.

Ticket: #5373

configure.ac
doc/userguide/configuration/landlock.rst
doc/userguide/configuration/suricata-yaml.rst
doc/userguide/upgrade.rst
src/suricata.c
suricata.yaml.in

index d50d565212ac2854a06565cd606f1f7d855b1a67..c42396cdab04feb478b764de4698aaeaeec1cd91 100644 (file)
     AC_CHECK_FUNCS([gethostname inet_ntoa uname])
     AC_CHECK_FUNCS([gettimeofday clock_gettime utime strptime tzset localtime_r])
     AC_CHECK_FUNCS([socket setenv select putenv dup2 endgrent endpwent atexit munmap])
+    AC_CHECK_FUNCS([setrlimit])
 
     AC_CHECK_FUNCS([fwrite_unlocked])
 
index 00d0660c85faf69e13cc8e035fb5a22b7bdd5328..65c7e8135bd89510041335954cde61be1f0247a9 100644 (file)
@@ -1,3 +1,5 @@
+.. _landlock:
+
 Using Landlock LSM
 ==================
 
index 27d6949b91a6cce29fb75951fdc2f2f316ee7ba0..5b4caea75b31b265a6bc59ef20292911ee4df51d 100644 (file)
@@ -2613,3 +2613,25 @@ detect thread. For each output script, a single state is used. Keep in
 mind that a rule reload temporary doubles the states requirement.
 
 .. _deprecation policy: https://suricata.io/about/deprecation-policy/
+
+.. _suricata-yaml-config-hardening:
+
+Configuration hardening
+-----------------------
+
+The `security` section of suricata.yaml is meant to provide in-depth security configuration options.
+
+Besides landlock, (see :ref:`landlock`), one setting is available.
+`limit-noproc` is a boolean to prevent process creation by Suricata.
+If you do not need Suricata to create other processes or threads
+(you may need it for LUA scripts for instance or plugins), enable this to
+call `setrlimit` with `RLIMIT_NPROC` argument (see `man setrlimit`).
+This prevents potential exploits against Suricata to fork a new process,
+even if it does not prevent the call of `exec`.
+
+Warning! This has no effect on Linux when running as root. If you want a hardened configuration,
+you probably want to set `run-as` configuration parameter so as to drop root privileges.
+
+Beyond suricata.yaml, other ways to harden Suricata are
+- compilation : enabling ASLR and other exploit mitigation techniques.
+- environment : running Suricata on a device that has no direct access to Internet.
index 9f2df10ef592cea8f403b040b194dfe34ae92faa..706ba14a96673186d4a477e85a05914cf5d36ca5 100644 (file)
@@ -37,6 +37,11 @@ Major changes
 ~~~~~~~~~~~~~
 - Upgrade of PCRE1 to PCRE2. See :ref:`pcre-update-v1-to-v2` for more details.
 
+Security changes
+~~~~~~~~~~~~~~~~
+- suricata.yaml now prevents process creation by Suricata by default with `security.limit-noproc`.
+  For more info, see :ref:`suricata-yaml-config-hardening`.
+
 Removals
 ~~~~~~~~
 - The libprelude output plugin has been removed.
index 335d6e301f542b14c86212e61012834e967a3c0c..74078c1d708f8820ae39ede034aec003702303fd 100644 (file)
 #if HAVE_SIGNAL_H
 #include <signal.h>
 #endif
+#ifndef OS_WIN32
+#ifdef HAVE_SYS_RESOURCE_H
+// setrlimit
+#include <sys/resource.h>
+#endif
+#endif
 
 #if HAVE_LIBSYSTEMD
 #include <systemd/sd-daemon.h>
@@ -2903,6 +2909,26 @@ int SuricataMain(int argc, char **argv)
                    "aborting...");
     }
 
+    int limit_nproc = 0;
+    if (ConfGetBool("security.limit-noproc", &limit_nproc) == 0) {
+        limit_nproc = 0;
+    }
+    if (limit_nproc) {
+#ifdef HAVE_SYS_RESOURCE_H
+#ifdef linux
+        if (geteuid() == 0) {
+            SCLogWarning(SC_ERR_SYSCONF, "setrlimit has no effet when running as root.");
+        }
+#endif
+        struct rlimit r = { 0, 0 };
+        if (setrlimit(RLIMIT_NPROC, &r) != 0) {
+            SCLogWarning(SC_ERR_SYSCONF, "setrlimit failed to prevent process creation.");
+        }
+#else
+        SCLogWarning(SC_ERR_SYSCONF, "setrlimit unavailable.");
+#endif
+    }
+
     SC_ATOMIC_SET(engine_stage, SURICATA_RUNTIME);
     PacketPoolPostRunmodes();
 
index a817ad1558cab92c967260f0e44968bf905108d5..e1a2ca932d056580c8527adba13bf6e0d22ce8f4 100644 (file)
@@ -1104,6 +1104,9 @@ asn1-max-frames: 256
 #  group: suri
 
 security:
+  # if true, prevents process creation from Suricata by calling
+  # setrlimit(RLIMIT_NPROC, 0)
+  limit-noproc: true
   # Use landlock security module under Linux
   landlock:
     enabled: no