|
| 1 | +From 808ae14e2da379e517298396c2242e07d37503ad Mon Sep 17 00:00:00 2001 |
| 2 | +From: AllSpark < [email protected]> |
| 3 | +Date: Tue, 11 Nov 2025 11:41:09 +0000 |
| 4 | +Subject: [PATCH] Fix directory permissions: make root and tempdir 0o700 with |
| 5 | + chmod adjustments; keep state at 0o711 for userns; add comments in v2 |
| 6 | + manager; |
| 7 | + |
| 8 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 9 | +Upstream-reference: AI Backport of https://github.com/containerd/containerd/commit/0450f046e6942e513d0ebf1ef5c2aff13daa187f.patch |
| 10 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 11 | +Upstream-reference: https://raw.githubusercontent.com/microsoft/azurelinux/22d76f85edefac1f144ba78ea3b2e4529a238491/SPECS/moby-containerd/CVE-2024-25621.patch |
| 12 | +--- |
| 13 | + pkg/cri/cri.go | 8 ++++++++ |
| 14 | + runtime/v2/manager.go | 2 ++ |
| 15 | + services/server/server.go | 14 ++++++++++++-- |
| 16 | + 3 files changed, 22 insertions(+), 2 deletions(-) |
| 17 | + |
| 18 | +diff --git a/pkg/cri/cri.go b/pkg/cri/cri.go |
| 19 | +index 59861ed..dee6988 100644 |
| 20 | +--- a/pkg/cri/cri.go |
| 21 | ++++ b/pkg/cri/cri.go |
| 22 | +@@ -19,6 +19,7 @@ package cri |
| 23 | + import ( |
| 24 | + "flag" |
| 25 | + "fmt" |
| 26 | ++ "os" |
| 27 | + "path/filepath" |
| 28 | + |
| 29 | + imagespec "github.com/opencontainers/image-spec/specs-go/v1" |
| 30 | +@@ -79,6 +80,13 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) { |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | ++ if err := os.MkdirAll(ic.State, 0700); err != nil { |
| 35 | ++ return nil, err |
| 36 | ++ } |
| 37 | ++ // chmod is needed for upgrading from an older release that created the dir with 0755 |
| 38 | ++ if err := os.Chmod(ic.State, 0700); err != nil { |
| 39 | ++ return nil, err |
| 40 | ++ } |
| 41 | + c := criconfig.Config{ |
| 42 | + PluginConfig: *pluginConfig, |
| 43 | + ContainerdRootDir: filepath.Dir(ic.Root), |
| 44 | +diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go |
| 45 | +index 1927cbb..1f26bbe 100644 |
| 46 | +--- a/runtime/v2/manager.go |
| 47 | ++++ b/runtime/v2/manager.go |
| 48 | +@@ -109,6 +109,8 @@ type ManagerConfig struct { |
| 49 | + // NewShimManager creates a manager for v2 shims |
| 50 | + func NewShimManager(ctx context.Context, config *ManagerConfig) (*ShimManager, error) { |
| 51 | + for _, d := range []string{config.Root, config.State} { |
| 52 | ++ // root: the parent of this directory is created as 0700, not 0711. |
| 53 | ++ // state: the parent of this directory is created as 0711 too, so as to support userns-remapped containers. |
| 54 | + if err := os.MkdirAll(d, 0711); err != nil { |
| 55 | + return nil, err |
| 56 | + } |
| 57 | +diff --git a/services/server/server.go b/services/server/server.go |
| 58 | +index c2b504c..e707ae4 100644 |
| 59 | +--- a/services/server/server.go |
| 60 | ++++ b/services/server/server.go |
| 61 | +@@ -86,16 +86,26 @@ func CreateTopLevelDirectories(config *srvconfig.Config) error { |
| 62 | + return errors.New("root and state must be different paths") |
| 63 | + } |
| 64 | + |
| 65 | +- if err := sys.MkdirAllWithACL(config.Root, 0711); err != nil { |
| 66 | ++ if err := sys.MkdirAllWithACL(config.Root, 0700); err != nil { |
| 67 | ++ return err |
| 68 | ++ } |
| 69 | ++ // chmod is needed for upgrading from an older release that created the dir with 0o711 |
| 70 | ++ if err := os.Chmod(config.Root, 0700); err != nil { |
| 71 | + return err |
| 72 | + } |
| 73 | + |
| 74 | ++ // For supporting userns-remapped containers, the state dir cannot be just mkdired with 0o700. |
| 75 | ++ // Each of plugins creates a dedicated directory beneath the state dir with appropriate permission bits. |
| 76 | + if err := sys.MkdirAllWithACL(config.State, 0711); err != nil { |
| 77 | + return err |
| 78 | + } |
| 79 | + |
| 80 | + if config.TempDir != "" { |
| 81 | +- if err := sys.MkdirAllWithACL(config.TempDir, 0711); err != nil { |
| 82 | ++ if err := sys.MkdirAllWithACL(config.TempDir, 0700); err != nil { |
| 83 | ++ return err |
| 84 | ++ } |
| 85 | ++ // chmod is needed for upgrading from an older release that created the dir with 0o711 |
| 86 | ++ if err := os.Chmod(config.Root, 0700); err != nil { |
| 87 | + return err |
| 88 | + } |
| 89 | + if runtime.GOOS == "windows" { |
| 90 | +-- |
| 91 | +2.45.4 |
| 92 | + |
0 commit comments