mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
cgroups/fs2/CreateCgroupPath: reinstate check
This check was removed in commit 5406833a65. Now, when this
function is called from a few places, it is no longer obvious
that the path always starts with /sys/fs/cgroup/, so reinstate
the check just to be on the safe side.
This check also ensures that elements[3:] can be used safely.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package fs2
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -11,6 +12,10 @@ import (
|
||||
// CreateCgroupPath creates cgroupv2 path, enabling all the
|
||||
// available controllers in the process.
|
||||
func CreateCgroupPath(path string) (Err error) {
|
||||
if !strings.HasPrefix(path, UnifiedMountpoint) {
|
||||
return fmt.Errorf("invalid cgroup path %s", path)
|
||||
}
|
||||
|
||||
const file = UnifiedMountpoint + "/cgroup.controllers"
|
||||
content, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user