diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-04-29 19:15:30 -0300 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-04-30 08:36:01 -0300 |
commit | 5954c07433b134694256b9989f2ad3f85a643976 (patch) | |
tree | 199057819796d79598ee974a8a12101d49ff222a /src/shared | |
parent | aa96c6cb44a6eeccc506ae055aae2519a7f914e1 (diff) |
cgroup: do not allow manipulating the cgroup path of units within the systemd:/system subtree
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/cgroup-util.c | 18 | ||||
-rw-r--r-- | src/shared/cgroup-util.h | 15 |
2 files changed, 29 insertions, 4 deletions
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 46a8128eb4..016080f65b 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -916,6 +916,7 @@ int cg_is_empty_recursive(const char *controller, const char *path, bool ignore_ int cg_split_spec(const char *spec, char **controller, char **path) { const char *e; char *t = NULL, *u = NULL; + _cleanup_free_ char *v = NULL; assert(spec); @@ -928,6 +929,7 @@ int cg_split_spec(const char *spec, char **controller, char **path) { if (!t) return -ENOMEM; + path_kill_slashes(t); *path = t; } @@ -943,7 +945,7 @@ int cg_split_spec(const char *spec, char **controller, char **path) { return -EINVAL; if (controller) { - t = strdup(spec); + t = strdup(normalize_controller(spec)); if (!t) return -ENOMEM; @@ -956,7 +958,10 @@ int cg_split_spec(const char *spec, char **controller, char **path) { return 0; } - t = strndup(spec, e-spec); + v = strndup(spec, e-spec); + if (!v) + return -ENOMEM; + t = strdup(normalize_controller(v)); if (!t) return -ENOMEM; if (!cg_controller_is_valid(t, true)) { @@ -969,12 +974,15 @@ int cg_split_spec(const char *spec, char **controller, char **path) { free(t); return -ENOMEM; } - if (!path_is_safe(u)) { + if (!path_is_safe(u) || + !path_is_absolute(u)) { free(t); free(u); return -EINVAL; } + path_kill_slashes(u); + if (controller) *controller = t; else @@ -993,7 +1001,6 @@ int cg_join_spec(const char *controller, const char *path, char **spec) { assert(path); - if (!controller) controller = "systemd"; else { @@ -1010,6 +1017,8 @@ int cg_join_spec(const char *controller, const char *path, char **spec) { if (!s) return -ENOMEM; + path_kill_slashes(s + strlen(controller) + 1); + *spec = s; return 0; } @@ -1029,6 +1038,7 @@ int cg_mangle_path(const char *path, char **result) { if (!t) return -ENOMEM; + path_kill_slashes(t); *result = t; return 0; } diff --git a/src/shared/cgroup-util.h b/src/shared/cgroup-util.h index a2ee72d67f..7bd02c1008 100644 --- a/src/shared/cgroup-util.h +++ b/src/shared/cgroup-util.h @@ -28,6 +28,21 @@ #include "set.h" #include "def.h" +/* + * General rules: + * + * We accept named hierarchies in the syntax "foo" and "name=foo". + * + * We expect that named hierarchies do not conflict in name with a + * kernel hierarchy, modulo the "name=" prefix. + * + * We always generate "normalized" controller names, i.e. without the + * "name=" prefix. + * + * We require absolute cgroup paths. When returning, we will always + * generate paths with multiple adjacent / removed. + */ + int cg_enumerate_processes(const char *controller, const char *path, FILE **_f); int cg_enumerate_tasks(const char *controller, const char *path, FILE **_f); int cg_read_pid(FILE *f, pid_t *_pid); |