Debian Codegraph @

landlock/restrict_threading_test.go

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