daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
803fb7
From 201006fa521199ebf109016c9dd22812c435dfe9 Mon Sep 17 00:00:00 2001
803fb7
From: Ismo Puustinen <ismo.puustinen@intel.com>
803fb7
Date: Fri, 8 Jan 2016 00:00:04 +0200
803fb7
Subject: [PATCH] capabilities: keep bounding set in non-inverted format.
803fb7
803fb7
Change the capability bounding set parser and logic so that the bounding
803fb7
set is kept as a positive set internally. This means that the set
803fb7
reflects those capabilities that we want to keep instead of drop.
803fb7
803fb7
Resolves: #1387398
803fb7
---
803fb7
 src/core/dbus-execute.c               |  4 +-
de8967
 src/core/execute.c                    |  9 +--
803fb7
 src/core/execute.h                    |  2 +-
803fb7
 src/core/load-fragment-gperf.gperf.m4 |  2 +-
de8967
 src/core/load-fragment.c              | 25 ++++----
803fb7
 src/core/load-fragment.h              |  2 +-
de8967
 src/core/main.c                       | 10 +--
803fb7
 src/core/unit.c                       |  2 +-
803fb7
 src/import/import-common.c            |  2 +-
803fb7
 src/nspawn/nspawn.c                   |  2 +-
de8967
 src/shared/capability.c               | 16 ++---
de8967
 src/shared/capability.h               | 12 +++-
de8967
 src/test/test-unit-file.c             | 89 +++++++++++++++------------
803fb7
 13 files changed, 96 insertions(+), 81 deletions(-)
803fb7
803fb7
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
803fb7
index da8b10d2b..a564c53fa 100644
803fb7
--- a/src/core/dbus-execute.c
803fb7
+++ b/src/core/dbus-execute.c
803fb7
@@ -324,9 +324,7 @@ static int property_get_capability_bounding_set(
803fb7
         assert(reply);
803fb7
         assert(c);
803fb7
 
803fb7
-        /* We store this negated internally, to match the kernel, but
803fb7
-         * we expose it normalized. */
803fb7
-        return sd_bus_message_append(reply, "t", ~c->capability_bounding_set_drop);
803fb7
+        return sd_bus_message_append(reply, "t", c->capability_bounding_set);
803fb7
 }
803fb7
 
803fb7
 static int property_get_capabilities(
803fb7
diff --git a/src/core/execute.c b/src/core/execute.c
803fb7
index f72b20966..40db11e28 100644
803fb7
--- a/src/core/execute.c
803fb7
+++ b/src/core/execute.c
803fb7
@@ -1733,8 +1733,8 @@ static int exec_child(
803fb7
                         }
803fb7
                 }
803fb7
 
