Skip to content
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
30 changes: 15 additions & 15 deletions analyzer/opcode/opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,29 @@ func (op *opcode) Analyze(path string, withTrace bool) ([]*analyzer.Issue, error
for _, segment := range callGraph.Segments() {
for _, instruction := range segment.Instructions() {
if !op.isAllowedOpcode(instruction.OpcodeHex(), instruction.Funct()) {
source, err := common.TraceAsmCaller(absPath, callGraph, segment.Label(), endCondition)
source, err := common.TraceAsmCaller(
absPath,
callGraph,
segment.Label(),
common.ProgramEntrypoint(op.profile.GOARCH),
)
if err != nil { // non-reachable portion ignored
continue
}
if common.ShouldIgnoreSource(source, op.profile.IgnoredFunctions) {
continue
}
if !withTrace {
source.CallStack = nil
}
issues = append(issues, &analyzer.Issue{

issue := &analyzer.Issue{
Severity: analyzer.IssueSeverityCritical,
CallStack: source,
Message: fmt.Sprintf("Incompatible Opcode Detected: Opcode: %s, Funct: %s",
Message: fmt.Sprintf("Potential Incompatible Opcode Detected: Opcode: %s, Funct: %s",
instruction.OpcodeHex(), instruction.Funct()),
})
}
if common.ShouldIgnoreSource(source, op.profile.IgnoredFunctions) {
issue.Severity = analyzer.IssueSeverityWarning
}
issues = append(issues, issue)
}
}
}
Expand Down Expand Up @@ -87,7 +94,7 @@ func (op *opcode) TraceStack(path string, function string) (*analyzer.CallStack,
if err != nil {
return nil, err
}
return common.TraceAsmCaller(absPath, graph, function, endCondition)
return common.TraceAsmCaller(absPath, graph, function, common.ProgramEntrypoint(op.profile.GOARCH))
}
func (op *opcode) isAllowedOpcode(opcode, funct string) bool {
return slices.ContainsFunc(op.profile.AllowedOpcodes, func(instr profile.OpcodeInstruction) bool {
Expand All @@ -102,10 +109,3 @@ func (op *opcode) isAllowedOpcode(opcode, funct string) bool {
})
})
}

func endCondition(function string) bool {
return function == "runtime.rt0_go" || // start point of a go program
function == "main.main" || // main
strings.Contains(function, ".init.") || // all init functions
strings.HasSuffix(function, ".init") // vars
}
24 changes: 10 additions & 14 deletions analyzer/syscall/asm_syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"path/filepath"
"slices"
"strings"

"github.com/ChainSafe/vm-compat/analyzer"
"github.com/ChainSafe/vm-compat/asmparser"
Expand Down Expand Up @@ -59,19 +58,23 @@ func (a *asmSyscallAnalyser) Analyze(path string, withTrace bool) ([]*analyzer.I
if slices.Contains(a.profile.AllowedSycalls, syscall.Number) {
continue
}
source, err := common.TraceAsmCaller(absPath, callGraph, syscall.Segment.Label(), endCondition)
source, err := common.TraceAsmCaller(
absPath,
callGraph,
syscall.Segment.Label(),
common.ProgramEntrypoint(a.profile.GOARCH),
)
if err != nil { // non-reachable portion ignored
continue
}
if common.ShouldIgnoreSource(source, a.profile.IgnoredFunctions) {
continue
}

if !withTrace {
source.CallStack = nil
}

severity := analyzer.IssueSeverityCritical
if common.ShouldIgnoreSource(source, a.profile.IgnoredFunctions) {
severity = analyzer.IssueSeverityWarning
}
message := fmt.Sprintf("Potential Incompatible Syscall Detected: %d", syscall.Number)
if slices.Contains(a.profile.NOOPSyscalls, syscall.Number) {
message = fmt.Sprintf("Potential NOOP Syscall Detected: %d", syscall.Number)
Expand Down Expand Up @@ -121,12 +124,5 @@ func (a *asmSyscallAnalyser) TraceStack(path string, function string) (*analyzer
if err != nil {
return nil, err
}
return common.TraceAsmCaller(absPath, graph, function, endCondition)
}

func endCondition(function string) bool {
return function == "runtime.rt0_go" || // start point of a go program
function == "main.main" || // main
strings.Contains(function, ".init.") || // all init functions
strings.HasSuffix(function, ".init") // vars
return common.TraceAsmCaller(absPath, graph, function, common.ProgramEntrypoint(a.profile.GOARCH))
}
31 changes: 31 additions & 0 deletions common/entrypoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package common

import "strings"

func ProgramEntrypoint(arch string) func(function string) bool {
switch arch {
case "mips":
return func(function string) bool {
// Ignoring rt0_go directly as it contains unreachable portion
return function == "runtime.check" ||
function == "runtime.args" ||
function == "runtime.osinit" ||
function == "runtime.schedinit" ||
function == "runtime.newproc" ||
function == "runtime.mstart" ||
function == "main.main" || // main
strings.Contains(function, ".init.") || // all init functions
strings.HasSuffix(function, ".init") // vars
}
case "mips64":
return func(function string) bool {
return function == "runtime.rt0_go" || // start point of a go program
function == "main.main" || // main
strings.Contains(function, ".init.") || // all init functions
strings.HasSuffix(function, ".init") // vars
}
}
return func(function string) bool {
return false
}
}
120 changes: 0 additions & 120 deletions profile/cannon/cannon-32.yaml

This file was deleted.

11 changes: 9 additions & 2 deletions profile/cannon/cannon-multithreaded-32.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
vm: Cannon
goos: linux
goarch: mips64
goarch: mips
ignored_functions:
- 'syscall.setrlimit'
- 'runtime.morestack'
- 'runtime.abort'

- 'runtime.exitThread'
- 'runtime.sigaltstack'
- 'runtime.rtsigprocmask'
- 'runtime.munmap'
- 'runtime.exit'
allowed_opcodes:
- opcode: '0x2'
funct: []
Expand Down Expand Up @@ -157,3 +161,6 @@ noop_syscalls:
- 4261
- 4076
- 4019
- 4215
- 4213
- 4140
Loading
Loading