aboutsummaryrefslogtreecommitdiffhomepage
path: root/container
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-07-06 02:14:35 +0900
committerOphestra <cat@gensokyo.uk>2025-07-06 02:14:35 +0900
commit356b42a406efbdef63bb040e32c7b73b4bd86b3d (patch)
tree97488e447aa777e2e72f5429ae40dbf0be708c10 /container
parentd9b6d48e7c1ea8fea8d8f6598b67d4e47938f052 (diff)
container/init: use /proc/self as intermediate
Setting up via /tmp is okay, /proc/self/fd makes a lot more sense though for reasons described in the comment. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container')
-rw-r--r--container/init.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/container/init.go b/container/init.go
index 8fc8e223..aa920012 100644
--- a/container/init.go
+++ b/container/init.go
@@ -20,8 +20,21 @@ const (
// time to wait for linger processes after death of initial process
residualProcessTimeout = 5 * time.Second
- // intermediate tmpfs mount point
- basePath = "/tmp"
+ /* intermediate tmpfs mount point
+
+ this path might seem like a weird choice, however there are many good reasons to use it:
+ - the contents of this path is never exposed to the container:
+ the tmpfs root established here effectively becomes anonymous after pivot_root
+ - it is safe to assume this path exists and is a directory:
+ this program will not work correctly without a proper /proc and neither will most others
+ - this path belongs to the container init:
+ the container init is not any more privileged or trusted than the rest of the container
+ - this path is only accessible by init and root:
+ the container init sets SUID_DUMP_DISABLE and terminates if that fails;
+
+ it should be noted that none of this should become relevant at any point since the resulting
+ intermediate root tmpfs should be effectively anonymous */
+ intermediateHostPath = "/proc/self/fd"
// setup params file descriptor
setupEnv = "HAKUREI_SETUP"
@@ -124,10 +137,10 @@ func Init(prepare func(prefix string), setVerbose func(verbose bool)) {
}
}
- if err := Mount("rootfs", basePath, "tmpfs", MS_NODEV|MS_NOSUID, ""); err != nil {
+ if err := Mount("rootfs", intermediateHostPath, "tmpfs", MS_NODEV|MS_NOSUID, ""); err != nil {
log.Fatalf("cannot mount intermediate root: %v", err)
}
- if err := os.Chdir(basePath); err != nil {
+ if err := os.Chdir(intermediateHostPath); err != nil {
log.Fatalf("cannot enter base path: %v", err)
}
@@ -141,8 +154,8 @@ func Init(prepare func(prefix string), setVerbose func(verbose bool)) {
if err := os.Mkdir(hostDir, 0755); err != nil {
log.Fatalf("%v", err)
}
- // pivot_root uncovers basePath in hostDir
- if err := PivotRoot(basePath, hostDir); err != nil {
+ // pivot_root uncovers intermediateHostPath in hostDir
+ if err := PivotRoot(intermediateHostPath, hostDir); err != nil {
log.Fatalf("cannot pivot into intermediate root: %v", err)
}
if err := os.Chdir("/"); err != nil {