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

support stripped executables #282

Merged
merged 1 commit into from
Jul 16, 2024
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
9 changes: 6 additions & 3 deletions ego/cli/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,13 @@ func (c *Cli) readDataFromELF(path string, section string, offset int, size int)
// checkUnsupportedImports checks whether the to-be-signed or to-be-executed binary uses Go imports which are not supported.
func (c *Cli) checkUnsupportedImports(path string) error {
symbols, err := c.getSymbolsFromELF(path)
if err != nil {
return fmt.Errorf("getting symbols: %w", err)
if err == nil {
return checkUnsupportedImports(symbols)
}
if errors.Is(err, elf.ErrNoSymbols) {
return nil
}
return checkUnsupportedImports(symbols)
return fmt.Errorf("getting symbols: %w", err)
}

func checkUnsupportedImports(symbols []elf.Symbol) error {
Expand Down
24 changes: 12 additions & 12 deletions ego/cli/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package cli

import (
"debug/elf"
"encoding/json"
"errors"
"fmt"
Expand All @@ -31,19 +32,18 @@ var ErrNoOEInfo = errors.New("could not find .oeinfo section")
var errConfigDoesNotExist = errors.New("enclave config file not found")

func (c *Cli) signWithJSON(conf *config.Config) error {
symbols, err := c.getSymbolsFromELF(conf.Exe)
if err != nil {
return fmt.Errorf("getting symbols: %w", err)
}

// First, check if the executable does not contain unsupported imports / symbols.
if err := checkUnsupportedImports(symbols); err != nil {
return err
}
if symbols, err := c.getSymbolsFromELF(conf.Exe); err == nil {
// First, check if the executable does not contain unsupported imports / symbols.
if err := checkUnsupportedImports(symbols); err != nil {
return err
}

// Check that heapSize is in the supported range of the heap mode the binary was built with.
if err := checkHeapMode(symbols, conf.HeapSize); err != nil {
return err
// Check that heapSize is in the supported range of the heap mode the binary was built with.
if err := checkHeapMode(symbols, conf.HeapSize); err != nil {
return err
}
} else if !errors.Is(err, elf.ErrNoSymbols) {
return fmt.Errorf("getting symbols: %w", err)
}

// write temp .conf file
Expand Down
8 changes: 8 additions & 0 deletions src/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ sed -i 's/"heapSize": 511,/"heapSize": 768,/' enclave.json
run ego sign
run ego run integration-test

# Test stripped executable
cd "$egoPath/ego/cmd/integration-test"
cp enclave.json /tmp/ego-integration-test/enclave.json
run ego-go build -o /tmp/ego-integration-test/integration-test -ldflags -s
cd /tmp/ego-integration-test
run ego sign
run ego run integration-test

# Test unsupported import detection on sign & run
mkdir "$tPath/unsupported-import-test"
cd "$egoPath/ego/cmd/unsupported-import-test"
Expand Down
Loading