aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-11-05 04:48:05 +0900
committerOphestra <cat@gensokyo.uk>2025-11-05 04:48:05 +0900
commitbecaf8b6d7151971907ff65f338afa038f021c92 (patch)
tree4130439807baa92b11d85ad1199d0f2f5e27f001
parent54c0d6bf48fdfade3aaf7741ec3d3cbc302c8b82 (diff)
std: relocate seccomp lookup tables
This should enable resolving NativeRule in hst. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--container/landlock.go6
-rw-r--r--container/seccomp/libseccomp.go3
-rw-r--r--container/seccomp/presets.go26
-rw-r--r--container/seccomp/presets_amd64_test.go (renamed from container/seccomp/hash_amd64_test.go)0
-rw-r--r--container/seccomp/presets_arm64_test.go (renamed from container/seccomp/hash_arm64_test.go)0
-rw-r--r--container/seccomp/presets_test.go (renamed from container/seccomp/hash_test.go)0
-rw-r--r--container/seccomp/syscall_test.go10
-rwxr-xr-xcontainer/std/mksysnum_linux.pl (renamed from container/seccomp/mksysnum_linux.pl)2
-rw-r--r--container/std/pnr.go (renamed from container/seccomp/pnr.go)2
-rw-r--r--container/std/syscall.go (renamed from container/seccomp/syscall.go)2
-rw-r--r--container/std/syscall_extra_linux_amd64.go (renamed from container/seccomp/syscall_extra_linux_amd64.go)2
-rw-r--r--container/std/syscall_extra_linux_arm64.go (renamed from container/seccomp/syscall_extra_linux_arm64.go)2
-rw-r--r--container/std/syscall_linux_amd64.go (renamed from container/seccomp/syscall_linux_amd64.go)2
-rw-r--r--container/std/syscall_linux_arm64.go (renamed from container/seccomp/syscall_linux_arm64.go)2
-rw-r--r--container/std/syscall_test.go21
15 files changed, 51 insertions, 29 deletions
diff --git a/container/landlock.go b/container/landlock.go
index 7f7461e2..63d03817 100644
--- a/container/landlock.go
+++ b/container/landlock.go
@@ -5,7 +5,7 @@ import (
"syscall"
"unsafe"
- "hakurei.app/container/seccomp"
+ "hakurei.app/container/std"
)
// include/uapi/linux/landlock.h
@@ -212,7 +212,7 @@ func (rulesetAttr *RulesetAttr) Create(flags uintptr) (fd int, err error) {
size = unsafe.Sizeof(*rulesetAttr)
}
- rulesetFd, _, errno := syscall.Syscall(seccomp.SYS_LANDLOCK_CREATE_RULESET, pointer, size, flags)
+ rulesetFd, _, errno := syscall.Syscall(std.SYS_LANDLOCK_CREATE_RULESET, pointer, size, flags)
fd = int(rulesetFd)
err = errno
@@ -231,7 +231,7 @@ func LandlockGetABI() (int, error) {
}
func LandlockRestrictSelf(rulesetFd int, flags uintptr) error {
- r, _, errno := syscall.Syscall(seccomp.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
}
diff --git a/container/seccomp/libseccomp.go b/container/seccomp/libseccomp.go
index 2044a668..c408b7b3 100644
--- a/container/seccomp/libseccomp.go
+++ b/container/seccomp/libseccomp.go
@@ -227,9 +227,10 @@ const (
// syscallResolveName resolves a syscall number by name via seccomp_syscall_resolve_name.
// This function is only for testing the lookup tables and included here for convenience.
-func syscallResolveName(s string) (trap int) {
+func syscallResolveName(s string) (trap int, ok bool) {
v := C.CString(s)
trap = int(C.seccomp_syscall_resolve_name(v))
C.free(unsafe.Pointer(v))
+ ok = trap != C.__NR_SCMP_ERROR
return
}
diff --git a/container/seccomp/presets.go b/container/seccomp/presets.go
index 8e9eaeb6..f16bc82c 100644
--- a/container/seccomp/presets.go
+++ b/container/seccomp/presets.go
@@ -5,32 +5,32 @@ package seccomp
import (
. "syscall"
- "hakurei.app/container/std"
+ . "hakurei.app/container/std"
)
-func Preset(presets std.FilterPreset, flags ExportFlag) (rules []NativeRule) {
+func Preset(presets FilterPreset, flags ExportFlag) (rules []NativeRule) {
allowedPersonality := PersonaLinux
- if presets&std.PresetLinux32 != 0 {
+ if presets&PresetLinux32 != 0 {
allowedPersonality = PersonaLinux32
}
presetDevelFinal := presetDevel(ScmpDatum(allowedPersonality))
l := len(presetCommon)
- if presets&std.PresetDenyNS != 0 {
+ if presets&PresetDenyNS != 0 {
l += len(presetNamespace)
}
- if presets&std.PresetDenyTTY != 0 {
+ if presets&PresetDenyTTY != 0 {
l += len(presetTTY)
}
- if presets&std.PresetDenyDevel != 0 {
+ if presets&PresetDenyDevel != 0 {
l += len(presetDevelFinal)
}
if flags&AllowMultiarch == 0 {
l += len(presetEmu)
}
- if presets&std.PresetExt != 0 {
+ if presets&PresetExt != 0 {
l += len(presetCommonExt)
- if presets&std.PresetDenyNS != 0 {
+ if presets&PresetDenyNS != 0 {
l += len(presetNamespaceExt)
}
if flags&AllowMultiarch == 0 {
@@ -40,21 +40,21 @@ func Preset(presets std.FilterPreset, flags ExportFlag) (rules []NativeRule) {
rules = make([]NativeRule, 0, l)
rules = append(rules, presetCommon...)
- if presets&std.PresetDenyNS != 0 {
+ if presets&PresetDenyNS != 0 {
rules = append(rules, presetNamespace...)
}
- if presets&std.PresetDenyTTY != 0 {
+ if presets&PresetDenyTTY != 0 {
rules = append(rules, presetTTY...)
}
- if presets&std.PresetDenyDevel != 0 {
+ if presets&PresetDenyDevel != 0 {
rules = append(rules, presetDevelFinal...)
}
if flags&AllowMultiarch == 0 {
rules = append(rules, presetEmu...)
}
- if presets&std.PresetExt != 0 {
+ if presets&PresetExt != 0 {
rules = append(rules, presetCommonExt...)
- if presets&std.PresetDenyNS != 0 {
+ if presets&PresetDenyNS != 0 {
rules = append(rules, presetNamespaceExt...)
}
if flags&AllowMultiarch == 0 {
diff --git a/container/seccomp/hash_amd64_test.go b/container/seccomp/presets_amd64_test.go
index c021772c..c021772c 100644
--- a/container/seccomp/hash_amd64_test.go
+++ b/container/seccomp/presets_amd64_test.go
diff --git a/container/seccomp/hash_arm64_test.go b/container/seccomp/presets_arm64_test.go
index a445d3b7..a445d3b7 100644
--- a/container/seccomp/hash_arm64_test.go
+++ b/container/seccomp/presets_arm64_test.go
diff --git a/container/seccomp/hash_test.go b/container/seccomp/presets_test.go
index b86d49ba..b86d49ba 100644
--- a/container/seccomp/hash_test.go
+++ b/container/seccomp/presets_test.go
diff --git a/container/seccomp/syscall_test.go b/container/seccomp/syscall_test.go
index e385a12c..57a73265 100644
--- a/container/seccomp/syscall_test.go
+++ b/container/seccomp/syscall_test.go
@@ -2,21 +2,21 @@ package seccomp
import (
"testing"
+
+ "hakurei.app/container/std"
)
func TestSyscallResolveName(t *testing.T) {
t.Parallel()
- for name, want := range Syscalls() {
+ for name, want := range std.Syscalls() {
t.Run(name, func(t *testing.T) {
t.Parallel()
- if got := syscallResolveName(name); got != want {
+ // this checks the std implementation against libseccomp.
+ if got, ok := syscallResolveName(name); !ok || got != want {
t.Errorf("syscallResolveName(%q) = %d, want %d", name, got, want)
}
- if got, ok := SyscallResolveName(name); !ok || got != want {
- t.Errorf("SyscallResolveName(%q) = %d, want %d", name, got, want)
- }
})
}
}
diff --git a/container/seccomp/mksysnum_linux.pl b/container/std/mksysnum_linux.pl
index 2dbd12fd..0dee69d8 100755
--- a/container/seccomp/mksysnum_linux.pl
+++ b/container/std/mksysnum_linux.pl
@@ -17,7 +17,7 @@ print <<EOF;
// $command
// Code generated by the command above; DO NOT EDIT.
-package seccomp
+package std
import . "syscall"
diff --git a/container/seccomp/pnr.go b/container/std/pnr.go
index 4cc7398b..1fa20ec0 100644
--- a/container/seccomp/pnr.go
+++ b/container/std/pnr.go
@@ -1,6 +1,6 @@
// Code generated from include/seccomp-syscalls.h; DO NOT EDIT.
-package seccomp
+package std
/*
* pseudo syscall definitions
diff --git a/container/seccomp/syscall.go b/container/std/syscall.go
index 36a988aa..ff8d396e 100644
--- a/container/seccomp/syscall.go
+++ b/container/std/syscall.go
@@ -1,4 +1,4 @@
-package seccomp
+package std
import "iter"
diff --git a/container/seccomp/syscall_extra_linux_amd64.go b/container/std/syscall_extra_linux_amd64.go
index 8b789890..5f8d4837 100644
--- a/container/seccomp/syscall_extra_linux_amd64.go
+++ b/container/std/syscall_extra_linux_amd64.go
@@ -1,4 +1,4 @@
-package seccomp
+package std
var syscallNumExtra = map[string]int{
"umount": SYS_UMOUNT,
diff --git a/container/seccomp/syscall_extra_linux_arm64.go b/container/std/syscall_extra_linux_arm64.go
index 62d8ff19..d21af8ea 100644
--- a/container/seccomp/syscall_extra_linux_arm64.go
+++ b/container/std/syscall_extra_linux_arm64.go
@@ -1,4 +1,4 @@
-package seccomp
+package std
import "syscall"
diff --git a/container/seccomp/syscall_linux_amd64.go b/container/std/syscall_linux_amd64.go
index 28dbcb47..183c99f6 100644
--- a/container/seccomp/syscall_linux_amd64.go
+++ b/container/std/syscall_linux_amd64.go
@@ -1,7 +1,7 @@
// mksysnum_linux.pl /usr/include/asm/unistd_64.h
// Code generated by the command above; DO NOT EDIT.
-package seccomp
+package std
import . "syscall"
diff --git a/container/seccomp/syscall_linux_arm64.go b/container/std/syscall_linux_arm64.go
index 9790ad6a..223da39c 100644
--- a/container/seccomp/syscall_linux_arm64.go
+++ b/container/std/syscall_linux_arm64.go
@@ -1,7 +1,7 @@
// mksysnum_linux.pl /usr/include/asm/unistd_64.h
// Code generated by the command above; DO NOT EDIT.
-package seccomp
+package std
import . "syscall"
diff --git a/container/std/syscall_test.go b/container/std/syscall_test.go
new file mode 100644
index 00000000..b82cc46a
--- /dev/null
+++ b/container/std/syscall_test.go
@@ -0,0 +1,21 @@
+package std_test
+
+import (
+ "testing"
+
+ "hakurei.app/container/std"
+)
+
+func TestSyscallResolveName(t *testing.T) {
+ t.Parallel()
+
+ for name, want := range std.Syscalls() {
+ t.Run(name, func(t *testing.T) {
+ t.Parallel()
+
+ if got, ok := std.SyscallResolveName(name); !ok || got != want {
+ t.Errorf("SyscallResolveName(%q) = %d, want %d", name, got, want)
+ }
+ })
+ }
+}