Skip to content

Commit 099e5bf

Browse files
authored
Merge pull request #4863 from oasisprotocol/yawning/stable/22.1.x/backport-4862
go/runtime/host/sandbox/process: Handle missing clone3
2 parents 87dc2e5 + a9ecc35 commit 099e5bf

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

.changelog/4861.bugfix.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
go/runtime/host/sandbox/process: Handle missing clone3
2+
3+
This should fix seccomp filter generation failures on systems with
4+
ancient kernel/userland pairs (RHEL8 and variants).

go/common/dynlib/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func LoadCache() (*Cache, error) {
336336
func loadCacheGlibc() (*Cache, error) {
337337
const entrySz = 4 + 4 + 4 + 4 + 8
338338

339-
ourOsVersion, err := getOsVersion()
339+
ourOsVersion, err := GetOsVersion()
340340
if err != nil {
341341
return nil, err
342342
}

go/common/dynlib/cache_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ func TestCache(t *testing.T) {
4040

4141
t.Logf("Test binary: %+v", fn)
4242

43+
v, err := GetOsVersion()
44+
if err == nil {
45+
t.Logf("OS version: %02x", v)
46+
}
47+
4348
impls := []struct {
4449
name string
4550
ctor ctorFn

go/common/dynlib/hwcap_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import (
3737
"syscall"
3838
)
3939

40-
func getOsVersion() (uint32, error) {
40+
// GetOsVersion returns the operating system version (major, minor, pl).
41+
func GetOsVersion() (uint32, error) {
4142
var buf syscall.Utsname
4243
err := syscall.Uname(&buf)
4344
if err != nil {

go/common/dynlib/hwcap_other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424

2525
package dynlib
2626

27-
func getOsVersion() (uint32, error) {
27+
func GetOsVersion() (uint32, error) {
2828
return 0, errUnsupported
2929
}

go/runtime/host/sandbox/process/seccomp_linux.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"syscall"
99

1010
seccomp "github.com/seccomp/libseccomp-golang"
11+
12+
"github.com/oasisprotocol/oasis-core/go/common/dynlib"
1113
)
1214

1315
// A list of syscalls allowed with any arguments.
@@ -355,6 +357,21 @@ func generateSeccompPolicy(out *os.File) error {
355357
return err
356358
}
357359

360+
// Handle clone3 if the kernel is new enough to support it.
361+
osVersion, err := dynlib.GetOsVersion()
362+
if err != nil {
363+
return err
364+
}
365+
if osVersion >= 0o50300 { // "The clone3() system call first appeared in Linux 5.3.""
366+
if err = handleClone3(filter); err != nil {
367+
return err
368+
}
369+
}
370+
371+
return filter.ExportBPF(out)
372+
}
373+
374+
func handleClone3(filter *seccomp.ScmpFilter) error {
358375
// We need to handle the clone3 syscall in a special manner as there are several complications
359376
// to its handling:
360377
//
@@ -373,6 +390,5 @@ func generateSeccompPolicy(out *os.File) error {
373390
if err != nil {
374391
return err
375392
}
376-
377-
return filter.ExportBPF(out)
393+
return nil
378394
}

0 commit comments

Comments
 (0)