]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: forbid absolute paths in config items that modify the cgroup layout 3674/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 15 Feb 2021 16:02:55 +0000 (17:02 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 15 Feb 2021 17:08:56 +0000 (18:08 +0100)
This is not a safety measure but merely is supposed to raise awareness that
these paths are always relative to the cgroup root as determined by
lxc.cgroup.relative.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c
src/lxc/string_utils.h

index 8153b72bbbcf55556d8378ebbc75bc97507760c8..880c1c55c4a97aed07f27032f13140377161c753 100644 (file)
@@ -1824,6 +1824,9 @@ static int set_config_cgroup_dir(const char *key, const char *value,
        if (lxc_config_value_empty(value))
                return clr_config_cgroup_dir(key, lxc_conf, NULL);
 
+       if (abspath(value))
+               return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
+
        if (dotdot(value))
                return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
 
@@ -1836,6 +1839,9 @@ static int set_config_cgroup_monitor_dir(const char *key, const char *value,
        if (lxc_config_value_empty(value))
                return clr_config_cgroup_monitor_dir(key, lxc_conf, NULL);
 
+       if (abspath(value))
+               return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
+
        if (dotdot(value))
                return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
 
@@ -1848,6 +1854,9 @@ static int set_config_cgroup_monitor_pivot_dir(const char *key, const char *valu
        if (lxc_config_value_empty(value))
                return clr_config_cgroup_monitor_pivot_dir(key, lxc_conf, NULL);
 
+       if (abspath(value))
+               return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
+
        if (dotdot(value))
                return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
 
@@ -1861,6 +1870,9 @@ static int set_config_cgroup_container_dir(const char *key, const char *value,
        if (lxc_config_value_empty(value))
                return clr_config_cgroup_container_dir(key, lxc_conf, NULL);
 
+       if (abspath(value))
+               return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
+
        if (dotdot(value))
                return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
 
@@ -1875,6 +1887,9 @@ static int set_config_cgroup_container_inner_dir(const char *key,
        if (lxc_config_value_empty(value))
                return clr_config_cgroup_container_inner_dir(key, lxc_conf, NULL);
 
+       if (abspath(value))
+               return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
+
        if (strchr(value, '/') || strequal(value, ".") || strequal(value, ".."))
                return log_error_errno(-EINVAL, EINVAL, "lxc.cgroup.dir.container.inner must be a single directory name");
 
index f18f274d6520a136d4afd8731fe2af17f5beb00b..6cf23d186425aee0d4ca722bbeff0ecd0e779090 100644 (file)
@@ -145,6 +145,11 @@ static inline bool dotdot(const char *str)
        return !!strstr(str, "..");
 }
 
+static inline bool abspath(const char *str)
+{
+       return *str == '/';
+}
+
 #define strnprintf(buf, buf_size, ...)                                            \
        ({                                                                        \
                int __ret_strnprintf;                                             \