How to use runInstanceInner method of main Package

Best Syzkaller code snippet using main.runInstanceInner

manager.go

Source:manager.go Github

copy

Full Screen

...365 idx := instances[last]366 instances = instances[:last]367 log.Logf(1, "loop: starting instance %v", idx)368 go func() {369 //调用mgr.runInstanceInner,370 //mgr.runInstanceInner()调用了FuzzerCmd()启动fuzz;371 //又调用MonitorExecution()监控信息并返回Report对象372 //返回crash信息373 crash, err := mgr.runInstance(idx)374 //结果处理375 runDone <- &RunResult{idx, crash, err}376 }()377 }378 }379 var stopRequest chan bool380 if !stopPending && canRepro() {381 stopRequest = mgr.vmStop382 }383 wait:384 select {385 case idx := <-bootInstance:386 instances = append(instances, idx)387 case stopRequest <- true:388 log.Logf(1, "loop: issued stop request")389 stopPending = true390 case res := <-runDone:391 log.Logf(1, "loop: instance %v finished, crash=%v", res.idx, res.crash != nil)392 if res.err != nil && shutdown != nil {393 log.Logf(0, "%v", res.err)394 }395 stopPending = false396 instances = append(instances, res.idx)397 // On shutdown qemu crashes with "qemu: terminating on signal 2",398 // which we detect as "lost connection". Don't save that as crash.399 if shutdown != nil && res.crash != nil {400 needRepro := mgr.saveCrash(res.crash)401 if needRepro {402 log.Logf(1, "loop: add pending repro for '%v'", res.crash.Title)403 pendingRepro[res.crash] = true404 }405 }406 case res := <-reproDone:407 atomic.AddUint32(&mgr.numReproducing, ^uint32(0))408 crepro := false409 title := ""410 if res.res != nil {411 crepro = res.res.CRepro412 title = res.res.Report.Title413 }414 log.Logf(1, "loop: repro on %+v finished '%v', repro=%v crepro=%v desc='%v'",415 res.instances, res.report0.Title, res.res != nil, crepro, title)416 if res.err != nil {417 log.Logf(0, "repro failed: %v", res.err)418 }419 delete(reproducing, res.report0.Title)420 instances = append(instances, res.instances...)421 reproInstances -= instancesPerRepro422 if res.res == nil {423 if !res.hub {424 mgr.saveFailedRepro(res.report0, res.stats)425 }426 } else {427 mgr.saveRepro(res.res, res.stats, res.hub)428 }429 case <-shutdown:430 log.Logf(1, "loop: shutting down...")431 shutdown = nil432 case crash := <-mgr.hubReproQueue:433 log.Logf(1, "loop: get repro from hub")434 pendingRepro[crash] = true435 case reply := <-mgr.needMoreRepros:436 reply <- phase >= phaseTriagedHub &&437 len(reproQueue)+len(pendingRepro)+len(reproducing) == 0438 goto wait439 case reply := <-mgr.reproRequest:440 repros := make(map[string]bool)441 for title := range reproducing {442 repros[title] = true443 }444 reply <- repros445 goto wait446 }447 }448}449func (mgr *Manager) preloadCorpus() {450 log.Logf(0, "loading corpus...")451 corpusDB, err := db.Open(filepath.Join(mgr.cfg.Workdir, "corpus.db"))452 if err != nil {453 log.Fatalf("failed to open corpus database: %v", err)454 }455 mgr.corpusDB = corpusDB456 if seedDir := filepath.Join(mgr.cfg.Syzkaller, "sys", mgr.cfg.TargetOS, "test"); osutil.IsExist(seedDir) {457 seeds, err := ioutil.ReadDir(seedDir)458 if err != nil {459 log.Fatalf("failed to read seeds dir: %v", err)460 }461 for _, seed := range seeds {462 data, err := ioutil.ReadFile(filepath.Join(seedDir, seed.Name()))463 if err != nil {464 log.Fatalf("failed to read seed %v: %v", seed.Name(), err)465 }466 mgr.seeds = append(mgr.seeds, data)467 }468 }469}470func (mgr *Manager) loadCorpus() {471 // By default we don't re-minimize/re-smash programs from corpus,472 // it takes lots of time on start and is unnecessary.473 // However, on version bumps we can selectively re-minimize/re-smash.474 minimized, smashed := true, true475 switch mgr.corpusDB.Version {476 case 0:477 // Version 0 had broken minimization, so we need to re-minimize.478 minimized = false479 fallthrough480 case 1:481 // Version 1->2: memory is preallocated so lots of mmaps become unnecessary.482 minimized = false483 fallthrough484 case 2:485 // Version 2->3: big-endian hints.486 smashed = false487 fallthrough488 case 3:489 // Version 3->4: to shake things up.490 minimized = false491 fallthrough492 case currentDBVersion:493 }494 broken := 0495 for key, rec := range mgr.corpusDB.Records {496 if !mgr.loadProg(rec.Val, minimized, smashed) {497 mgr.corpusDB.Delete(key)498 broken++499 }500 }501 mgr.fresh = len(mgr.corpusDB.Records) == 0502 corpusSize := len(mgr.candidates)503 log.Logf(0, "%-24v: %v (deleted %v broken)", "corpus", corpusSize, broken)504 for _, seed := range mgr.seeds {505 mgr.loadProg(seed, true, false)506 }507 log.Logf(0, "%-24v: %v/%v", "seeds", len(mgr.candidates)-corpusSize, len(mgr.seeds))508 mgr.seeds = nil509 // We duplicate all inputs in the corpus and shuffle the second part.510 // This solves the following problem. A fuzzer can crash while triaging candidates,511 // in such case it will also lost all cached candidates. Or, the input can be somewhat flaky512 // and doesn't give the coverage on first try. So we give each input the second chance.513 // Shuffling should alleviate deterministically losing the same inputs on fuzzer crashing.514 mgr.candidates = append(mgr.candidates, mgr.candidates...)515 shuffle := mgr.candidates[len(mgr.candidates)/2:]516 rand.Shuffle(len(shuffle), func(i, j int) {517 shuffle[i], shuffle[j] = shuffle[j], shuffle[i]518 })519 if mgr.phase != phaseInit {520 panic(fmt.Sprintf("loadCorpus: bad phase %v", mgr.phase))521 }522 mgr.phase = phaseLoadedCorpus523}524func (mgr *Manager) loadProg(data []byte, minimized, smashed bool) bool {525 bad, disabled := checkProgram(mgr.target, mgr.targetEnabledSyscalls, data)526 if bad {527 return false528 }529 if disabled {530 // This program contains a disabled syscall.531 // We won't execute it, but remember its hash so532 // it is not deleted during minimization.533 // 这个程序包含了disabled系统调用,我们不会执行它,但是记住它的哈希值保证最小化过程中不会删除它。534 mgr.disabledHashes[hash.String(data)] = struct{}{}535 return true536 }537 mgr.candidates = append(mgr.candidates, rpctype.RPCCandidate{538 Prog: data,539 Minimized: minimized,540 Smashed: smashed,541 })542 return true543}544func checkProgram(target *prog.Target, enabled map[*prog.Syscall]bool, data []byte) (bad, disabled bool) {545 p, err := target.Deserialize(data, prog.NonStrict)546 if err != nil {547 return true, true548 }549 if len(p.Calls) > prog.MaxCalls {550 return true, true551 }552 for _, c := range p.Calls {553 if !enabled[c.Meta] {554 return false, true555 }556 }557 return false, false558}559//讲syz-fuzzer和syz-executor复制到VM中,调用FuzzerCmd函数通过ssh执行syz-fuzzer。560func (mgr *Manager) runInstance(index int) (*Crash, error) {561 mgr.checkUsedFiles()562 instanceName := fmt.Sprintf("vm-%d", index)563 // 运行虚拟机564 rep, vmInfo, err := mgr.runInstanceInner(index, instanceName)565 //关闭虚拟机566 machineInfo := mgr.serv.shutdownInstance(instanceName)567 if len(vmInfo) != 0 {568 machineInfo = append(append(vmInfo, '\n'), machineInfo...)569 }570 // Error that is not a VM crash.571 if err != nil {572 return nil, err573 }574 // No crash.575 if rep == nil {576 return nil, nil577 }578 crash := &Crash{579 vmIndex: index,580 hub: false,581 Report: rep,582 machineInfo: machineInfo,583 }584 return crash, nil585}586func (mgr *Manager) runInstanceInner(index int, instanceName string) (*report.Report, []byte, error) {587 // 创建588 inst, err := mgr.vmPool.Create(index)589 if err != nil {590 return nil, nil, fmt.Errorf("failed to create instance: %v", err)591 }592 defer inst.Close()593 // forward594 fwdAddr, err := inst.Forward(mgr.serv.port)595 if err != nil {596 return nil, nil, fmt.Errorf("failed to setup port forwarding: %v", err)597 }598 // 复制fuzzer二进制文件599 fuzzerBin, err := inst.Copy(mgr.cfg.FuzzerBin)600 if err != nil {...

Full Screen

Full Screen

runInstanceInner

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 svc := ec2.New(session.New(), &aws.Config{Region: aws.String("us-west-2")})4 resp, err := svc.DescribeInstances(nil)5 if err != nil {6 fmt.Println("Error", err)7 } else {8 fmt.Println("Success", resp)9 }10}11import (12func main() {13 svc := ec2.New(session.New(), &aws.Config{Region: aws.String("us-west-2")})14 resp, err := svc.DescribeInstances(nil)15 if err != nil {16 fmt.Println("Error", err)17 } else {18 fmt.Println("Success", resp)19 }20}21import (22func main() {23 svc := ec2.New(session.New(), &aws.Config{Region: aws.String("us-west-2")})

Full Screen

Full Screen

runInstanceInner

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World!")4}5import (6func main() {7 fmt.Println("Hello World!")8}9import (10func main() {11 fmt.Println("Hello World!")12}13import (14func main() {15 fmt.Println("Hello World!")16}17import (18func main() {19 fmt.Println("Hello World!")20}21import (22func main() {23 fmt.Println("Hello World!")24}25import (26func main() {27 fmt.Println("Hello World!")28}29import (30func main() {31 fmt.Println("Hello World!")32}33import (34func main() {35 fmt.Println("Hello World!")36}37import (38func main() {39 fmt.Println("Hello World!")40}41import (42func main() {43 fmt.Println("Hello World!")44}45import (46func main() {47 fmt.Println("Hello World!")48}49import (50func main() {51 fmt.Println("Hello World!")52}

Full Screen

Full Screen

runInstanceInner

Using AI Code Generation

copy

Full Screen

1import (2func main() {3}4func runInstanceInner() {5 ctx := context.Background()6 vmConfigSpec := types.VirtualMachineConfigSpec{7 Files: &types.VirtualMachineFileInfo{8 VmPathName: fmt.Sprintf("[%s]", datastore.Name()),9 },10 DeviceChange: []types.BaseVirtualDeviceConfigSpec{11 &types.VirtualDeviceConfigSpec{12 Device: &types.ParaVirtualSCSIController{13 VirtualSCSIController: types.VirtualSCSIController{14 VirtualController: types.VirtualController{15 VirtualDevice: types.VirtualDevice{16 },17 },18 },19 },20 },21 },22 }23 hostConfigSpec := types.VirtualMachineRelocateSpec{24 Host: host.Reference(),25 Pool: resourcePool.Reference(),26 }

Full Screen

Full Screen

runInstanceInner

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 runInstanceInner()5}6import "fmt"7func main() {8 fmt.Println("Hello, playground")9 runInstance()10}11import "fmt"12func main() {13 fmt.Println("Hello, playground")14 run()15}

Full Screen

Full Screen

runInstanceInner

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 runInstanceInner()5}6import "fmt"7func main() {8 fmt.Println("Hello, playground")9 runInstance()10}11import "fmt"12func main() {13 fmt.Println("Hello, playground")14 runInstance()15}16Your name to display (optional):17Your name to display (optional):18Your name to display (optional):19Your name to display (optional):20Your name to display (optional):21Your name to display (optional):22Your name to display (optional):23Your name to display (optional):

Full Screen

Full Screen

runInstanceInner

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World!")4 runInstanceInner()5}6import (7func main() {8 fmt.Println("Hello World!")9 runInstance()10}11import (12func main() {13 fmt.Println("Hello World!")14 runInstance()15}16import (17func main() {18 fmt.Println("Hello World!")19 RunInstanceInner()20}

Full Screen

Full Screen

runInstanceInner

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var m = &main{}4 var method = reflect.ValueOf(m).MethodByName("runInstanceInner")5 var args = []reflect.Value{6 reflect.ValueOf("Hello, World!"),7 }8 method.Call(args)9}10import (11func main() {12 var m = &main{}13 var method = reflect.ValueOf(m).MethodByName("runInstanceInner")14 var args = []reflect.Value{15 reflect.ValueOf("Hello, World!"),16 }17 method.Call(args)18}19import (20func main() {21 var m = &main{}22 var method = reflect.ValueOf(m).MethodByName("runInstanceInner")23 var args = []reflect.Value{24 reflect.ValueOf("Hello, World!"),25 }26 method.Call(args)27}28import (29func main() {30 var m = &main{}31 var method = reflect.ValueOf(m).MethodByName("runInstanceInner")32 var args = []reflect.Value{33 reflect.ValueOf("Hello, World!"),34 }35 method.Call(args)36}37import (38func main() {39 var m = &main{}40 var method = reflect.ValueOf(m).MethodByName("runInstanceInner")41 var args = []reflect.Value{42 reflect.ValueOf("Hello, World!"),43 }44 method.Call(args)45}46import (47func main() {48 var m = &main{}49 var method = reflect.ValueOf(m).MethodByName("runInstanceInner")

Full Screen

Full Screen

runInstanceInner

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 for i < 10 {5 go runInstanceInner()6 }7 time.Sleep(10 * time.Second)8}9func runInstanceInner() {10 fmt.Println("Hello World Inner")11}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful