How to use checkVhciInjection method of host Package

Best Syzkaller code snippet using host.checkVhciInjection

features_linux.go

Source:features_linux.go Github

copy

Full Screen

...23 checkFeature[FeatureNetDevices] = unconditionallyEnabled24 checkFeature[FeatureKCSAN] = checkKCSAN25 checkFeature[FeatureDevlinkPCI] = checkDevlinkPCI26 checkFeature[FeatureUSBEmulation] = checkUSBEmulation27 checkFeature[FeatureVhciInjection] = checkVhciInjection28}29func checkCoverage() string {30 if reason := checkDebugFS(); reason != "" {31 return reason32 }33 if !osutil.IsExist("/sys/kernel/debug/kcov") {34 return "CONFIG_KCOV is not enabled"35 }36 if err := osutil.IsAccessible("/sys/kernel/debug/kcov"); err != nil {37 return err.Error()38 }39 return ""40}41func checkComparisons() (reason string) {42 return checkCoverageFeature(FeatureComparisons)43}44func checkExtraCoverage() (reason string) {45 return checkCoverageFeature(FeatureExtraCoverage)46}47func checkCoverageFeature(feature int) (reason string) {48 if reason = checkDebugFS(); reason != "" {49 return reason50 }51 // TODO(dvyukov): this should run under target arch.52 // E.g. KCOV ioctls were initially not supported on 386 (missing compat_ioctl),53 // and a 386 executor won't be able to use them, but an amd64 fuzzer will be.54 fd, err := syscall.Open("/sys/kernel/debug/kcov", syscall.O_RDWR, 0)55 if err != nil {56 return "CONFIG_KCOV is not enabled"57 }58 defer syscall.Close(fd)59 // Trigger host target lazy initialization, it will fill linux.KCOV_INIT_TRACE.60 // It's all wrong and needs to be refactored.61 if _, err := prog.GetTarget(runtime.GOOS, runtime.GOARCH); err != nil {62 return fmt.Sprintf("failed to get target: %v", err)63 }64 coverSize := uintptr(64 << 10)65 _, _, errno := syscall.Syscall(66 syscall.SYS_IOCTL, uintptr(fd), linux.KCOV_INIT_TRACE, coverSize)67 if errno != 0 {68 return fmt.Sprintf("ioctl(KCOV_INIT_TRACE) failed: %v", errno)69 }70 mem, err := syscall.Mmap(fd, 0, int(coverSize*unsafe.Sizeof(uintptr(0))),71 syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)72 if err != nil {73 return fmt.Sprintf("KCOV mmap failed: %v", err)74 }75 defer func() {76 if err := syscall.Munmap(mem); err != nil {77 reason = fmt.Sprintf("munmap failed: %v", err)78 }79 }()80 switch feature {81 case FeatureComparisons:82 _, _, errno = syscall.Syscall(syscall.SYS_IOCTL,83 uintptr(fd), linux.KCOV_ENABLE, linux.KCOV_TRACE_CMP)84 if errno != 0 {85 if errno == 524 { // ENOTSUPP86 return "CONFIG_KCOV_ENABLE_COMPARISONS is not enabled"87 }88 return fmt.Sprintf("ioctl(KCOV_TRACE_CMP) failed: %v", errno)89 }90 case FeatureExtraCoverage:91 arg := KcovRemoteArg{92 TraceMode: uint32(linux.KCOV_TRACE_PC),93 AreaSize: uint32(coverSize * unsafe.Sizeof(uintptr(0))),94 NumHandles: 0,95 CommonHandle: 0,96 }97 _, _, errno = syscall.Syscall(syscall.SYS_IOCTL,98 uintptr(fd), linux.KCOV_REMOTE_ENABLE, uintptr(unsafe.Pointer(&arg)))99 if errno != 0 {100 if errno == 25 { // ENOTTY101 return "extra coverage is not supported by the kernel"102 }103 return fmt.Sprintf("ioctl(KCOV_REMOTE_ENABLE) failed: %v", errno)104 }105 default:106 panic("unknown feature in checkCoverageFeature")107 }108 defer func() {109 _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), linux.KCOV_DISABLE, 0)110 if errno != 0 {111 reason = fmt.Sprintf("ioctl(KCOV_DISABLE) failed: %v", errno)112 }113 }()114 return ""115}116type KcovRemoteArg struct {117 TraceMode uint32118 AreaSize uint32119 NumHandles uint32120 CommonHandle uint64121 // Handles []uint64 goes here.122}123func checkFault() string {124 if err := osutil.IsAccessible("/proc/self/make-it-fail"); err != nil {125 return "CONFIG_FAULT_INJECTION is not enabled"126 }127 if err := osutil.IsAccessible("/proc/thread-self/fail-nth"); err != nil {128 return "kernel does not have systematic fault injection support"129 }130 if reason := checkDebugFS(); reason != "" {131 return reason132 }133 if err := osutil.IsAccessible("/sys/kernel/debug/failslab/ignore-gfp-wait"); err != nil {134 return "CONFIG_FAULT_INJECTION_DEBUG_FS or CONFIG_FAILSLAB are not enabled"135 }136 return ""137}138func checkLeak() string {139 if reason := checkDebugFS(); reason != "" {140 return reason141 }142 fd, err := syscall.Open("/sys/kernel/debug/kmemleak", syscall.O_RDWR, 0)143 if err != nil {144 return "CONFIG_DEBUG_KMEMLEAK is not enabled"145 }146 defer syscall.Close(fd)147 if _, err := syscall.Write(fd, []byte("scan=off")); err != nil {148 if err == syscall.EBUSY {149 return "KMEMLEAK disabled: increase CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE or unset CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF"150 }151 return fmt.Sprintf("/sys/kernel/debug/kmemleak write failed: %v", err)152 }153 return ""154}155func checkSandboxNamespace() string {156 if err := osutil.IsAccessible("/proc/self/ns/user"); err != nil {157 return err.Error()158 }159 return ""160}161func checkSandboxAndroid() string {162 if err := osutil.IsAccessible("/sys/fs/selinux/policy"); err != nil {163 return err.Error()164 }165 return ""166}167func checkNetInjection() string {168 if err := osutil.IsAccessible("/dev/net/tun"); err != nil {169 return err.Error()170 }171 return ""172}173func checkUSBEmulation() string {174 if err := osutil.IsAccessible("/dev/raw-gadget"); err != nil {175 return err.Error()176 }177 return ""178}179func checkVhciInjection() string {180 if err := osutil.IsAccessible("/dev/vhci"); err != nil {181 return err.Error()182 }183 return ""184}185func checkDebugFS() string {186 if err := osutil.IsAccessible("/sys/kernel/debug"); err != nil {187 return "debugfs is not enabled or not mounted"188 }189 return ""190}191func checkKCSAN() string {192 if err := osutil.IsAccessible("/sys/kernel/debug/kcsan"); err != nil {193 return err.Error()...

Full Screen

Full Screen

checkVhciInjection

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 u, err := soap.ParseURL(os.Args[1])4 if err != nil {5 log.Fatal(err)6 }7 u.User = url.UserPassword(os.Args[2], os.Args[3])8 c, err := govmomi.NewClient(u, true)9 if err != nil {10 log.Fatal(err)11 }12 f := find.NewFinder(c.Client, true)13 dc, err := f.DefaultDatacenter()14 if err != nil {15 log.Fatal(err)16 }17 f.SetDatacenter(dc)18 f = find.NewFinder(c.Client, true)19 dc, err = f.DefaultDatacenter()20 if err != nil {21 log.Fatal(err)22 }23 f.SetDatacenter(dc)24 vm, err := f.VirtualMachine(c.Context, os.Args[4])25 if err != nil {26 log.Fatal(err)27 }28 hs, err := vm.HostSystem(c.Context)29 if err != nil {30 log.Fatal(err)31 }32 err = hs.Properties(c.Context, hs.Reference(), []string{"hardware"}, &hw)33 if err != nil {34 log.Fatal(err)35 }36 err = hs.Properties(c.Context, hs.NetworkSystem(c.Context), []string{"networkInfo.vnic"}, &n)37 if err != nil {38 log.Fatal(err)39 }40 fmt.Println("VM: ", vm.Name(), " is running on host: ",

Full Screen

Full Screen

checkVhciInjection

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Println(err)5 os.Exit(1)6 }7 ctx := context.Background()8 c, err := govmomi.NewClient(ctx, u, true)9 if err != nil {10 fmt.Println(err)11 os.Exit(1)12 }13 f := find.NewFinder(c.Client, true)14 dc, err := f.DefaultDatacenter(ctx)15 if err != nil {16 fmt.Println(err)17 os.Exit(1)18 }19 f.SetDatacenter(dc)20 hosts, err := f.HostSystemList(ctx, "*")21 if err != nil {22 fmt.Println(err)23 os.Exit(1)24 }25 for _, host := range hosts {26 if host.Summary.Runtime.ConnectionState == "connected" {27 if host.Summary.Runtime.InMaintenanceMode == false {28 if host.Parent.Type == "ClusterComputeResource" {29 if strings.Contains(host.Parent.Value, "domain-c") {30 if strings.Contains(host.Parent.Value, "domain-c") {31 if strings.Contains(host.Parent.Value, "domain-c") {32 if strings.Contains(host.Parent.Value, "domain-c") {33 if strings.Contains(host.Parent.Value, "domain-c") {34 if strings.Contains(host.Parent.Value, "domain-c") {35 if strings.Contains(host.Parent.Value, "domain-c") {36 if strings.Contains(host.Parent.Value, "domain-c") {

Full Screen

Full Screen

checkVhciInjection

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 c, err := govmomi.NewClient(context.Background(), u, true)7 if err != nil {8 log.Fatal(err)9 }10 f := find.NewFinder(c.Client, true)11 dc, err := f.DefaultDatacenter(context.Background())12 if err != nil {13 log.Fatal(err)14 }15 f.SetDatacenter(dc)16 vms, err := f.VirtualMachineList(context.Background(), "*")17 if err != nil {18 log.Fatal(err)19 }20 if len(vms) == 0 {21 log.Fatal("Virtual machine not found")22 }23 fmt.Printf("Using VM: %s24 err = vm.Properties(context.Background(), vm.Reference(), []string{"runtime.host"}, &hostSystem)25 if err != nil {26 log.Fatal(err)27 }28 hostRef := types.ManagedObjectReference{29 }30 host, err := f.ObjectReference(context.Background(), hostRef)31 if err != nil {32 log.Fatal(err)33 }34 err = host.Properties(context.Background(), host.Reference(), []string{"name"}, &hostName)35 if err != nil {36 log.Fatal(err)37 }38 fmt.Printf("Using host: %s39 hostSystemObj := host.(*govmomi.HostSystem)

Full Screen

Full Screen

checkVhciInjection

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithCancel(context.Background())4 defer cancel()5 c, err := govmomi.NewClient(ctx, os.Args[1], true)6 if err != nil {7 fmt.Println(err)8 }9 finder := find.NewFinder(c.Client, true)10 dc, err := finder.Datacenter(ctx, os.Args[2])11 if err != nil {12 fmt.Println(err)13 }14 finder.SetDatacenter(dc)15 host, err := finder.HostSystem(ctx, os.Args[3])16 if err != nil {17 fmt.Println(err)18 }19 hostConfig, err := host.Config(ctx)20 if err != nil {21 fmt.Println(err)22 }23 hostNetworkSystem := hostConfigManagerNetworkSystem.(*types.HostNetworkSystem)24 hostVSwitchSpec := types.HostVirtualSwitchSpec{25 }26 hostVSwitchSpecPolicy := types.HostNetworkPolicy{27 NicTeaming: &types.HostNicTeamingPolicy{28 ReversePolicy: &types.BoolPolicy{29 },30 NotifySwitches: &types.BoolPolicy{31 },32 Failback: &types.BoolPolicy{33 },34 FailoverOrder: &types.HostNicOrderPolicy{

Full Screen

Full Screen

checkVhciInjection

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithCancel(context.Background())4 defer cancel()5 var (6 if len(os.Args) != 2 {7 log.Fatal("Usage: govc host.checkVhciInjection [host]")8 }9 u, err = soap.ParseURL(os.Args[1])10 if err != nil {11 log.Fatal(err)12 }13 u.User = url.UserPassword("administrator", "VMware1!")14 c, err := govmomi.NewClient(ctx, u, insecure)15 if err != nil {16 log.Fatal(err)17 }18 f := find.NewFinder(c.Client, true)19 host, err := f.DefaultHostSystem(ctx)20 if err != nil {21 log.Fatal(err)22 }23 hostSystem := host.Reference()24 res, err := host.CheckVhciInjection(ctx, hostSystem1)25 if err != nil {26 fmt.Println(err)27 }28 fmt.Println(strings.Join(res, "29}

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