How to use isSupportedMount method of host Package

Best Syzkaller code snippet using host.isSupportedMount

syscalls_linux.go

Source:syscalls_linux.go Github

copy

Full Screen

...32 if strings.HasPrefix(c.Name, "openat$") {33 return isSupportedOpenAt(c)34 }35 if strings.HasPrefix(c.Name, "mount$") {36 return isSupportedMount(c, sandbox)37 }38 if c.Name == "ioctl$EXT4_IOC_SHUTDOWN" && sandbox == "none" {39 // Don't shutdown root filesystem.40 return false, "unsafe with sandbox=none"41 }42 // There are 3 possible strategies for detecting supported syscalls:43 // 1. Executes all syscalls with presumably invalid arguments and check for ENOprog.44 // But not all syscalls are safe to execute. For example, pause will hang,45 // while setpgrp will push the process into own process group.46 // 2. Check presence of /sys/kernel/debug/tracing/events/syscalls/sys_enter_* files.47 // This requires root and CONFIG_FTRACE_SYSCALLS. Also it lies for some syscalls.48 // For example, on x86_64 it says that sendfile is not present (only sendfile64).49 // 3. Check sys_syscallname in /proc/kallsyms.50 // Requires CONFIG_KALLSYMS.51 // Kallsyms seems to be the most reliable and fast. That's what we use first.52 // If kallsyms is not present, we fallback to execution of syscalls.53 kallsymsOnce.Do(func() {54 kallsyms, _ := ioutil.ReadFile("/proc/kallsyms")55 if len(kallsyms) == 0 {56 return57 }58 kallsymsSyscallSet = parseKallsyms(kallsyms, target.Arch)59 })60 if !testFallback && len(kallsymsSyscallSet) != 0 {61 r, v := isSupportedKallsyms(c)62 return r, v63 }64 return isSupportedTrial(c)65}66func parseKallsyms(kallsyms []byte, arch string) map[string]bool {67 set := make(map[string]bool)68 var re *regexp.Regexp69 switch arch {70 case "386", "amd64":71 re = regexp.MustCompile(` T (__ia32_|__x64_)?sys_([^\n]+)\n`)72 case "arm", "arm64":73 re = regexp.MustCompile(` T (__arm64_)?sys_([^\n]+)\n`)74 case "ppc64le":75 re = regexp.MustCompile(` T ()?sys_([^\n]+)\n`)76 case "mips64le":77 re = regexp.MustCompile(` T sys_(mips_)?([^\n]+)\n`)78 default:79 panic("unsupported arch for kallsyms parsing")80 }81 matches := re.FindAllSubmatch(kallsyms, -1)82 for _, m := range matches {83 name := string(m[2])84 log.Logf(2, "found in kallsyms: %v", name)85 set[name] = true86 }87 return set88}89func isSupportedKallsyms(c *prog.Syscall) (bool, string) {90 name := c.CallName91 if newname := kallsymsRenameMap[name]; newname != "" {92 name = newname93 }94 if !kallsymsSyscallSet[name] {95 return false, fmt.Sprintf("sys_%v is not present in /proc/kallsyms", name)96 }97 return true, ""98}99func isSupportedTrial(c *prog.Syscall) (bool, string) {100 switch c.CallName {101 // These known to cause hangs.102 case "exit", "pause":103 return true, ""104 }105 trialMu.Lock()106 defer trialMu.Unlock()107 if res, ok := trialSupported[c.NR]; ok {108 return res, "ENOSYS"109 }110 cmd := osutil.Command(os.Args[0])111 cmd.Env = []string{fmt.Sprintf("SYZ_TRIAL_TEST=%v", c.NR)}112 _, err := osutil.Run(10*time.Second, cmd)113 res := err != nil114 trialSupported[c.NR] = res115 return res, "ENOSYS"116}117func init() {118 str := os.Getenv("SYZ_TRIAL_TEST")119 if str == "" {120 return121 }122 nr, err := strconv.Atoi(str)123 if err != nil {124 panic(err)125 }126 arg := ^uintptr(0) - 1e4 // something as invalid as possible127 _, _, err = syscall.Syscall6(uintptr(nr), arg, arg, arg, arg, arg, arg)128 if err == syscall.ENOSYS {129 os.Exit(0)130 }131 os.Exit(1)132}133// Some syscall names diverge in __NR_* consts and kallsyms.134// umount2 is renamed to umount in arch/x86/entry/syscalls/syscall_64.tbl.135// Where umount is renamed to oldumount is unclear.136var (137 kallsymsOnce sync.Once138 kallsymsSyscallSet map[string]bool139 kallsymsRenameMap = map[string]string{140 "umount": "oldumount",141 "umount2": "umount",142 "stat": "newstat",143 }144 trialMu sync.Mutex145 trialSupported = make(map[uint64]bool)146 filesystems []byte147 filesystemsOnce sync.Once148 lsmOnce sync.Once149 lsmError error150 lsmDisabled map[string]bool151)152// The function is lengthy as it handles all pseudo-syscalls,153// but it does not seem to cause comprehension problems as there is no shared state.154// Splitting this per-syscall will only increase code size.155func isSupportedSyzkall(sandbox string, c *prog.Syscall) (bool, string) {156 switch c.CallName {157 case "syz_open_dev":158 return isSupportedSyzOpenDev(sandbox, c)159 case "syz_open_procfs":160 return true, ""161 case "syz_open_pts":162 return true, ""163 case "syz_emit_ethernet", "syz_extract_tcp_res":164 reason := checkNetInjection()165 return reason == "", reason166 case "syz_usb_connect", "syz_usb_connect_ath9k", "syz_usb_disconnect",167 "syz_usb_control_io", "syz_usb_ep_write", "syz_usb_ep_read":168 reason := checkUSBEmulation()169 return reason == "", reason170 case "syz_kvm_setup_cpu":171 switch c.Name {172 case "syz_kvm_setup_cpu$x86":173 if runtime.GOARCH == "amd64" || runtime.GOARCH == "386" {174 return true, ""175 }176 case "syz_kvm_setup_cpu$arm64":177 if runtime.GOARCH == "arm64" {178 return true, ""179 }180 }181 return false, "unsupported arch"182 case "syz_init_net_socket":183 // Unfortunately this only works with sandbox none at the moment.184 // The problem is that setns of a network namespace requires CAP_SYS_ADMIN185 // in the target namespace, and we've lost all privs in the init namespace186 // during creation of a user namespace.187 if ok, reason := onlySandboxNone(sandbox); !ok {188 return false, reason189 }190 return isSupportedSocket(c)191 case "syz_genetlink_get_family_id":192 fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_GENERIC)193 if fd == -1 {194 return false, fmt.Sprintf("socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC) failed: %v", err)195 }196 syscall.Close(fd)197 return true, ""198 case "syz_mount_image":199 if ok, reason := onlySandboxNone(sandbox); !ok {200 return ok, reason201 }202 fstype, ok := extractStringConst(c.Args[0].Type)203 if !ok {204 panic("syz_mount_image arg is not string")205 }206 return isSupportedFilesystem(fstype)207 case "syz_read_part_table":208 return onlySandboxNone(sandbox)209 case "syz_execute_func":210 return true, ""211 }212 panic("unknown syzkall: " + c.Name)213}214func isSupportedSyzOpenDev(sandbox string, c *prog.Syscall) (bool, string) {215 if _, ok := c.Args[0].Type.(*prog.ConstType); ok {216 // This is for syz_open_dev$char/block.217 return true, ""218 }219 fname, ok := extractStringConst(c.Args[0].Type)220 if !ok {221 panic("first open arg is not a pointer to string const")222 }223 if !strings.Contains(fname, "#") {224 panic(fmt.Sprintf("%v does not contain # in the file name (should be openat)", c.Name))225 }226 if checkUSBEmulation() == "" {227 // These entries might not be available at boot time,228 // but will be created by connected USB devices.229 USBDevicePrefixes := []string{230 "/dev/hidraw", "/dev/usb/hiddev", "/dev/input/",231 }232 for _, prefix := range USBDevicePrefixes {233 if strings.HasPrefix(fname, prefix) {234 return true, ""235 }236 }237 }238 var check func(dev string) bool239 check = func(dev string) bool {240 if !strings.Contains(dev, "#") {241 // Note: don't try to open them all, some can hang (e.g. /dev/snd/pcmC#D#p).242 return osutil.IsExist(dev)243 }244 for i := 0; i < 10; i++ {245 if check(strings.Replace(dev, "#", strconv.Itoa(i), 1)) {246 return true247 }248 }249 return false250 }251 if !check(fname) {252 return false, fmt.Sprintf("file %v does not exist", fname)253 }254 return onlySandboxNoneOrNamespace(sandbox)255}256func isSupportedLSM(c *prog.Syscall) string {257 lsmOnce.Do(func() {258 data, err := ioutil.ReadFile("/sys/kernel/security/lsm")259 if err != nil {260 // securityfs may not be mounted, but it does not mean261 // that no LSMs are enabled.262 if !os.IsNotExist(err) {263 lsmError = err264 }265 return266 }267 lsmDisabled = make(map[string]bool)268 for _, lsm := range []string{"selinux", "apparmor", "smack"} {269 if !strings.Contains(string(data), lsm) {270 lsmDisabled[lsm] = true271 }272 }273 })274 if lsmError != nil {275 return lsmError.Error()276 }277 for lsm := range lsmDisabled {278 if strings.Contains(strings.ToLower(c.Name), lsm) {279 return fmt.Sprintf("LSM %v is not enabled", lsm)280 }281 }282 return ""283}284func onlySandboxNone(sandbox string) (bool, string) {285 if syscall.Getuid() != 0 || sandbox != "none" {286 return false, "only supported under root with sandbox=none"287 }288 return true, ""289}290func onlySandboxNoneOrNamespace(sandbox string) (bool, string) {291 if syscall.Getuid() != 0 || sandbox == "setuid" {292 return false, "only supported under root with sandbox=none/namespace"293 }294 return true, ""295}296func isSupportedSocket(c *prog.Syscall) (bool, string) {297 af, ok := c.Args[0].Type.(*prog.ConstType)298 if !ok {299 panic("socket family is not const")300 }301 fd, err := syscall.Socket(int(af.Val), 0, 0)302 if fd != -1 {303 syscall.Close(fd)304 }305 if err == syscall.ENOSYS {306 return false, "socket syscall returns ENOSYS"307 }308 if err == syscall.EAFNOSUPPORT {309 return false, "socket family is not supported (EAFNOSUPPORT)"310 }311 proto, ok := c.Args[2].Type.(*prog.ConstType)312 if !ok {313 return true, ""314 }315 var typ uint64316 if arg, ok := c.Args[1].Type.(*prog.ConstType); ok {317 typ = arg.Val318 } else if arg, ok := c.Args[1].Type.(*prog.FlagsType); ok {319 typ = arg.Vals[0]320 } else {321 return true, ""322 }323 fd, err = syscall.Socket(int(af.Val), int(typ), int(proto.Val))324 if fd != -1 {325 syscall.Close(fd)326 return true, ""327 }328 return false, err.Error()329}330func isSupportedOpenAt(c *prog.Syscall) (bool, string) {331 var fd int332 var err error333 fname, ok := extractStringConst(c.Args[1].Type)334 if !ok || len(fname) == 0 || fname[0] != '/' {335 return true, ""336 }337 modes := []int{syscall.O_RDONLY, syscall.O_WRONLY, syscall.O_RDWR}338 // Attempt to extract flags from the syscall description339 if mode, ok := c.Args[2].Type.(*prog.ConstType); ok {340 modes = []int{int(mode.Val)}341 }342 for _, mode := range modes {343 fd, err = syscall.Open(fname, mode, 0)344 if fd != -1 {345 syscall.Close(fd)346 }347 if err == nil {348 return true, ""349 }350 }351 return false, fmt.Sprintf("open(%v) failed: %v", fname, err)352}353func isSupportedMount(c *prog.Syscall, sandbox string) (bool, string) {354 fstype, ok := extractStringConst(c.Args[2].Type)355 if !ok {356 panic(fmt.Sprintf("%v: filesystem is not string const", c.Name))357 }358 if ok, reason := isSupportedFilesystem(fstype); !ok {359 return ok, reason360 }361 switch fstype {362 case "fuse", "fuseblk":363 if err := osutil.IsAccessible("/dev/fuse"); err != nil {364 return false, err.Error()365 }366 return onlySandboxNoneOrNamespace(sandbox)367 default:...

Full Screen

Full Screen

isSupportedMount

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithCancel(context.Background())4 defer cancel()5 u, err := url.Parse(os.Args[1])6 if err != nil {7 log.Fatal(err)8 }9 u.User = url.UserPassword(os.Args[2], os.Args[3])10 c, err := govmomi.NewClient(ctx, u, true)11 if err != nil {12 log.Fatal(err)13 }14 f := find.NewFinder(c.Client, true)15 dc, err := f.DefaultDatacenter(ctx)16 if err != nil {17 log.Fatal(err)18 }19 f.SetDatacenter(dc)20 host, err := f.DefaultHostSystem(ctx)21 if err != nil {22 log.Fatal(err)23 }24 err = host.Properties(ctx, host.Reference(), []string{"configManager.storageSystem"}, &h)25 if err != nil {26 log.Fatal(err)27 }28 storageSystem := object.NewStorageResourceManager(c.Client)29 storageSystem := object.NewStorageResourceManager(c.Client)30 mountInfo, err := storageSystem.QueryStorageArrayType(ctx, h.ConfigManager.StorageSystem.Reference())31 if err != nil {32 log.Fatal(err)33 }34 mountInfo, err := storageSystem.QueryStorageArrayType(ctx, h.ConfigManager.StorageSystem.Reference())35 if err != nil {36 log.Fatal(err)37 }38 for _, mount := range mountInfo {39 fmt.Printf("Mount: %s40 fmt.Printf("Mount: %s

Full Screen

Full Screen

isSupportedMount

Using AI Code Generation

copy

Full Screen

1func (h *host) isSupportedMount(mountType string) bool {2 for _, t := range h.SupportedMounts {3 if t == mountType {4 }5 }6}7func (h *host) isSupportedMount(mountType string) bool {8 for _, t := range h.SupportedMounts {9 if t == mountType {10 }11 }12}13func (h *host) isSupportedMount(mountType string) bool {14 for _, t := range h.SupportedMounts {15 if t == mountType {16 }17 }18}19func (h *host) isSupportedMount(mountType string) bool {20 for _, t := range h.SupportedMounts {21 if t == mountType {22 }23 }24}25func (h *host) isSupportedMount(mountType string) bool {26 for _, t := range h.SupportedMounts {27 if t == mountType {28 }29 }30}31func (h *host) isSupportedMount(mountType string) bool {32 for _, t := range h.SupportedMounts {33 if t == mountType {34 }35 }36}37func (h *host) isSupportedMount(mountType string) bool {38 for _, t := range h.SupportedMounts {39 if t == mountType {40 }41 }42}43func (h *host) isSupportedMount(mountType string) bool {44 for _, t := range h.SupportedMounts {

Full Screen

Full Screen

isSupportedMount

Using AI Code Generation

copy

Full Screen

1func main() {2 host := new(Host)3 host.isSupportedMount()4}5func (h *Host) isSupportedMount() {6 fmt.Println("isSupportedMount method of host class")7}8func main() {9 host := new(Host)10 host.isSupportedMount()11}12func (h *Host) isSupportedMount() {13 fmt.Println("isSupportedMount method of host class")14}15import (16func main() {17 http.HandleFunc("/", handler)18 log.Fatal(http.ListenAndServe(":8080", nil))19}20func handler(w http.ResponseWriter, r *http.Request) {21 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))22}23I have imported the html package in the code. I am using go version go1.9.2 linux/amd64

Full Screen

Full Screen

isSupportedMount

Using AI Code Generation

copy

Full Screen

1func main() {2 if err != nil {3 log.Fatal(err)4 }5 defer host.CloseConnection()6 supported, err := host.IsSupportedMount()7 if err != nil {8 log.Fatal(err)9 }10 if !supported {11 log.Fatal("mount is not supported")12 }13 domain, err := host.DomainDefineXML(diskXML)14 if err != nil {15 log.Fatal(err)16 }17 defer domain.Free()18 mountPoint, err := host.MountStoragePool("default", 0)19 if err != nil {20 log.Fatal(err)21 }22 defer mountPoint.Free()23 err = domain.AttachDeviceFlags(diskXML, libvirt.DOMAIN_DEVICE_MODIFY_CONFIG)24 if err != nil {25 log.Fatal(err)26 }27 err = domain.DetachDeviceFlags(diskXML, libvirt.DOMAIN_DEVICE_MODIFY_CONFIG)28 if err != nil {29 log.Fatal(err)30 }31}

Full Screen

Full Screen

isSupportedMount

Using AI Code Generation

copy

Full Screen

1func isSupportedMount(hostVolume string) bool {2 if hostVolume != "" {3 if _, err := os.Stat(hostVolume); err == nil {4 }5 }6}7func isSupportedMount(hostVolume string) bool {8 if hostVolume != "" {9 if _, err := os.Stat(hostVolume); err == nil {10 }11 }12}13func isSupportedMount(hostVolume string) bool {14 if hostVolume != "" {15 if _, err := os.Stat(hostVolume); err == nil {16 }17 }18}19func isSupportedMount(hostVolume string) bool {20 if hostVolume != "" {21 if _, err := os.Stat(hostVolume); err == nil {22 }23 }24}25func isSupportedMount(hostVolume string) bool {26 if hostVolume != "" {27 if _, err := os.Stat(hostVolume); err == nil {28 }29 }30}31func isSupportedMount(hostVolume string) bool {32 if hostVolume != "" {33 if _, err := os.Stat(hostVolume); err == nil {34 }35 }36}37func isSupportedMount(hostVolume string) bool {38 if hostVolume != "" {39 if _, err := os.Stat(hostVolume); err == nil {40 }41 }42}43func isSupportedMount(hostVolume string) bool {44 if hostVolume != "" {45 if _, err := os.Stat(hostVolume); err == nil {46 }47 }48}49func isSupportedMount(hostVolume string) bool {50 if hostVolume != "" {

Full Screen

Full Screen

isSupportedMount

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 host := os.Host()4 supported := host.isSupportedMount(mountPoint)5 fmt.Printf("Is the mount point %s supported? %v", mountPoint, supported)6}

Full Screen

Full Screen

isSupportedMount

Using AI Code Generation

copy

Full Screen

1if !host.IsSupportedMount() {2log.Errorf("Mounting of %s is not supported on this host", mnt.Source)3return nil, fmt.Errorf("Mounting of %s is not supported on this host", mnt.Source)4}5if !host.IsSupportedMount() {6log.Errorf("Mounting of %s is not supported on this host", mnt.Source)7return nil, fmt.Errorf("Mounting of %s is not supported on this host", mnt.Source)8}9if !host.IsSupportedMount() {10log.Errorf("Mounting of %s is not supported on this host", mnt.Source)11return nil, fmt.Errorf("Mounting of %s is not supported on this host", mnt.Source)12}13if !host.IsSupportedMount() {14log.Errorf("Mounting of %s is not supported on this host", mnt.Source)15return nil, fmt.Errorf("Mounting of %s is not supported on this host", mnt.Source)16}17if !host.IsSupportedMount() {18log.Errorf("Mounting of %s is not supported on this host", mnt.Source)19return nil, fmt.Errorf("Mounting of %s is not supported on this host", mnt.Source)20}21if !host.IsSupportedMount() {22log.Errorf("Mounting of %s is not supported on this host", mnt.Source)23return nil, fmt.Errorf("Mounting of %s is not supported on this host", mnt.Source)24}25if !host.IsSupportedMount() {26log.Errorf("Mounting of %s is not supported on this host", mnt.Source)27return nil, fmt.Errorf("Mounting of %s is not supported on this host", mnt.Source)28}29if !host.IsSupportedMount() {30log.Errorf("Mounting of %

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