confile: forbid absolute paths in config items that modify the cgroup layout

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: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 0a48ee66
...@@ -1824,6 +1824,9 @@ static int set_config_cgroup_dir(const char *key, const char *value, ...@@ -1824,6 +1824,9 @@ static int set_config_cgroup_dir(const char *key, const char *value,
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_cgroup_dir(key, lxc_conf, NULL); 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)) if (dotdot(value))
return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key); 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, ...@@ -1836,6 +1839,9 @@ static int set_config_cgroup_monitor_dir(const char *key, const char *value,
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_cgroup_monitor_dir(key, lxc_conf, NULL); 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)) if (dotdot(value))
return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key); 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 ...@@ -1848,6 +1854,9 @@ static int set_config_cgroup_monitor_pivot_dir(const char *key, const char *valu
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_cgroup_monitor_pivot_dir(key, lxc_conf, NULL); 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)) if (dotdot(value))
return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key); 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, ...@@ -1861,6 +1870,9 @@ static int set_config_cgroup_container_dir(const char *key, const char *value,
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_cgroup_container_dir(key, lxc_conf, NULL); 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)) if (dotdot(value))
return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key); 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, ...@@ -1875,6 +1887,9 @@ static int set_config_cgroup_container_inner_dir(const char *key,
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_cgroup_container_inner_dir(key, lxc_conf, NULL); 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, "..")) if (strchr(value, '/') || strequal(value, ".") || strequal(value, ".."))
return log_error_errno(-EINVAL, EINVAL, "lxc.cgroup.dir.container.inner must be a single directory name"); return log_error_errno(-EINVAL, EINVAL, "lxc.cgroup.dir.container.inner must be a single directory name");
......
...@@ -145,6 +145,11 @@ static inline bool dotdot(const char *str) ...@@ -145,6 +145,11 @@ static inline bool dotdot(const char *str)
return !!strstr(str, ".."); return !!strstr(str, "..");
} }
static inline bool abspath(const char *str)
{
return *str == '/';
}
#define strnprintf(buf, buf_size, ...) \ #define strnprintf(buf, buf_size, ...) \
({ \ ({ \
int __ret_strnprintf; \ int __ret_strnprintf; \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment