diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-10-28 18:52:23 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-10-28 18:52:23 +0900 |
| commit | aa1f96eeebecaa8e4cbbccb826fe168c9270228d (patch) | |
| tree | 7bc64b31f4e5723d603f44b993427edce305626b /cmd/fsu/main.go | |
| parent | 431dc095e53b64d33ec4c47aedf3082ec8cffe80 (diff) | |
fsu: check parent executable path
Only allow main program to launch fsu. This change and further checks in the main program reduces attack surface.
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'cmd/fsu/main.go')
| -rw-r--r-- | cmd/fsu/main.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/cmd/fsu/main.go b/cmd/fsu/main.go index 99c25c9d..af0315ea 100644 --- a/cmd/fsu/main.go +++ b/cmd/fsu/main.go @@ -35,11 +35,20 @@ func main() { log.Fatal("this program must not be started by root") } - // check compiled in fortify path + // validate compiled in fortify path if FortifyPath == fpPoison || !path.IsAbs(FortifyPath) { log.Fatal("invalid fortify path, this copy of fsu is not compiled correctly") } + pexe := path.Join("/proc", strconv.Itoa(os.Getppid()), "exe") + if p, err := os.Readlink(pexe); err != nil { + log.Fatalf("cannot read parent executable path: %v", err) + } else if strings.HasSuffix(p, " (deleted)") { + log.Fatal("fortify executable has been deleted") + } else if p != FortifyPath { + log.Fatal("this program must be started by fortify") + } + // uid = 1000000 + // fid * 10000 + // aid |
