Debian Codegraph @

landlock/syscall/landlock.go

raw
1 // Package syscall provides a low-level interface to the Linux Landlock sandboxing feature.
2 //
3 // The package contains constants and syscall wrappers. The syscall
4 // wrappers whose names start with AllThreads will execute the syscall
5 // on all OS threads belonging to the current process, as long as
6 // these threads have been started implicitly by the Go runtime or
7 // using `pthread_create`.
8 //
9 // This package package is a stopgap solution while there is no
10 // Landlock support in x/sys/unix. The syscall package is considered
11 // highly unstable and may change or disappear without warning.
12 //
13 // The full documentation can be found at
14 // https://www.kernel.org/doc/html/latest/userspace-api/landlock.html.
15 package syscall
16
17 // Landlock filesystem access rights.
18 //
19 // Please see the full documentation at
20 // https://www.kernel.org/doc/html/latest/userspace-api/landlock.html#filesystem-flags.
21 const (
22 AccessFSExecute = 1 << iota
23 AccessFSWriteFile
24 AccessFSReadFile
25 AccessFSReadDir
26 AccessFSRemoveDir
27 AccessFSRemoveFile
28 AccessFSMakeChar
29 AccessFSMakeDir
30 AccessFSMakeReg
31 AccessFSMakeSock
32 AccessFSMakeFifo
33 AccessFSMakeBlock
34 AccessFSMakeSym
35 AccessFSRefer
36 AccessFSTruncate
37 AccessFSIoctlDev
38 AccessFSResolveUnix
39 )
40
41 // Landlock network access rights.
42 //
43 // Please see the full documentation at
44 // https://www.kernel.org/doc/html/latest/userspace-api/landlock.html#network-flags.
45 const (
46 AccessNetBindTCP = 1 << iota
47 AccessNetConnectTCP
48 )
49
50 // Landlock scope flags.
51 //
52 // Please see the full documentation at
53 // https://www.kernel.org/doc/html/latest/userspace-api/landlock.html#scope-flags.
54 const (
55 ScopeAbstractUnixSocket = 1 << iota
56 ScopeSignal
57 )
58
59 // Flags for [AllThreadsLandlockRestrictSelf].
60 //
61 // Please see full documentation at
62 // https://docs.kernel.org/userspace-api/landlock.html#enforcing-a-ruleset
63 const (
64 FlagRestrictSelfLogSameExecOff = 1 << iota
65 FlagRestrictSelfLogNewExecOn
66 FlagRestrictSelfLogSubdomainsOff
67 FlagRestrictSelfTSync
68 )
69
70 // RulesetAttr is the Landlock ruleset definition.
71 //
72 // Argument of LandlockCreateRuleset(). This structure can grow in future versions of Landlock.
73 //
74 // C version is in usr/include/linux/landlock.h
75 type RulesetAttr struct {
76 HandledAccessFS uint64
77 HandledAccessNet uint64
78 Scoped uint64
79 }
80
81 // PathBeneathAttr references a file hierarchy and defines the desired
82 // extent to which it should be usable when the rule is enforced.
83 type PathBeneathAttr struct {
84 // AllowedAccess is a bitmask of allowed actions for this file
85 // hierarchy (cf. "Filesystem flags"). The enabled bits must
86 // be a subset of the bits defined in the ruleset.
87 AllowedAccess uint64
88
89 // ParentFd is a file descriptor, opened with `O_PATH`, which identifies
90 // the parent directory of a file hierarchy, or just a file.
91 ParentFd int
92 }
93
94 // NetPortAttr specifies which ports can be used for what.
95 type NetPortAttr struct {
96 AllowedAccess uint64
97 Port uint64
98 }