diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-02-28 20:18:30 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-02-28 20:18:30 +0900 |
| commit | cd9b534d6b1d432d3c997ccc5b14f630afb9dda6 (patch) | |
| tree | fcf2e26356d614bb081e94285a1a8eb19cb8283c /container/landlock.go | |
| parent | 84e6922f3073ec09756df6075a801529ecd202f6 (diff) | |
container: improve documentation
This change removes inconsistencies collected over time in this package.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/landlock.go')
| -rw-r--r-- | container/landlock.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/container/landlock.go b/container/landlock.go index 7f0a821f..acaab585 100644 --- a/container/landlock.go +++ b/container/landlock.go @@ -38,6 +38,7 @@ const ( _LANDLOCK_ACCESS_FS_DELIM ) +// String returns a space-separated string of [LandlockAccessFS] flags. func (f LandlockAccessFS) String() string { switch f { case LANDLOCK_ACCESS_FS_EXECUTE: @@ -116,6 +117,7 @@ const ( _LANDLOCK_ACCESS_NET_DELIM ) +// String returns a space-separated string of [LandlockAccessNet] flags. func (f LandlockAccessNet) String() string { switch f { case LANDLOCK_ACCESS_NET_BIND_TCP: @@ -152,6 +154,7 @@ const ( _LANDLOCK_SCOPE_DELIM ) +// String returns a space-separated string of [LandlockScope] flags. func (f LandlockScope) String() string { switch f { case LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET: @@ -184,10 +187,12 @@ type RulesetAttr struct { HandledAccessFS LandlockAccessFS // Bitmask of handled network actions. HandledAccessNet LandlockAccessNet - // Bitmask of scopes restricting a Landlock domain from accessing outside resources (e.g. IPCs). + // Bitmask of scopes restricting a Landlock domain from accessing outside + // resources (e.g. IPCs). Scoped LandlockScope } +// String returns a user-facing description of [RulesetAttr]. func (rulesetAttr *RulesetAttr) String() string { if rulesetAttr == nil { return "NULL" @@ -208,6 +213,7 @@ func (rulesetAttr *RulesetAttr) String() string { return strings.Join(elems, ", ") } +// Create loads the ruleset into the kernel. func (rulesetAttr *RulesetAttr) Create(flags uintptr) (fd int, err error) { var pointer, size uintptr // NULL needed for abi version @@ -216,10 +222,13 @@ func (rulesetAttr *RulesetAttr) Create(flags uintptr) (fd int, err error) { size = unsafe.Sizeof(*rulesetAttr) } - rulesetFd, _, errno := syscall.Syscall(std.SYS_LANDLOCK_CREATE_RULESET, pointer, size, flags) + rulesetFd, _, errno := syscall.Syscall( + std.SYS_LANDLOCK_CREATE_RULESET, + pointer, size, + flags, + ) fd = int(rulesetFd) err = errno - if fd < 0 { return } @@ -230,12 +239,19 @@ func (rulesetAttr *RulesetAttr) Create(flags uintptr) (fd int, err error) { return fd, nil } +// LandlockGetABI returns the ABI version supported by the kernel. func LandlockGetABI() (int, error) { return (*RulesetAttr)(nil).Create(LANDLOCK_CREATE_RULESET_VERSION) } +// LandlockRestrictSelf applies a loaded ruleset to the calling thread. func LandlockRestrictSelf(rulesetFd int, flags uintptr) error { - r, _, errno := syscall.Syscall(std.SYS_LANDLOCK_RESTRICT_SELF, uintptr(rulesetFd), flags, 0) + r, _, errno := syscall.Syscall( + std.SYS_LANDLOCK_RESTRICT_SELF, + uintptr(rulesetFd), + flags, + 0, + ) if r != 0 { return errno } |
