diff --git a/analyzer/opcode/opcode.go b/analyzer/opcode/opcode.go index 20b8abd..ba33203 100644 --- a/analyzer/opcode/opcode.go +++ b/analyzer/opcode/opcode.go @@ -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) } } } @@ -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 { @@ -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 -} diff --git a/analyzer/syscall/asm_syscall.go b/analyzer/syscall/asm_syscall.go index 7544693..430c618 100644 --- a/analyzer/syscall/asm_syscall.go +++ b/analyzer/syscall/asm_syscall.go @@ -5,7 +5,6 @@ import ( "fmt" "path/filepath" "slices" - "strings" "github.com/ChainSafe/vm-compat/analyzer" "github.com/ChainSafe/vm-compat/asmparser" @@ -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) @@ -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)) } diff --git a/common/entrypoint.go b/common/entrypoint.go new file mode 100644 index 0000000..7b462af --- /dev/null +++ b/common/entrypoint.go @@ -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 + } +} diff --git a/profile/cannon/cannon-32.yaml b/profile/cannon/cannon-32.yaml deleted file mode 100644 index 69096f6..0000000 --- a/profile/cannon/cannon-32.yaml +++ /dev/null @@ -1,120 +0,0 @@ -vm: Cannon -goos: linux -goarch: mips -ignored_functions: - - 'syscall.setrlimit' - - 'runtime.morestack' - - 'runtime.abort' - -allowed_opcodes: - - opcode: '0x2' - funct: [] - - opcode: '0x3' - funct: [] - - opcode: '0x4' - funct: [] - - opcode: '0x5' - funct: [] - - opcode: '0x6' - funct: [] - - opcode: '0x7' - funct: [] - - opcode: '0x1' - funct: [] - - opcode: '0x1a' - funct: [] - - opcode: '0x1b' - funct: [] - - opcode: '0x0' - funct: - - '0x0' - - '0x2' - - '0x3' - - '0x4' - - '0x6' - - '0x7' - - '0x8' - - '0x9' - - '0xa' - - '0xb' - - '0xc' - - '0xf' - - '0x10' - - '0x11' - - '0x12' - - '0x13' - - '0x18' - - '0x19' - - '0x1a' - - '0x1b' - - '0x20' - - '0x21' - - '0x22' - - '0x23' - - '0x24' - - '0x25' - - '0x26' - - '0x27' - - '0x2a' - - '0x2b' - - '0xa' - - '0xb' - - '0xc' - - opcode: '0x8' - funct: [] - - opcode: '0x9' - funct: [] - - opcode: '0xa' - funct: [] - - opcode: '0xb' - funct: [] - - opcode: '0xc' - funct: [] - - opcode: '0xd' - funct: [] - - opcode: '0xe' - funct: [] - - opcode: '0x1c' - funct: - - '0x2' - - '0x20' - - '0x21' - - opcode: '0xf' - funct: [] - - opcode: '0x20' - funct: [] - - opcode: '0x21' - funct: [] - - opcode: '0x22' - funct: [] - - opcode: '0x23' - funct: [] - - opcode: '0x24' - funct: [] - - opcode: '0x25' - funct: [] - - opcode: '0x26' - funct: [] - - opcode: '0x28' - funct: [] - - opcode: '0x29' - funct: [] - - opcode: '0x2a' - funct: [] - - opcode: '0x2b' - funct: [] - - opcode: '0x2e' - funct: [] - - opcode: '0x30' - funct: [] - - opcode: '0x38' - funct: [] -allowed_syscalls: - - 4090 - - 4045 - - 4120 - - 4246 - - 4003 - - 4004 - - 4055 -noop_syscalls: [] diff --git a/profile/cannon/cannon-multithreaded-32.yaml b/profile/cannon/cannon-multithreaded-32.yaml index d95d990..50bd4b3 100644 --- a/profile/cannon/cannon-multithreaded-32.yaml +++ b/profile/cannon/cannon-multithreaded-32.yaml @@ -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: [] @@ -157,3 +161,6 @@ noop_syscalls: - 4261 - 4076 - 4019 + - 4215 + - 4213 + - 4140 diff --git a/profile/cannon/cannon-64.yaml b/profile/cannon/cannon-multithreaded-64.yaml similarity index 100% rename from profile/cannon/cannon-64.yaml rename to profile/cannon/cannon-multithreaded-64.yaml diff --git a/profile/cannon/cannon-singlethreaded-32.yaml b/profile/cannon/cannon-singlethreaded-32.yaml new file mode 100644 index 0000000..09bcd34 --- /dev/null +++ b/profile/cannon/cannon-singlethreaded-32.yaml @@ -0,0 +1,481 @@ +vm: Cannon +goos: linux +goarch: mips +ignored_functions: + - 'syscall.setrlimit' + - 'runtime.morestack' + - 'runtime.abort' + - 'runtime.exitThread' + - 'runtime.sigaltstack' + - 'runtime.rtsigprocmask' + - 'runtime.munmap' + - 'runtime.exit' + - 'runtime.gcenable' + - 'runtime.init.5' + - 'runtime.main.func1' + - 'runtime.deductSweepCredit' + - 'runtime.(*gcControllerState).commit' + - 'github.com/prometheus/client_golang/prometheus.init' + - 'github.com/prometheus/client_golang/prometheus.init.0' + - 'github.com/prometheus/procfs.init' + - 'github.com/prometheus/common/model.init' + - 'github.com/prometheus/client_model/go.init' + - 'github.com/prometheus/client_model/go.init.0' + - 'github.com/prometheus/client_model/go.init.1' + - 'flag.init' + - 'runtime.check' +allowed_opcodes: + - opcode: '0x2' + funct: [] + - opcode: '0x3' + funct: [] + - opcode: '0x4' + funct: [] + - opcode: '0x5' + funct: [] + - opcode: '0x6' + funct: [] + - opcode: '0x7' + funct: [] + - opcode: '0x1' + funct: [] + - opcode: '0x1a' + funct: [] + - opcode: '0x1b' + funct: [] + - opcode: '0x0' + funct: + - '0x0' + - '0x2' + - '0x3' + - '0x4' + - '0x6' + - '0x7' + - '0x8' + - '0x9' + - '0xa' + - '0xb' + - '0xc' + - '0xf' + - '0x10' + - '0x11' + - '0x12' + - '0x13' + - '0x18' + - '0x19' + - '0x1a' + - '0x1b' + - '0x20' + - '0x21' + - '0x22' + - '0x23' + - '0x24' + - '0x25' + - '0x26' + - '0x27' + - '0x2a' + - '0x2b' + - '0xa' + - '0xb' + - '0xc' + - opcode: '0x8' + funct: [] + - opcode: '0x9' + funct: [] + - opcode: '0xa' + funct: [] + - opcode: '0xb' + funct: [] + - opcode: '0xc' + funct: [] + - opcode: '0xd' + funct: [] + - opcode: '0xe' + funct: [] + - opcode: '0x1c' + funct: + - '0x2' + - '0x20' + - '0x21' + - opcode: '0xf' + funct: [] + - opcode: '0x20' + funct: [] + - opcode: '0x21' + funct: [] + - opcode: '0x22' + funct: [] + - opcode: '0x23' + funct: [] + - opcode: '0x24' + funct: [] + - opcode: '0x25' + funct: [] + - opcode: '0x26' + funct: [] + - opcode: '0x28' + funct: [] + - opcode: '0x29' + funct: [] + - opcode: '0x2a' + funct: [] + - opcode: '0x2b' + funct: [] + - opcode: '0x2e' + funct: [] + - opcode: '0x30' + funct: [] + - opcode: '0x38' + funct: [] +allowed_syscalls: + - 4090 + - 4045 + - 4120 + - 4246 + - 4003 + - 4004 + - 4055 +noop_syscalls: + - 4000 + - 4001 + - 4002 + - 4005 + - 4006 + - 4007 + - 4008 + - 4009 + - 4010 + - 4011 + - 4012 + - 4013 + - 4014 + - 4015 + - 4016 + - 4017 + - 4018 + - 4019 + - 4020 + - 4021 + - 4022 + - 4023 + - 4024 + - 4025 + - 4026 + - 4027 + - 4028 + - 4029 + - 4030 + - 4031 + - 4032 + - 4033 + - 4034 + - 4035 + - 4036 + - 4037 + - 4038 + - 4039 + - 4040 + - 4041 + - 4042 + - 4043 + - 4044 + - 4046 + - 4047 + - 4048 + - 4049 + - 4050 + - 4051 + - 4052 + - 4053 + - 4054 + - 4056 + - 4057 + - 4058 + - 4059 + - 4060 + - 4061 + - 4062 + - 4063 + - 4064 + - 4065 + - 4066 + - 4067 + - 4068 + - 4069 + - 4070 + - 4071 + - 4072 + - 4073 + - 4074 + - 4075 + - 4076 + - 4077 + - 4078 + - 4079 + - 4080 + - 4081 + - 4082 + - 4083 + - 4084 + - 4085 + - 4086 + - 4087 + - 4088 + - 4089 + - 4091 + - 4092 + - 4093 + - 4094 + - 4095 + - 4096 + - 4097 + - 4098 + - 4099 + - 4100 + - 4101 + - 4102 + - 4103 + - 4104 + - 4105 + - 4106 + - 4107 + - 4108 + - 4109 + - 4110 + - 4111 + - 4112 + - 4113 + - 4114 + - 4115 + - 4116 + - 4117 + - 4118 + - 4119 + - 4121 + - 4122 + - 4123 + - 4124 + - 4125 + - 4126 + - 4127 + - 4128 + - 4129 + - 4130 + - 4131 + - 4132 + - 4133 + - 4134 + - 4135 + - 4136 + - 4137 + - 4138 + - 4139 + - 4140 + - 4141 + - 4142 + - 4143 + - 4144 + - 4145 + - 4146 + - 4147 + - 4148 + - 4149 + - 4150 + - 4151 + - 4152 + - 4153 + - 4154 + - 4155 + - 4156 + - 4157 + - 4158 + - 4159 + - 4160 + - 4161 + - 4162 + - 4163 + - 4164 + - 4165 + - 4166 + - 4167 + - 4168 + - 4169 + - 4170 + - 4171 + - 4172 + - 4173 + - 4174 + - 4175 + - 4176 + - 4177 + - 4178 + - 4179 + - 4180 + - 4181 + - 4182 + - 4183 + - 4184 + - 4185 + - 4186 + - 4187 + - 4188 + - 4189 + - 4190 + - 4191 + - 4192 + - 4193 + - 4194 + - 4195 + - 4196 + - 4197 + - 4198 + - 4199 + - 4200 + - 4201 + - 4202 + - 4203 + - 4204 + - 4205 + - 4206 + - 4207 + - 4208 + - 4209 + - 4210 + - 4211 + - 4212 + - 4213 + - 4214 + - 4215 + - 4216 + - 4217 + - 4218 + - 4219 + - 4220 + - 4221 + - 4222 + - 4223 + - 4224 + - 4225 + - 4226 + - 4227 + - 4228 + - 4229 + - 4230 + - 4231 + - 4232 + - 4233 + - 4234 + - 4235 + - 4236 + - 4237 + - 4238 + - 4239 + - 4240 + - 4241 + - 4242 + - 4243 + - 4244 + - 4245 + - 4247 + - 4248 + - 4249 + - 4250 + - 4251 + - 4252 + - 4253 + - 4254 + - 4255 + - 4256 + - 4257 + - 4258 + - 4259 + - 4260 + - 4261 + - 4262 + - 4263 + - 4264 + - 4265 + - 4266 + - 4267 + - 4268 + - 4269 + - 4270 + - 4271 + - 4272 + - 4273 + - 4274 + - 4275 + - 4276 + - 4277 + - 4278 + - 4280 + - 4281 + - 4282 + - 4283 + - 4284 + - 4285 + - 4286 + - 4287 + - 4288 + - 4289 + - 4290 + - 4291 + - 4292 + - 4293 + - 4294 + - 4295 + - 4296 + - 4297 + - 4298 + - 4299 + - 4300 + - 4301 + - 4302 + - 4303 + - 4304 + - 4305 + - 4306 + - 4307 + - 4308 + - 4309 + - 4310 + - 4311 + - 4312 + - 4313 + - 4314 + - 4315 + - 4316 + - 4317 + - 4318 + - 4319 + - 4320 + - 4321 + - 4322 + - 4323 + - 4324 + - 4325 + - 4326 + - 4327 + - 4328 + - 4329 + - 4330 + - 4331 + - 4332 + - 4333 + - 4334 + - 4335 + - 4336 + - 4337 + - 4338 + - 4339 + - 4340 + - 4341 + - 4342 + - 4343 + - 4344 + - 4345 + - 4346 + - 4346 + - 4346 + - 4305 + - 4310