test(runner): verify sandbox isolation with a hostile program suite
This commit is contained in:
1 parent
afee564bf4
commit
e858280d91
38 files changed
+1359
-168
No files matched your search
+24
@@ -0,0 +1,24 @@
|
||||
// Isolation probe: the program is not root and cannot become root, change
|
||||
// ownership to root, or raise its limits.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ok := os.Getuid() != 0 && os.Geteuid() != 0 && os.Getgid() != 0 && os.Getegid() != 0
|
||||
ok = ok && syscall.Setuid(0) != nil && syscall.Setgid(0) != nil
|
||||
if err := os.WriteFile("/tmp/owned", nil, 0o600); err == nil {
|
||||
ok = ok && os.Chown("/tmp/owned", 0, 0) != nil
|
||||
}
|
||||
limit := syscall.Rlimit{Cur: 1 << 40, Max: 1 << 40}
|
||||
ok = ok && syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit) != nil
|
||||
if ok {
|
||||
fmt.Println("unprivileged")
|
||||
return
|
||||
}
|
||||
fmt.Println("privileged")
|
||||
}
|
||||
Reference in new issue
Block a user