|
@@ -230,12 +230,39 @@ func (m *Manager) GetPids() ([]int, error) {
|
|
return cgroups.GetPids(dir)
|
|
return cgroups.GetPids(dir)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// pathClean makes a path safe for use with filepath.Join. This is done by not
|
|
|
|
+// only cleaning the path, but also (if the path is relative) adding a leading
|
|
|
|
+// '/' and cleaning it (then removing the leading '/'). This ensures that a
|
|
|
|
+// path resulting from prepending another path will always resolve to lexically
|
|
|
|
+// be a subdirectory of the prefixed path. This is all done lexically, so paths
|
|
|
|
+// that include symlinks won't be safe as a result of using pathClean.
|
|
|
|
+func pathClean(path string) string {
|
|
|
|
+ // Ensure that all paths are cleaned (especially problematic ones like
|
|
|
|
+ // "/../../../../../" which can cause lots of issues).
|
|
|
|
+ path = filepath.Clean(path)
|
|
|
|
+
|
|
|
|
+ // If the path isn't absolute, we need to do more processing to fix paths
|
|
|
|
+ // such as "../../../../<etc>/some/path". We also shouldn't convert absolute
|
|
|
|
+ // paths to relative ones.
|
|
|
|
+ if !filepath.IsAbs(path) {
|
|
|
|
+ path = filepath.Clean(string(os.PathSeparator) + path)
|
|
|
|
+ // This can't fail, as (by definition) all paths are relative to root.
|
|
|
|
+ path, _ = filepath.Rel(string(os.PathSeparator), path)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Clean the path again for good measure.
|
|
|
|
+ return filepath.Clean(path)
|
|
|
|
+}
|
|
|
|
+
|
|
func getCgroupData(c *configs.Cgroup, pid int) (*cgroupData, error) {
|
|
func getCgroupData(c *configs.Cgroup, pid int) (*cgroupData, error) {
|
|
root, err := getCgroupRoot()
|
|
root, err := getCgroupRoot()
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Clean the parent slice path.
|
|
|
|
+ c.Parent = pathClean(c.Parent)
|
|
|
|
+
|
|
return &cgroupData{
|
|
return &cgroupData{
|
|
root: root,
|
|
root: root,
|
|
parent: c.Parent,
|
|
parent: c.Parent,
|