mirror of
https://github.com/reactos/syzkaller.git
synced 2025-02-21 12:01:00 +00:00

This commits implements 4 syzcalls: syz_usb_connect, syz_usb_io_control, syz_usb_ep_write and syz_usb_disconnect. Those syzcalls are used to emit USB packets through a custom GadgetFS-like interface (currently exposed at /sys/kernel/debug/usb-fuzzer), which requires special kernel patches. USB fuzzing support is quite basic, as it mostly covers only the USB device enumeration process. Even though the syz_usb_ep_write syzcall does allow to communicate with USB endpoints after the device has been enumerated, no coverage is collected from that code yet.
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
// Copyright 2017 syzkaller project authors. All rights reserved.
|
|
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
|
|
|
// +build
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"regexp"
|
|
)
|
|
|
|
func main() {
|
|
out, err := os.Create("generated.go")
|
|
if err != nil {
|
|
failf("%v", err)
|
|
}
|
|
defer out.Close()
|
|
data, err := ioutil.ReadFile("../../executor/common.h")
|
|
if err != nil {
|
|
failf("%v", err)
|
|
}
|
|
for _, include := range []string{
|
|
"common_linux.h",
|
|
"common_akaros.h",
|
|
"common_bsd.h",
|
|
"common_fuchsia.h",
|
|
"common_windows.h",
|
|
"common_test.h",
|
|
"common_kvm_amd64.h",
|
|
"common_kvm_arm64.h",
|
|
"common_usb.h",
|
|
"kvm.h",
|
|
"kvm.S.h",
|
|
} {
|
|
contents, err := ioutil.ReadFile("../../executor/" + include)
|
|
if err != nil {
|
|
failf("%v", err)
|
|
}
|
|
replace := []byte("#include \"" + include + "\"")
|
|
if bytes.Index(data, replace) == -1 {
|
|
failf("can't fine %v include", include)
|
|
}
|
|
data = bytes.Replace(data, replace, contents, -1)
|
|
}
|
|
for _, remove := range []string{
|
|
"(\n|^)\\s*//.*",
|
|
"\\s*//.*",
|
|
} {
|
|
data = regexp.MustCompile(remove).ReplaceAll(data, nil)
|
|
}
|
|
fmt.Fprintf(out, "// AUTOGENERATED FROM executor/common.h\n\n")
|
|
fmt.Fprintf(out, "package csource\n\nvar commonHeader = `\n")
|
|
out.Write(data)
|
|
fmt.Fprintf(out, "`\n")
|
|
}
|
|
|
|
func failf(msg string, args ...interface{}) {
|
|
fmt.Fprintf(os.Stderr, msg+"\n", args...)
|
|
os.Exit(1)
|
|
}
|