1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
//go:build linux
package landlock_test
import (
"sync"
"testing"
"github.com/landlock-lsm/go-landlock/landlock"
"github.com/landlock-lsm/go-landlock/landlock/lltest"
)
// Verify that Landlock applies to all system threads that belong to
// the current Go process. The raw landlock_restrict_self syscall only
// applies to the current system thread, but these are managed by the
// Go runtime and not easily controlled. The same issue has already
// been discussed in the context of seccomp at
// https://github.com/golang/go/issues/3405.
func TestRestrictInPresenceOfThreading(t *testing.T) {
lltest.RunInSubprocess(t, func() {
lltest.RequireABI(t, 1)
fpath := MakeSomeFile(t)
err := landlock.V1.RestrictPaths() // No access permitted at all.
if err != nil {
t.Skipf("kernel does not support Landlock v1; tests cannot be run.")
}
var wg sync.WaitGroup
defer wg.Wait()
const (
parallelism = 3
attempts = 10
)
for g := 0; g < parallelism; g++ {
wg.Add(1)
go func(grIdx int) {
defer wg.Done()
for i := 0; i < attempts; i++ {
if err := openForRead(fpath); err == nil {
t.Errorf("openForRead(%q) successful, want error", fpath)
}
}
}(g)
}
})
}
|