Skip to content

Commit

Permalink
Merge pull request #4863 from oasisprotocol/yawning/stable/22.1.x/bac…
Browse files Browse the repository at this point in the history
…kport-4862

go/runtime/host/sandbox/process: Handle missing clone3
  • Loading branch information
Yawning authored Jul 25, 2022
2 parents 87dc2e5 + a9ecc35 commit 099e5bf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .changelog/4861.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/runtime/host/sandbox/process: Handle missing clone3

This should fix seccomp filter generation failures on systems with
ancient kernel/userland pairs (RHEL8 and variants).
2 changes: 1 addition & 1 deletion go/common/dynlib/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func LoadCache() (*Cache, error) {
func loadCacheGlibc() (*Cache, error) {
const entrySz = 4 + 4 + 4 + 4 + 8

ourOsVersion, err := getOsVersion()
ourOsVersion, err := GetOsVersion()
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions go/common/dynlib/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func TestCache(t *testing.T) {

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

v, err := GetOsVersion()
if err == nil {
t.Logf("OS version: %02x", v)
}

impls := []struct {
name string
ctor ctorFn
Expand Down
3 changes: 2 additions & 1 deletion go/common/dynlib/hwcap_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import (
"syscall"
)

func getOsVersion() (uint32, error) {
// GetOsVersion returns the operating system version (major, minor, pl).
func GetOsVersion() (uint32, error) {
var buf syscall.Utsname
err := syscall.Uname(&buf)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/common/dynlib/hwcap_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

package dynlib

func getOsVersion() (uint32, error) {
func GetOsVersion() (uint32, error) {
return 0, errUnsupported
}
20 changes: 18 additions & 2 deletions go/runtime/host/sandbox/process/seccomp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"syscall"

seccomp "github.com/seccomp/libseccomp-golang"

"github.com/oasisprotocol/oasis-core/go/common/dynlib"
)

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

// Handle clone3 if the kernel is new enough to support it.
osVersion, err := dynlib.GetOsVersion()
if err != nil {
return err
}
if osVersion >= 0o50300 { // "The clone3() system call first appeared in Linux 5.3.""
if err = handleClone3(filter); err != nil {
return err
}
}

return filter.ExportBPF(out)
}

func handleClone3(filter *seccomp.ScmpFilter) error {
// We need to handle the clone3 syscall in a special manner as there are several complications
// to its handling:
//
Expand All @@ -373,6 +390,5 @@ func generateSeccompPolicy(out *os.File) error {
if err != nil {
return err
}

return filter.ExportBPF(out)
return nil
}

0 comments on commit 099e5bf

Please sign in to comment.