Debian Codegraph @

landlock/bug39_workaround.go

raw
1 //go:build linux && cgo && !landlocktsync
2
3 package landlock
4
5 import (
6 "fmt"
7 "os"
8
9 "github.com/landlock-lsm/go-landlock/landlock/syscall"
10 )
11
12 // maybeWorkaroundBug39 adds an extra rule in the case that we are
13 // affected by https://github.com/landlock-lsm/go-landlock/issues/39.
14 //
15 // libpsx 1.2.72+ attempts to list the directory /proc/$PID/task, just
16 // after doing the Landlock enforcement system call on each thread.
17 // We are silently adding that directory so that the enforcement will
18 // return a success.
19 func maybeWorkaroundBug39(c Config, rules []Rule) []Rule {
20 const readDir = syscall.AccessFSReadDir
21 if c.handledAccessFS.intersect(readDir).isEmpty() {
22 return rules
23 }
24 path := fmt.Sprintf("/proc/%v/task", os.Getpid())
25 extraRule := PathAccess(readDir, path)
26 return append(rules, extraRule)
27 }