summaryrefslogtreecommitdiff
path: root/src/shared/seccomp-util.c
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2016-09-07 06:44:06 +0300
committerGitHub <noreply@github.com>2016-09-07 06:44:06 +0300
commitc5d5fc91eba8541a3a86ff6b839a2b6e824f4149 (patch)
tree5ac8a407c10f16e024b07a92a1d14f89b43244c5 /src/shared/seccomp-util.c
parent29272d9e03b85deafe30ff79aa291afe7cceb430 (diff)
parentfd74fa791f95433ac52520764b67e6fb4bda2c0e (diff)
Merge pull request #4087 from fsateler/detect-seccomp-filter
seccomp: also detect if seccomp filtering is available
Diffstat (limited to 'src/shared/seccomp-util.c')
-rw-r--r--src/shared/seccomp-util.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c
index 6c489284d1..2f42381fc1 100644
--- a/src/shared/seccomp-util.c
+++ b/src/shared/seccomp-util.c
@@ -20,9 +20,9 @@
#include <errno.h>
#include <seccomp.h>
#include <stddef.h>
+#include <sys/prctl.h>
+#include <linux/seccomp.h>
-#include "alloc-util.h"
-#include "fileio.h"
#include "macro.h"
#include "seccomp-util.h"
#include "string-util.h"
@@ -91,11 +91,22 @@ int seccomp_add_secondary_archs(scmp_filter_ctx *c) {
}
+static bool is_basic_seccomp_available(void) {
+ int r;
+ r = prctl(PR_GET_SECCOMP, 0, 0, 0, 0);
+ return r >= 0;
+}
+
+static bool is_seccomp_filter_available(void) {
+ int r;
+ r = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, NULL, 0, 0);
+ return r < 0 && errno == EFAULT;
+}
+
bool is_seccomp_available(void) {
- _cleanup_free_ char* field = NULL;
static int cached_enabled = -1;
if (cached_enabled < 0)
- cached_enabled = get_proc_field("/proc/self/status", "Seccomp", "\n", &field) == 0;
+ cached_enabled = is_basic_seccomp_available() && is_seccomp_filter_available();
return cached_enabled;
}