]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: forbid walking upwards for confile items that modify cgroup layout
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 15 Feb 2021 15:49:09 +0000 (16:49 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 15 Feb 2021 17:08:56 +0000 (18:08 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c
src/lxc/log.h
src/lxc/string_utils.h

index 2176644c11ac39b74848e04721da40b74733d38d..8153b72bbbcf55556d8378ebbc75bc97507760c8 100644 (file)
@@ -1815,7 +1815,6 @@ static int set_config_cgroup2_controller(const char *key, const char *value,
                                              CGROUP2_SUPER_MAGIC);
 }
 
-
 static int set_config_cgroup_dir(const char *key, const char *value,
                                 struct lxc_conf *lxc_conf, void *data)
 {
@@ -1825,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 (dotdot(value))
+               return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
+
        return set_config_path_item(&lxc_conf->cgroup_meta.dir, value);
 }
 
@@ -1834,6 +1836,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 (dotdot(value))
+               return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
+
        return set_config_path_item(&lxc_conf->cgroup_meta.monitor_dir, value);
 }
 
@@ -1843,6 +1848,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 (dotdot(value))
+               return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
+
        return set_config_path_item(&lxc_conf->cgroup_meta.monitor_pivot_dir, value);
 }
 
@@ -1853,6 +1861,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 (dotdot(value))
+               return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
+
        return set_config_path_item(&lxc_conf->cgroup_meta.container_dir, value);
 }
 
index 6391b5488a8acf68448a947c19998e080577cac4..1f7857582884a0a4b3d61149cc9d38e373a152eb 100644 (file)
@@ -501,6 +501,14 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo,       \
                __internal_ret__;                             \
        })
 
+#define syserrno_set(__ret__, format, ...)                    \
+       ({                                                    \
+               typeof(__ret__) __internal_ret__ = (__ret__); \
+               errno = abs(__ret__);                         \
+               SYSERROR(format, ##__VA_ARGS__);              \
+               __internal_ret__;                             \
+       })
+
 #define log_error(__ret__, format, ...)                       \
        ({                                                    \
                typeof(__ret__) __internal_ret__ = (__ret__); \
index f12879254742752405af2ebbd8ceeecb1a082200..f18f274d6520a136d4afd8731fe2af17f5beb00b 100644 (file)
@@ -140,6 +140,11 @@ static inline bool strequal(const char *str, const char *eq)
        return strcmp(str, eq) == 0;
 }
 
+static inline bool dotdot(const char *str)
+{
+       return !!strstr(str, "..");
+}
+
 #define strnprintf(buf, buf_size, ...)                                            \
        ({                                                                        \
                int __ret_strnprintf;                                             \