diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-07-01 20:23:33 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-07-01 22:11:32 +0900 |
| commit | 1a8840bebc673672235b6e10b1b9386f24751757 (patch) | |
| tree | d1e6772bfd685e2162d047e3640bd3ee55c1a1f7 /sandbox/seccomp/api.go | |
| parent | 1fb453dffe4c83866fedfa4590be30ec65e815ff (diff) | |
sandbox/seccomp: resolve rules natively
This enables loading syscall filter policies from external cross-platform config files.
This also removes a significant amount of C code.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'sandbox/seccomp/api.go')
| -rw-r--r-- | sandbox/seccomp/api.go | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/sandbox/seccomp/api.go b/sandbox/seccomp/api.go deleted file mode 100644 index 81fb68cf..00000000 --- a/sandbox/seccomp/api.go +++ /dev/null @@ -1,76 +0,0 @@ -package seccomp - -import ( - "context" - "errors" - "syscall" - - "git.gensokyo.uk/security/hakurei/helper/proc" -) - -const ( - PresetStrict = FilterExt | FilterDenyNS | FilterDenyTTY | FilterDenyDevel - PresetCommon = PresetStrict | FilterMultiarch -) - -// New returns an inactive Encoder instance. -func New(opts FilterOpts) *Encoder { return &Encoder{newExporter(opts)} } - -// Load loads a filter into the kernel. -func Load(opts FilterOpts) error { return buildFilter(-1, opts) } - -/* -An Encoder writes a BPF program to an output stream. - -Methods of Encoder are not safe for concurrent use. - -An Encoder must not be copied after first use. -*/ -type Encoder struct { - *exporter -} - -func (e *Encoder) Read(p []byte) (n int, err error) { - if err = e.prepare(); err != nil { - return - } - return e.r.Read(p) -} - -func (e *Encoder) Close() error { - if e.r == nil { - return syscall.EINVAL - } - - // this hangs if the cgo thread fails to exit - return errors.Join(e.closeWrite(), <-e.exportErr) -} - -// NewFile returns an instance of exporter implementing [proc.File]. -func NewFile(opts FilterOpts) proc.File { return &File{opts: opts} } - -// File implements [proc.File] and provides access to the read end of exporter pipe. -type File struct { - opts FilterOpts - proc.BaseFile -} - -func (f *File) ErrCount() int { return 2 } -func (f *File) Fulfill(ctx context.Context, dispatchErr func(error)) error { - e := newExporter(f.opts) - if err := e.prepare(); err != nil { - return err - } - f.Set(e.r) - go func() { - select { - case err := <-e.exportErr: - dispatchErr(nil) - dispatchErr(err) - case <-ctx.Done(): - dispatchErr(e.closeWrite()) - dispatchErr(<-e.exportErr) - } - }() - return nil -} |
