landlock-lsm / go-landlock

A Go library for the Linux Landlock sandboxing feature
MIT License
105 stars 7 forks source link

RestrictPaths needs to apply to all OS threads and Goroutines at once #5

Closed gnoack closed 2 years ago

gnoack commented 2 years ago

The mapping of Goroutines to system threads is managed by the Go runtime and even at the start of main() you don't get the guarantee that there is only one OS thread active. (In fact, even the GC uses Goroutines, so it's clear to see this is difficult to guarantee.)

The same problem has already been discussed in the context of seccomp(2), which has the same semantics: https://github.com/golang/go/issues/3405 @AndrewGMorgan is pointing to syscall.AllThreadsSyscall() as a way to apply a syscall to all Go-managed OS threads at once.

AndrewGMorgan commented 2 years ago

Note, that syscall.AllThreadsSyscall() is disabled if CGo is enabled. For both with and without CGo I have developed the package: psx. If CGO_ENABLED=0 this package redirects to syscall.AllThreadsSyscall(), but if CGO_ENABLED=1 it uses libpsx.