aboutsummaryrefslogtreecommitdiffhomepage
path: root/helper/bwrap/seccomp.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-02-13 23:15:34 +0900
committerOphestra <cat@gensokyo.uk>2025-02-13 23:34:15 +0900
commitfe7d208cf76fa6f24bb9d12ba29b5ed61d837ce3 (patch)
treecac02af50a13b2078739a8f5a74d219f3b60833d /helper/bwrap/seccomp.go
parent60c287375048b21eab2bd82f1e7d43e36dcfb3a2 (diff)
helper: use generic extra files interface
This replaces the pipes object and integrates context into helper process lifecycle. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'helper/bwrap/seccomp.go')
-rw-r--r--helper/bwrap/seccomp.go52
1 files changed, 24 insertions, 28 deletions
diff --git a/helper/bwrap/seccomp.go b/helper/bwrap/seccomp.go
index 860d720b..d6f34dfe 100644
--- a/helper/bwrap/seccomp.go
+++ b/helper/bwrap/seccomp.go
@@ -2,8 +2,9 @@ package bwrap
import (
"fmt"
- "os"
+ "strconv"
+ "git.gensokyo.uk/security/fortify/helper/proc"
"git.gensokyo.uk/security/fortify/helper/seccomp"
"git.gensokyo.uk/security/fortify/internal/fmsg"
)
@@ -23,35 +24,13 @@ type SyscallPolicy struct {
Bluetooth bool `json:"bluetooth"`
}
-type seccompBuilder struct {
- config *Config
-}
-
-func (s *seccompBuilder) Len() int {
- if s == nil {
- return 0
- }
- return 2
-}
-
-func (s *seccompBuilder) Append(args *[]string, extraFiles *[]*os.File) error {
- if s == nil {
- return nil
- }
- if f, err := s.config.resolveSeccomp(); err != nil {
- return err
- } else {
- extraFile(args, extraFiles, positionalArgs[Seccomp], f)
- return nil
- }
-}
-
-func (c *Config) resolveSeccomp() (*os.File, error) {
+func (c *Config) seccompArgs() FDBuilder {
+ // explicitly disable syscall filter
if c.Syscall == nil {
- return nil, nil
+ // nil File skips builder
+ return new(seccompBuilder)
}
- // resolve seccomp filter opts
var (
opts seccomp.SyscallOpts
optd []string
@@ -86,5 +65,22 @@ func (c *Config) resolveSeccomp() (*os.File, error) {
seccomp.CPrintln(fmt.Sprintf("seccomp flags: %s", optd))
}
- return seccomp.Export(opts)
+ return &seccompBuilder{seccomp.NewFile(opts)}
+}
+
+type seccompBuilder struct{ proc.File }
+
+func (s *seccompBuilder) Len() int {
+ if s == nil || s.File == nil {
+ return 0
+ }
+ return 2
+}
+
+func (s *seccompBuilder) Append(args *[]string) {
+ if s == nil || s.File == nil {
+ return
+ }
+
+ *args = append(*args, positionalArgs[Seccomp], strconv.Itoa(int(s.Fd())))
}