|
| 1 | +From da0f5007529564b9a9d197b576a775b505bfc2af Mon Sep 17 00:00:00 2001 |
| 2 | +From: Akihiro Suda < [email protected]> |
| 3 | +Date: Mon, 27 Oct 2025 16:42:59 +0900 |
| 4 | +Subject: [PATCH] Fix directory permissions |
| 5 | + |
| 6 | +- Create /var/lib/containerd with 0o700 (was: 0o711). |
| 7 | +- Create config.TempDir with 0o700 (was: 0o711). |
| 8 | +- Create /run/containerd/io.containerd.grpc.v1.cri with 0o700 (was: 0o755). |
| 9 | +- Create /run/containerd/io.containerd.sandbox.controller.v1.shim with 0o700 (was: 0o711). |
| 10 | +- Leave /run/containerd and /run/containerd/io.containerd.runtime.v2.task created with 0o711, |
| 11 | + as required by userns-remapped containers. |
| 12 | + /run/containerd/io.containerd.runtime.v2.task/<NS>/<ID> is created with: |
| 13 | + - 0o700 for non-userns-remapped containers |
| 14 | + - 0o710 for userns-remapped containers with the remapped root group as the owner group. |
| 15 | + |
| 16 | +Signed-off-by: AllSpark < [email protected]> |
| 17 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 18 | +Upstream-reference: AI Backport of https://github.com/containerd/containerd/commit/0450f046e6942e513d0ebf1ef5c2aff13daa187f.patch |
| 19 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 20 | +Upstream-reference: https://raw.githubusercontent.com/microsoft/azurelinux/79d629e86579f82f49940591633f4eae98cb0413/SPECS/moby-containerd-cc/CVE-2024-25621.patch |
| 21 | +--- |
| 22 | + pkg/cri/cri.go | 8 ++++++++ |
| 23 | + runtime/v2/manager.go | 2 ++ |
| 24 | + services/server/server.go | 14 ++++++++++++-- |
| 25 | + 3 files changed, 22 insertions(+), 2 deletions(-) |
| 26 | + |
| 27 | +diff --git a/pkg/cri/cri.go b/pkg/cri/cri.go |
| 28 | +index aa57313..55db3a2 100644 |
| 29 | +--- a/pkg/cri/cri.go |
| 30 | ++++ b/pkg/cri/cri.go |
| 31 | +@@ -62,6 +62,14 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) { |
| 32 | + return nil, fmt.Errorf("invalid plugin config: %w", err) |
| 33 | + } |
| 34 | + |
| 35 | ++ if err := os.MkdirAll(ic.State, 0700); err != nil { |
| 36 | ++ return nil, err |
| 37 | ++ } |
| 38 | ++ // chmod is needed for upgrading from an older release that created the dir with 0755 |
| 39 | ++ if err := os.Chmod(ic.State, 0700); err != nil { |
| 40 | ++ return nil, err |
| 41 | ++ } |
| 42 | ++ |
| 43 | + c := criconfig.Config{ |
| 44 | + PluginConfig: *pluginConfig, |
| 45 | + ContainerdRootDir: filepath.Dir(ic.Root), |
| 46 | +diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go |
| 47 | +index 73e1af7..d48ac8f 100644 |
| 48 | +--- a/runtime/v2/manager.go |
| 49 | ++++ b/runtime/v2/manager.go |
| 50 | +@@ -133,6 +133,8 @@ type ManagerConfig struct { |
| 51 | + // NewShimManager creates a manager for v2 shims |
| 52 | + func NewShimManager(ctx context.Context, config *ManagerConfig) (*ShimManager, error) { |
| 53 | + for _, d := range []string{config.Root, config.State} { |
| 54 | ++ // root: the parent of this directory is created as 0700, not 0711. |
| 55 | ++ // state: the parent of this directory is created as 0711 too, so as to support userns-remapped containers. |
| 56 | + if err := os.MkdirAll(d, 0711); err != nil { |
| 57 | + return nil, err |
| 58 | + } |
| 59 | +diff --git a/services/server/server.go b/services/server/server.go |
| 60 | +index 2a548ef..04782bf 100644 |
| 61 | +--- a/services/server/server.go |
| 62 | ++++ b/services/server/server.go |
| 63 | +@@ -76,12 +76,22 @@ func CreateTopLevelDirectories(config *srvconfig.Config) error { |
| 64 | + return err |
| 65 | + } |
| 66 | + |
| 67 | +- if err := sys.MkdirAllWithACL(config.State, 0711); err != nil { |
| 68 | ++ if err := sys.MkdirAllWithACL(config.Root, 0700); err != nil { |
| 69 | ++ return err |
| 70 | ++ } |
| 71 | ++ // chmod is needed for upgrading from an older release that created the dir with 0o711 |
| 72 | ++ if err := os.Chmod(config.Root, 0700); err != nil { |
| 73 | + return err |
| 74 | + } |
| 75 | + |
| 76 | ++ // For supporting userns-remapped containers, the state dir cannot be just mkdired with 0o700. |
| 77 | ++ // Each of plugins creates a dedicated directory beneath the state dir with appropriate permission bits. |
| 78 | + if config.TempDir != "" { |
| 79 | +- if err := sys.MkdirAllWithACL(config.TempDir, 0711); err != nil { |
| 80 | ++ if err := sys.MkdirAllWithACL(config.TempDir, 0700); err != nil { |
| 81 | ++ return err |
| 82 | ++ } |
| 83 | ++ // chmod is needed for upgrading from an older release that created the dir with 0o711 |
| 84 | ++ if err := os.Chmod(config.Root, 0700); err != nil { |
| 85 | + return err |
| 86 | + } |
| 87 | + if runtime.GOOS == "windows" { |
| 88 | +-- |
| 89 | +2.45.4 |
| 90 | + |
0 commit comments