diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-03-13 00:41:37 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-03-13 00:41:37 +0900 |
| commit | 6af8b8859fde3a2b63afee20f004e184896cec3a (patch) | |
| tree | 4dd71b2339231a764070f817b92176f24964e81f | |
| parent | f38ba7e923e9017040c67f290e4d8db29685e3ee (diff) | |
sandbox: read overflow ids
Signed-off-by: Ophestra <cat@gensokyo.uk>
| -rw-r--r-- | internal/sandbox/overflow.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/sandbox/overflow.go b/internal/sandbox/overflow.go new file mode 100644 index 00000000..ebaad704 --- /dev/null +++ b/internal/sandbox/overflow.go @@ -0,0 +1,37 @@ +package sandbox + +import ( + "bytes" + "log" + "os" + "strconv" + "sync" +) + +var ( + ofUid int + ofGid int + ofOnce sync.Once +) + +const ( + ofUidPath = "/proc/sys/kernel/overflowuid" + ofGidPath = "/proc/sys/kernel/overflowgid" +) + +func mustReadOverflow() { + if v, err := os.ReadFile(ofUidPath); err != nil { + log.Fatalf("cannot read %q: %v", ofUidPath, err) + } else if ofUid, err = strconv.Atoi(string(bytes.TrimSpace(v))); err != nil { + log.Fatalf("cannot interpret %q: %v", ofUidPath, err) + } + + if v, err := os.ReadFile(ofGidPath); err != nil { + log.Fatalf("cannot read %q: %v", ofGidPath, err) + } else if ofGid, err = strconv.Atoi(string(bytes.TrimSpace(v))); err != nil { + log.Fatalf("cannot interpret %q: %v", ofGidPath, err) + } +} + +func OverflowUid() int { ofOnce.Do(mustReadOverflow); return ofUid } +func OverflowGid() int { ofOnce.Do(mustReadOverflow); return ofGid } |
