From b426e9b76b44e4a19f0b64244be2061ed11e4bdc Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 25 Oct 2023 15:02:10 -0700 Subject: [PATCH] libct/cgroups.OpenFile: clean "file" argument This prevents potential exploit of using "../" in cgroups.OpenFile (as well as other methods that use OpenFile) to read or write to other cgroups. Signed-off-by: Kir Kolyshkin (cherry picked from commit 2c9598c88638b529b032eac4bd480b7600c13785) Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/file.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libcontainer/cgroups/file.go b/libcontainer/cgroups/file.go index 0cdaf7478..48b263a16 100644 --- a/libcontainer/cgroups/file.go +++ b/libcontainer/cgroups/file.go @@ -10,6 +10,7 @@ import ( "strings" "sync" + "github.com/opencontainers/runc/libcontainer/utils" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" ) @@ -122,7 +123,7 @@ func openFile(dir, file string, flags int) (*os.File, error) { flags |= os.O_TRUNC | os.O_CREATE mode = 0o600 } - path := path.Join(dir, file) + path := path.Join(dir, utils.CleanPath(file)) if prepareOpenat2() != nil { return openFallback(path, flags, mode) }