|
|
df98bb |
From e706f5df66b7189a7df526aeeb45c86b8c4b057a Mon Sep 17 00:00:00 2001
|
|
|
df98bb |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
df98bb |
Date: Mon, 2 Nov 2020 14:51:10 +0100
|
|
|
df98bb |
Subject: [PATCH] seccomp: allow turning off of seccomp filtering via env var
|
|
|
df98bb |
|
|
|
df98bb |
Fixes: #17504
|
|
|
df98bb |
|
|
|
df98bb |
(While we are it, also move $SYSTEMD_SECCOMP_LOG= env var description
|
|
|
df98bb |
into the right document section)
|
|
|
df98bb |
|
|
|
df98bb |
Also suggested in: https://github.com/systemd/systemd/issues/17245#issuecomment-704773603
|
|
|
df98bb |
|
|
|
df98bb |
(cherry picked from commit ce8f6d478e3f6c6a313fb19615aa5029bb18f86d)
|
|
|
df98bb |
|
|
|
df98bb |
Resolves: #1916835
|
|
|
df98bb |
---
|
|
|
df98bb |
doc/ENVIRONMENT.md | 3 +++
|
|
|
df98bb |
src/nspawn/nspawn-seccomp.c | 2 +-
|
|
|
df98bb |
src/shared/seccomp-util.c | 19 +++++++++++++++----
|
|
|
df98bb |
3 files changed, 19 insertions(+), 5 deletions(-)
|
|
|
df98bb |
|
|
|
df98bb |
diff --git a/doc/ENVIRONMENT.md b/doc/ENVIRONMENT.md
|
|
|
df98bb |
index 0e763b6302..36b649afe1 100644
|
|
|
df98bb |
--- a/doc/ENVIRONMENT.md
|
|
|
df98bb |
+++ b/doc/ENVIRONMENT.md
|
|
|
df98bb |
@@ -117,3 +117,6 @@ systemd-sulogin-shell:
|
|
|
df98bb |
* `$SYSTEMD_SULOGIN_FORCE=1` — This skips asking for the root password if the
|
|
|
df98bb |
root password is not available (such as when the root account is locked).
|
|
|
df98bb |
See `sulogin(8)` for more details.
|
|
|
df98bb |
+
|
|
|
df98bb |
+* `$SYSTEMD_SECCOMP=0` – if set, seccomp filters will not be enforced, even if
|
|
|
df98bb |
+ support for it is compiled in and available in the kernel.
|
|
|
df98bb |
diff --git a/src/nspawn/nspawn-seccomp.c b/src/nspawn/nspawn-seccomp.c
|
|
|
df98bb |
index b56c5b04a8..fba22644da 100644
|
|
|
df98bb |
--- a/src/nspawn/nspawn-seccomp.c
|
|
|
df98bb |
+++ b/src/nspawn/nspawn-seccomp.c
|
|
|
df98bb |
@@ -172,7 +172,7 @@ int setup_seccomp(uint64_t cap_list_retain, char **syscall_whitelist, char **sys
|
|
|
df98bb |
int r;
|
|
|
df98bb |
|
|
|
df98bb |
if (!is_seccomp_available()) {
|
|
|
df98bb |
- log_debug("SECCOMP features not detected in the kernel, disabling SECCOMP filterering");
|
|
|
df98bb |
+ log_debug("SECCOMP features not detected in the kernel or disabled at runtime, disabling SECCOMP filtering");
|
|
|
df98bb |
return 0;
|
|
|
df98bb |
}
|
|
|
df98bb |
|
|
|
df98bb |
diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c
|
|
|
df98bb |
index d91fb4e269..e903512d45 100644
|
|
|
df98bb |
--- a/src/shared/seccomp-util.c
|
|
|
df98bb |
+++ b/src/shared/seccomp-util.c
|
|
|
df98bb |
@@ -12,6 +12,7 @@
|
|
|
df98bb |
|
|
|
df98bb |
#include "af-list.h"
|
|
|
df98bb |
#include "alloc-util.h"
|
|
|
df98bb |
+#include "env-util.h"
|
|
|
df98bb |
#include "macro.h"
|
|
|
df98bb |
#include "nsflags.h"
|
|
|
df98bb |
#include "process-util.h"
|
|
|
df98bb |
@@ -244,10 +245,20 @@ static bool is_seccomp_filter_available(void) {
|
|
|
df98bb |
bool is_seccomp_available(void) {
|
|
|
df98bb |
static int cached_enabled = -1;
|
|
|
df98bb |
|
|
|
df98bb |
- if (cached_enabled < 0)
|
|
|
df98bb |
- cached_enabled =
|
|
|
df98bb |
- is_basic_seccomp_available() &&
|
|
|
df98bb |
- is_seccomp_filter_available();
|
|
|
df98bb |
+ if (cached_enabled < 0) {
|
|
|
df98bb |
+ int b;
|
|
|
df98bb |
+
|
|
|
df98bb |
+ b = getenv_bool("SYSTEMD_SECCOMP");
|
|
|
df98bb |
+ if (b != 0) {
|
|
|
df98bb |
+ if (b < 0 && b != -ENXIO) /* ENXIO: env var unset */
|
|
|
df98bb |
+ log_debug_errno(b, "Failed to parse $SYSTEMD_SECCOMP value, ignoring.");
|
|
|
df98bb |
+
|
|
|
df98bb |
+ cached_enabled =
|
|
|
df98bb |
+ is_basic_seccomp_available() &&
|
|
|
df98bb |
+ is_seccomp_filter_available();
|
|
|
df98bb |
+ } else
|
|
|
df98bb |
+ cached_enabled = false;
|
|
|
df98bb |
+ }
|
|
|
df98bb |
|
|
|
df98bb |
return cached_enabled;
|
|
|
df98bb |
}
|