init: write sysctls using safe procfs API

sysctls could in principle also be used as a write gadget for arbitrary
procfs files. As this requires getting a non-subset=pid /proc handle we
amortise this by only allocating a single procfs handle for all sysctl
writes.

Fixes: GHSA-cgrx-mc8f-2prm CVE-2025-52881
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai
2025-07-17 11:31:50 +10:00
parent b3dd1bc562
commit 77d217c7c3
3 changed files with 57 additions and 12 deletions
-8
View File
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
@@ -1351,13 +1350,6 @@ func maskPaths(paths []string, mountLabel string) error {
return nil
}
// writeSystemProperty writes the value to a path under /proc/sys as determined from the key.
// For e.g. net.ipv4.ip_forward translated to /proc/sys/net/ipv4/ip_forward.
func writeSystemProperty(key, value string) error {
keyPath := strings.ReplaceAll(key, ".", "/")
return os.WriteFile(path.Join("/proc/sys", keyPath), []byte(value), 0o644)
}
// Do the mount operation followed by additional mounts required to take care
// of propagation flags. This will always be scoped inside the container rootfs.
func mountPropagate(m mountEntry, rootfs string, mountLabel string) error {