Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/runtime/host/sgx: Autodetect SGX device name #4354

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/4333.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/runtime/host/sgx: Autodetect SGX device name
27 changes: 25 additions & 2 deletions go/runtime/host/sgx/sgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sync"
"time"
Expand Down Expand Up @@ -145,6 +146,23 @@ func (s *sgxProvisioner) loadEnclaveBinaries(rtCfg host.Config) ([]byte, []byte,
return sgxs, sig, nil
}

func (s *sgxProvisioner) discoverSGXDevice() (string, error) {
// Different versions of Intel SGX drivers provide different names for
// the SGX device. Autodetect which one actually exists.
sgxDevices := []string{"/dev/sgx", "/dev/sgx/enclave", "/dev/sgx_enclave", "/dev/isgx"}
for _, dev := range sgxDevices {
fi, err := os.Stat(dev)
if err != nil {
continue
}
if fi.Mode()&os.ModeDevice != 0 {
return dev, nil
}
}

return "", fmt.Errorf("no SGX device was found on this system")
}

func (s *sgxProvisioner) getSandboxConfig(rtCfg host.Config, socketPath, runtimeDir string) (process.Config, error) {
// To try to avoid bad things from happening if the signature/enclave
// binaries change out from under us, and because the enclave binary
Expand All @@ -161,6 +179,12 @@ func (s *sgxProvisioner) getSandboxConfig(rtCfg host.Config, socketPath, runtime
return process.Config{}, fmt.Errorf("host/sgx: failed to load enclave/signature: %w", err)
}

sgxDev, err := s.discoverSGXDevice()
if err != nil {
return process.Config{}, fmt.Errorf("host/sgx: %w", err)
}
s.logger.Info("found SGX device", "path", sgxDev)

return process.Config{
Path: s.cfg.LoaderPath,
Args: []string{
Expand All @@ -173,8 +197,7 @@ func (s *sgxProvisioner) getSandboxConfig(rtCfg host.Config, socketPath, runtime
aesmdSocketPath: "/var/run/aesmd/aesm.socket",
},
BindDev: map[string]string{
// TODO: Support different kinds of SGX drivers.
"/dev/isgx": "/dev/isgx",
sgxDev: sgxDev,
},
BindData: map[string]io.Reader{
runtimePath: bytes.NewReader(sgxs),
Expand Down