Add Landlock sandboxing and NoNewPrivs to SysProcAttr on Linux
On Linux, programs that run untrusted work through os/exec often want the child process to have fewer privileges than the parent. For example, a server might run git on untrusted repositories and want git to touch only one temporary directory. Landlock is a Linux kernel feature that restricts file access. Until now, Go had no safe way to apply it to a child process only, because forking manually is hard with Go's threaded runtime.
The proposal adds new fields to syscall.SysProcAttr on Linux. When UseLandlock is set, the child calls landlock_restrict_self(LandlockFD, LandlockFlags) before exec. LandlockFD is a ruleset file descriptor, which can come from a library such as go-landlock. A new NoNewPrivs field calls prctl(PR_SET_NO_NEW_PRIVS) before exec.
cmd := exec.Command("git", "clone", url, tmpDir)
cmd.SysProcAttr = &syscall.SysProcAttr{
NoNewPrivs: true,
UseLandlock: true,
LandlockFD: rulesetFD, // e.g. allows only /usr (read) and tmpDir (read-write)
}
err := cmd.Run()
- Proposal
- #68595 by edigaryev
- Status
- Implemented on Aug 17, 2026
- Release
- Go 1.28
- Impact
- low
- Area
- syscall