收紧运行目录与管理员本地文件读取边界

This commit is contained in:
xuans committed 2026-09-22 03:26:01 +08:00
1 parent f732a255ce
commit 2dd5156018
5 files changed
+98 -6

No files matched your search

@@ -120,7 +120,12 @@ func findStartCaller() (callerIdentity, error) {
if err != nil || (executable != "/usr/bin/systemctl" && executable != "/bin/systemctl") {
continue
}
data, err := os.ReadFile(filepath.Join(base, "cmdline"))
procRoot, err := os.OpenRoot(base)
if err != nil {
continue
}
data, err := procRoot.ReadFile("cmdline")
_ = procRoot.Close()
if err != nil {
continue
}
@@ -132,7 +137,12 @@ func findStartCaller() (callerIdentity, error) {
if !allowed {
return callerIdentity{}, ErrUnauthorizedPeer
}
status, err := os.ReadFile(filepath.Join(base, "status"))
procRoot, err = os.OpenRoot(base)
if err != nil {
return callerIdentity{}, ErrUnauthorizedPeer
}
status, err := procRoot.ReadFile("status")
_ = procRoot.Close()
if err != nil || !rootProcessStatus(string(status)) {
return callerIdentity{}, ErrUnauthorizedPeer
}