803fb7
-                if (context->capability_bounding_set_drop) {
803fb7
-                        r = capability_bounding_set_drop(context->capability_bounding_set_drop, false);
803fb7
+                if (!cap_test_all(context->capability_bounding_set)) {
803fb7
+                        r = capability_bounding_set_drop(context->capability_bounding_set, false);
803fb7
                         if (r < 0) {
803fb7
                                 *exit_status = EXIT_CAPABILITIES;
803fb7
                                 return r;
803fb7
@@ -1988,6 +1988,7 @@ void exec_context_init(ExecContext *c) {
803fb7
         c->timer_slack_nsec = NSEC_INFINITY;
803fb7
         c->personality = 0xffffffffUL;
803fb7
         c->runtime_directory_mode = 0755;
803fb7
+        c->capability_bounding_set = CAP_ALL;
803fb7
 }
803fb7
 
803fb7
 void exec_context_done(ExecContext *c) {
803fb7
@@ -2419,12 +2420,12 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
803fb7
                         (c->secure_bits & 1<
803fb7
                         (c->secure_bits & 1<
803fb7
 
803fb7
-        if (c->capability_bounding_set_drop) {
803fb7
+        if (c->capability_bounding_set != CAP_ALL) {
803fb7
                 unsigned long l;
803fb7
                 fprintf(f, "%sCapabilityBoundingSet:", prefix);
803fb7
 
803fb7
                 for (l = 0; l <= cap_last_cap(); l++)
803fb7
-                        if (!(c->capability_bounding_set_drop & ((uint64_t) 1ULL << (uint64_t) l)))
803fb7
+                        if (c->capability_bounding_set & (UINT64_C(1) << l))
803fb7
                                 fprintf(f, " %s", strna(capability_to_name(l)));
803fb7
 
803fb7
                 fputs("\n", f);
803fb7
diff --git a/src/core/execute.h b/src/core/execute.h
803fb7
index cadd0e6b4..40f7b794c 100644
803fb7
--- a/src/core/execute.h
803fb7
+++ b/src/core/execute.h
803fb7
@@ -150,7 +150,7 @@ struct ExecContext {
803fb7
         char **read_write_dirs, **read_only_dirs, **inaccessible_dirs;
803fb7
         unsigned long mount_flags;
803fb7
 
803fb7
-        uint64_t capability_bounding_set_drop;
803fb7
+        uint64_t capability_bounding_set;
803fb7
 
803fb7
         cap_t capabilities;
803fb7
         int secure_bits;
803fb7
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
803fb7
index b50fe45b4..e4ce29210 100644
803fb7
--- a/src/core/load-fragment-gperf.gperf.m4
803fb7
+++ b/src/core/load-fragment-gperf.gperf.m4
803fb7
@@ -47,7 +47,7 @@ $1.SyslogLevel,                  config_parse_log_level,             0,
803fb7
 $1.SyslogLevelPrefix,            config_parse_bool,                  0,                             offsetof($1, exec_context.syslog_level_prefix)
803fb7
 $1.Capabilities,                 config_parse_exec_capabilities,     0,                             offsetof($1, exec_context)
803fb7
 $1.SecureBits,                   config_parse_exec_secure_bits,      0,                             offsetof($1, exec_context)
803fb7
-$1.CapabilityBoundingSet,        config_parse_bounding_set,          0,                             offsetof($1, exec_context.capability_bounding_set_drop)
803fb7
+$1.CapabilityBoundingSet,        config_parse_capability_set,        0,                             offsetof($1, exec_context.capability_bounding_set)
803fb7
 $1.TimerSlackNSec,               config_parse_nsec,                  0,                             offsetof($1, exec_context.timer_slack_nsec)
803fb7
 $1.NoNewPrivileges,              config_parse_no_new_privileges,     0,                             offsetof($1, exec_context)
803fb7
 m4_ifdef(`HAVE_SECCOMP',
803fb7
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
803fb7
index ab3b0c2e9..dbaaf2fee 100644
803fb7
--- a/src/core/load-fragment.c
803fb7
+++ b/src/core/load-fragment.c
803fb7
@@ -1015,7 +1015,7 @@ int config_parse_exec_secure_bits(const char *unit,
803fb7
         return 0;
803fb7
 }
803fb7
 
803fb7
-int config_parse_bounding_set(
803fb7
+int config_parse_capability_set(
803fb7
                 const char *unit,
803fb7
                 const char *filename,
803fb7
                 unsigned line,
803fb7
@@ -1027,8 +1027,8 @@ int config_parse_bounding_set(
803fb7
                 void *data,
803fb7
                 void *userdata) {
803fb7
 
803fb7
-        uint64_t *capability_bounding_set_drop = data;
803fb7
-        uint64_t capability_bounding_set, sum = 0;
803fb7
+        uint64_t *capability_set = data;
803fb7
+        uint64_t sum = 0, initial = 0;
803fb7
         bool invert = false;
803fb7
         const char *p;
803fb7
 
803fb7
@@ -1042,10 +1042,8 @@ int config_parse_bounding_set(
803fb7
                 rvalue++;
803fb7
         }
803fb7
 
803fb7
-        /* Note that we store this inverted internally, since the
803fb7
-         * kernel wants it like this. But we actually expose it
803fb7
-         * non-inverted everywhere to have a fully normalized
803fb7
-         * interface. */
803fb7
+        if (strcmp(lvalue, "CapabilityBoundingSet") == 0)
803fb7
+                initial = CAP_ALL; /* initialized to all bits on */
803fb7
 
803fb7
         p = rvalue;
803fb7
         for (;;) {
803fb7
@@ -1071,11 +1069,14 @@ int config_parse_bounding_set(
803fb7
                 sum |= ((uint64_t) UINT64_C(1)) << (uint64_t) cap;
803fb7
         }
803fb7
 
803fb7
-        capability_bounding_set = invert ? ~sum : sum;
803fb7
-        if (*capability_bounding_set_drop != 0 && capability_bounding_set != 0)
803fb7
-                *capability_bounding_set_drop = ~(~*capability_bounding_set_drop | capability_bounding_set);
803fb7
+        sum = invert ? ~sum : sum;
803fb7
+
803fb7
+        if (sum == 0 || *capability_set == initial)
803fb7
+                /* "" or uninitialized data -> replace */
803fb7
+                *capability_set = sum;
803fb7
         else
803fb7
-                *capability_bounding_set_drop = ~capability_bounding_set;
803fb7
+                /* previous data -> merge */
803fb7
+                *capability_set |= sum;
803fb7
 
803fb7
         return 0;
803fb7
 }
803fb7
@@ -4050,7 +4051,7 @@ void unit_dump_config_items(FILE *f) {
803fb7
                 { config_parse_log_level,             "LEVEL" },
803fb7
                 { config_parse_exec_capabilities,     "CAPABILITIES" },
803fb7
                 { config_parse_exec_secure_bits,      "SECUREBITS" },
803fb7
-                { config_parse_bounding_set,          "BOUNDINGSET" },
803fb7
+                { config_parse_capability_set,        "BOUNDINGSET" },
803fb7
                 { config_parse_limit,                 "LIMIT" },
803fb7
                 { config_parse_unit_deps,             "UNIT [...]" },
803fb7
                 { config_parse_exec,                  "PATH [ARGUMENT [...]]" },
803fb7
diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h
803fb7
index 9dd7d1bda..2059353d3 100644
803fb7
--- a/src/core/load-fragment.h
803fb7
+++ b/src/core/load-fragment.h
803fb7
@@ -54,7 +54,7 @@ int config_parse_exec_cpu_sched_prio(const char *unit, const char *filename, uns
803fb7
 int config_parse_exec_cpu_affinity(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
803fb7
 int config_parse_exec_capabilities(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
803fb7
 int config_parse_exec_secure_bits(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
803fb7
-int config_parse_bounding_set(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
803fb7
+int config_parse_capability_set(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
803fb7
 int config_parse_limit(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
803fb7
 int config_parse_bytes_limit(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
803fb7
 int config_parse_sec_limit(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
803fb7
diff --git a/src/core/main.c b/src/core/main.c
803fb7
index a0df1e5ce..cba992cea 100644
803fb7
--- a/src/core/main.c
803fb7
+++ b/src/core/main.c
803fb7
@@ -108,7 +108,7 @@ static usec_t arg_runtime_watchdog = 0;
803fb7
 static usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE;
803fb7
 static char **arg_default_environment = NULL;
803fb7
 static struct rlimit *arg_default_rlimit[_RLIMIT_MAX] = {};
803fb7
-static uint64_t arg_capability_bounding_set_drop = 0;
803fb7
+static uint64_t arg_capability_bounding_set = CAP_ALL;
803fb7
 static nsec_t arg_timer_slack_nsec = NSEC_INFINITY;
803fb7
 static usec_t arg_default_timer_accuracy_usec = 1 * USEC_PER_MINUTE;
803fb7
 static Set* arg_syscall_archs = NULL;
803fb7
@@ -642,7 +642,7 @@ static int parse_config_file(void) {
803fb7
                 { "Manager", "JoinControllers",           config_parse_join_controllers, 0, &arg_join_controllers                  },
803fb7
                 { "Manager", "RuntimeWatchdogSec",        config_parse_sec,              0, &arg_runtime_watchdog                  },
803fb7
                 { "Manager", "ShutdownWatchdogSec",       config_parse_sec,              0, &arg_shutdown_watchdog                 },
803fb7
-                { "Manager", "CapabilityBoundingSet",     config_parse_bounding_set,     0, &arg_capability_bounding_set_drop      },
803fb7
+                { "Manager", "CapabilityBoundingSet",     config_parse_capability_set,   0, &arg_capability_bounding_set           },
803fb7
 #ifdef HAVE_SECCOMP
803fb7
                 { "Manager", "SystemCallArchitectures",   config_parse_syscall_archs,    0, &arg_syscall_archs                     },
803fb7
 #endif
803fb7
@@ -1622,14 +1622,14 @@ int main(int argc, char *argv[]) {
803fb7
                 if (prctl(PR_SET_TIMERSLACK, arg_timer_slack_nsec) < 0)
803fb7
                         log_error_errno(errno, "Failed to adjust timer slack: %m");
803fb7
 
803fb7
-        if (arg_capability_bounding_set_drop) {
803fb7
-                r = capability_bounding_set_drop_usermode(arg_capability_bounding_set_drop);
803fb7
+        if (!cap_test_all(arg_capability_bounding_set)) {
803fb7
+                r = capability_bounding_set_drop_usermode(arg_capability_bounding_set);
803fb7
                 if (r < 0) {
803fb7
                         log_emergency_errno(r, "Failed to drop capability bounding set of usermode helpers: %m");
803fb7
                         error_message = "Failed to drop capability bounding set of usermode helpers";
803fb7
                         goto finish;
803fb7
                 }
803fb7
-                r = capability_bounding_set_drop(arg_capability_bounding_set_drop, true);
803fb7
+                r = capability_bounding_set_drop(arg_capability_bounding_set, true);
803fb7
                 if (r < 0) {
803fb7
                         log_emergency_errno(r, "Failed to drop capability bounding set: %m");
803fb7
                         error_message = "Failed to drop capability bounding set";
803fb7
diff --git a/src/core/unit.c b/src/core/unit.c
803fb7
index 4eb0d78f4..103f92084 100644
803fb7
--- a/src/core/unit.c
803fb7
+++ b/src/core/unit.c
803fb7
@@ -3213,7 +3213,7 @@ int unit_patch_contexts(Unit *u) {
803fb7
                         ec->no_new_privileges = true;
803fb7
 
803fb7
                 if (ec->private_devices)
803fb7
-                        ec->capability_bounding_set_drop |= (uint64_t) 1ULL << (uint64_t) CAP_MKNOD;
803fb7
+                        ec->capability_bounding_set &= ~(UINT64_C(1) << CAP_MKNOD);
803fb7
         }
803fb7
 
803fb7
         cc = unit_get_cgroup_context(u);
803fb7
diff --git a/src/import/import-common.c b/src/import/import-common.c
803fb7
index f10a453ee..243e657c5 100644
803fb7
--- a/src/import/import-common.c
803fb7
+++ b/src/import/import-common.c
803fb7
@@ -526,7 +526,7 @@ int import_fork_tar(const char *path, pid_t *ret) {
803fb7
                 if (unshare(CLONE_NEWNET) < 0)
803fb7
                         log_error_errno(errno, "Failed to lock tar into network namespace, ignoring: %m");
803fb7
 
803fb7
-                r = capability_bounding_set_drop(~retain, true);
803fb7
+                r = capability_bounding_set_drop(retain, true);
803fb7
                 if (r < 0)
803fb7
                         log_error_errno(r, "Failed to drop capabilities, ignoring: %m");
803fb7
 
803fb7
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
803fb7
index a37b64094..d0003d379 100644
803fb7
--- a/src/nspawn/nspawn.c
803fb7
+++ b/src/nspawn/nspawn.c
803fb7
@@ -1863,7 +1863,7 @@ static int setup_journal(const char *directory) {
803fb7
 }
803fb7
 
803fb7
 static int drop_capabilities(void) {
803fb7
-        return capability_bounding_set_drop(~arg_retain, false);
803fb7
+        return capability_bounding_set_drop(arg_retain, false);
803fb7
 }
803fb7
 
803fb7
 static int register_machine(pid_t pid, int local_ifindex) {
803fb7
diff --git a/src/shared/capability.c b/src/shared/capability.c
803fb7
index 2b963fde3..3ed31df5a 100644
803fb7
--- a/src/shared/capability.c
803fb7
+++ b/src/shared/capability.c
803fb7
@@ -98,7 +98,7 @@ unsigned long cap_last_cap(void) {
803fb7
         return p;
803fb7
 }
803fb7
 
803fb7
-int capability_bounding_set_drop(uint64_t drop, bool right_now) {
803fb7
+int capability_bounding_set_drop(uint64_t keep, bool right_now) {
803fb7
         _cleanup_cap_free_ cap_t after_cap = NULL;
803fb7
         cap_flag_value_t fv;
803fb7
         unsigned long i;
803fb7
@@ -139,7 +139,7 @@ int capability_bounding_set_drop(uint64_t drop, bool right_now) {
803fb7
 
803fb7
         for (i = 0; i <= cap_last_cap(); i++) {
803fb7
 
803fb7
-                if (drop & ((uint64_t) 1ULL << (uint64_t) i)) {
803fb7
+                if (!(keep & (UINT64_C(1) << i))) {
803fb7
                         cap_value_t v;
803fb7
 
803fb7
                         /* Drop it from the bounding set */
803fb7
@@ -178,7 +178,7 @@ finish:
803fb7
         return r;
803fb7
 }
803fb7
 
803fb7
-static int drop_from_file(const char *fn, uint64_t drop) {
803fb7
+static int drop_from_file(const char *fn, uint64_t keep) {
803fb7
         int r, k;
803fb7
         uint32_t hi, lo;
803fb7
         uint64_t current, after;
803fb7
@@ -198,7 +198,7 @@ static int drop_from_file(const char *fn, uint64_t drop) {
803fb7
                 return -EIO;
803fb7
 
803fb7
         current = (uint64_t) lo | ((uint64_t) hi << 32ULL);
803fb7
-        after = current & ~drop;
803fb7
+        after = current & keep;
803fb7
 
803fb7
         if (current == after)
803fb7
                 return 0;
803fb7
@@ -215,14 +215,14 @@ static int drop_from_file(const char *fn, uint64_t drop) {
803fb7
         return r;
803fb7
 }
803fb7
 
803fb7
-int capability_bounding_set_drop_usermode(uint64_t drop) {
803fb7
+int capability_bounding_set_drop_usermode(uint64_t keep) {
803fb7
         int r;
803fb7
 
803fb7
-        r = drop_from_file("/proc/sys/kernel/usermodehelper/inheritable", drop);
803fb7
+        r = drop_from_file("/proc/sys/kernel/usermodehelper/inheritable", keep);
803fb7
         if (r < 0)
803fb7
                 return r;
803fb7
 
803fb7
-        r = drop_from_file("/proc/sys/kernel/usermodehelper/bset", drop);
803fb7
+        r = drop_from_file("/proc/sys/kernel/usermodehelper/bset", keep);
803fb7
         if (r < 0)
803fb7
                 return r;
803fb7
 
803fb7
@@ -259,7 +259,7 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) {
803fb7
                 return log_error_errno(errno, "Failed to disable keep capabilities flag: %m");
803fb7
 
803fb7
         /* Drop all caps from the bounding set, except the ones we want */
803fb7
-        r = capability_bounding_set_drop(~keep_capabilities, true);
803fb7
+        r = capability_bounding_set_drop(keep_capabilities, true);
803fb7
         if (r < 0)
803fb7
                 return log_error_errno(r, "Failed to drop capabilities: %m");
803fb7
 
803fb7
diff --git a/src/shared/capability.h b/src/shared/capability.h
803fb7
index 6f2f6f997..04cd6e54e 100644
803fb7
--- a/src/shared/capability.h
803fb7
+++ b/src/shared/capability.h
803fb7
@@ -27,10 +27,12 @@
803fb7
 
803fb7
 #include "util.h"
803fb7
 
803fb7
+#define CAP_ALL (uint64_t) -1
803fb7
+
803fb7
 unsigned long cap_last_cap(void);
803fb7
 int have_effective_cap(int value);
803fb7
-int capability_bounding_set_drop(uint64_t drop, bool right_now);
803fb7
-int capability_bounding_set_drop_usermode(uint64_t drop);
803fb7
+int capability_bounding_set_drop(uint64_t keep, bool right_now);
803fb7
+int capability_bounding_set_drop_usermode(uint64_t keep);
803fb7
 
803fb7
 int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilites);
803fb7
 
803fb7
@@ -44,3 +46,9 @@ static inline void cap_free_charpp(char **p) {
803fb7
                 cap_free(*p);
803fb7
 }
803fb7
 #define _cleanup_cap_free_charp_ _cleanup_(cap_free_charpp)
803fb7
+
803fb7
+static inline bool cap_test_all(uint64_t caps) {
803fb7
+        uint64_t m;
803fb7
+        m = (UINT64_C(1) << (cap_last_cap() + 1)) - 1;
803fb7
+        return (caps & m) == m;
803fb7
+}
803fb7
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
803fb7
index 0f00a8fff..38ecfe972 100644
803fb7
--- a/src/test/test-unit-file.c
803fb7
+++ b/src/test/test-unit-file.c
803fb7
@@ -550,6 +550,53 @@ static uint64_t make_cap(int cap) {
803fb7
         return ((uint64_t) 1ULL << (uint64_t) cap);
803fb7
 }
803fb7
 
803fb7
+static void test_config_parse_capability_set(void) {
803fb7
+        /* int config_parse_capability_set(
803fb7
+                 const char *unit,
803fb7
+                 const char *filename,
803fb7
+                 unsigned line,
803fb7
+                 const char *section,
803fb7
+                 unsigned section_line,
803fb7
+                 const char *lvalue,
803fb7
+                 int ltype,
803fb7
+                 const char *rvalue,
803fb7
+                 void *data,
803fb7
+                 void *userdata) */
803fb7
+        int r;
803fb7
+        uint64_t capability_bounding_set = 0;
803fb7
+
803fb7
+        r = config_parse_capability_set(NULL, "fake", 1, "section", 1,
803fb7
+                              "CapabilityBoundingSet", 0, "CAP_NET_RAW",
803fb7
+                              &capability_bounding_set, NULL);
803fb7
+        assert_se(r >= 0);
803fb7
+        assert_se(capability_bounding_set == make_cap(CAP_NET_RAW));
803fb7
+
803fb7
+        r = config_parse_capability_set(NULL, "fake", 1, "section", 1,
803fb7
+                              "CapabilityBoundingSet", 0, "CAP_NET_ADMIN",
803fb7
+                              &capability_bounding_set, NULL);
803fb7
+        assert_se(r >= 0);
803fb7
+        assert_se(capability_bounding_set == (make_cap(CAP_NET_RAW) | make_cap(CAP_NET_ADMIN)));
803fb7
+
803fb7
+        r = config_parse_capability_set(NULL, "fake", 1, "section", 1,
803fb7
+                              "CapabilityBoundingSet", 0, "",
803fb7
+                              &capability_bounding_set, NULL);
803fb7
+        assert_se(r >= 0);
803fb7
+        assert_se(capability_bounding_set == UINT64_C(0));
803fb7
+
803fb7
+        r = config_parse_capability_set(NULL, "fake", 1, "section", 1,
803fb7
+                              "CapabilityBoundingSet", 0, "~",
803fb7
+                              &capability_bounding_set, NULL);
803fb7
+        assert_se(r >= 0);
803fb7
+        assert_se(cap_test_all(capability_bounding_set));
803fb7
+
803fb7
+        capability_bounding_set = 0;
803fb7
+        r = config_parse_capability_set(NULL, "fake", 1, "section", 1,
803fb7
+                              "CapabilityBoundingSet", 0, "  'CAP_NET_RAW' WAT_CAP??? CAP_NET_ADMIN CAP'_trailing_garbage",
803fb7
+                              &capability_bounding_set, NULL);
803fb7
+        assert_se(r >= 0);
803fb7
+        assert_se(capability_bounding_set == (make_cap(CAP_NET_RAW) | make_cap(CAP_NET_ADMIN)));
803fb7
+}
803fb7
+
803fb7
 static void test_config_parse_rlimit(void) {
803fb7
         struct rlimit * rl[_RLIMIT_MAX] = {};
803fb7
 
803fb7
@@ -665,46 +712,6 @@ static void test_config_parse_rlimit(void) {
803fb7
         free(rl[RLIMIT_RTTIME]);
803fb7
 }
803fb7
 
803fb7
-static void test_config_parse_bounding_set(void) {
803fb7
-        /* int config_parse_bounding_set(
803fb7
-                 const char *unit,
803fb7
-                 const char *filename,
803fb7
-                 unsigned line,
803fb7
-                 const char *section,
803fb7
-                 unsigned section_line,
803fb7
-                 const char *lvalue,
803fb7
-                 int ltype,
803fb7
-                 const char *rvalue,
803fb7
-                 void *data,
803fb7
-                 void *userdata) */
803fb7
-        int r;
803fb7
-        uint64_t capability_bounding_set_drop = 0;
803fb7
-
803fb7
-        r = config_parse_bounding_set(NULL, "fake", 1, "section", 1,
803fb7
-                              "CapabilityBoundingSet", 0, "CAP_NET_RAW",
803fb7
-                              &capability_bounding_set_drop, NULL);
803fb7
-        assert_se(r >= 0);
803fb7
-        assert_se(capability_bounding_set_drop == ~make_cap(CAP_NET_RAW));
803fb7
-
803fb7
-        r = config_parse_bounding_set(NULL, "fake", 1, "section", 1,
803fb7
-                              "CapabilityBoundingSet", 0, "CAP_NET_ADMIN",
803fb7
-                              &capability_bounding_set_drop, NULL);
803fb7
-        assert_se(r >= 0);
803fb7
-        assert_se(capability_bounding_set_drop == ~(make_cap(CAP_NET_RAW) | make_cap(CAP_NET_ADMIN)));
803fb7
-
803fb7
-        r = config_parse_bounding_set(NULL, "fake", 1, "section", 1,
803fb7
-                              "CapabilityBoundingSet", 0, "",
803fb7
-                              &capability_bounding_set_drop, NULL);
803fb7
-        assert_se(r >= 0);
803fb7
-        assert_se(capability_bounding_set_drop == ~((uint64_t) 0ULL));
803fb7
-
803fb7
-        r = config_parse_bounding_set(NULL, "fake", 1, "section", 1,
803fb7
-                              "CapabilityBoundingSet", 0, "~",
803fb7
-                              &capability_bounding_set_drop, NULL);
803fb7
-        assert_se(r >= 0);
803fb7
-        assert_se(capability_bounding_set_drop == (uint64_t) 0ULL);
803fb7
-}
803fb7
-
803fb7
 int main(int argc, char *argv[]) {
803fb7
         int r;
803fb7
 
803fb7
@@ -713,8 +720,8 @@ int main(int argc, char *argv[]) {
803fb7
 
803fb7
         r = test_unit_file_get_set();
803fb7
         test_config_parse_exec();
803fb7
+        test_config_parse_capability_set();
803fb7
         test_config_parse_rlimit();
803fb7
-        test_config_parse_bounding_set();
803fb7
         test_load_env_file_1();
803fb7
         test_load_env_file_2();
803fb7
         test_load_env_file_3();