From 8aa587b0a13ba3f8e19b359b1e254cdf94a8b7ff Mon Sep 17 00:00:00 2001 From: Joey Jiao Date: Sat, 19 Jan 2019 19:30:10 +0800 Subject: sys/syz-extract: add -includedirs option Kernel modules are in different directories in some cases, so to include the headers in the module dir or other directories the includedirs flag is added. ex: -includedirs path1/include,path2/include --- sys/syz-extract/akaros.go | 6 ++++++ sys/syz-extract/extract.go | 27 +++++++++++++++------------ sys/syz-extract/freebsd.go | 5 +++++ sys/syz-extract/linux.go | 5 +++++ sys/syz-extract/netbsd.go | 5 +++++ sys/syz-extract/openbsd.go | 5 +++++ sys/syz-extract/trusty.go | 6 ++++++ 7 files changed, 47 insertions(+), 12 deletions(-) diff --git a/sys/syz-extract/akaros.go b/sys/syz-extract/akaros.go index e9a2dd3af..ecd609458 100644 --- a/sys/syz-extract/akaros.go +++ b/sys/syz-extract/akaros.go @@ -6,6 +6,7 @@ package main import ( "fmt" "path/filepath" + "strings" "github.com/google/syzkaller/pkg/compiler" ) @@ -35,5 +36,10 @@ func (*akaros) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uin for _, incdir := range info.Incdirs { args = append(args, "-I"+filepath.Join(dir, incdir)) } + if arch.includeDirs != "" { + for _, dir := range strings.Split(arch.includeDirs, ",") { + args = append(args, "-I"+dir) + } + } return extract(info, "gcc", args, "", true) } diff --git a/sys/syz-extract/extract.go b/sys/syz-extract/extract.go index fc63f7384..20346aeac 100644 --- a/sys/syz-extract/extract.go +++ b/sys/syz-extract/extract.go @@ -24,18 +24,20 @@ var ( flagOS = flag.String("os", "", "target OS") flagBuild = flag.Bool("build", false, "regenerate arch-specific kernel headers") flagSourceDir = flag.String("sourcedir", "", "path to kernel source checkout dir") + flagIncludes = flag.String("includedirs", "", "path to other kernel source include dirs separated by commas") flagBuildDir = flag.String("builddir", "", "path to kernel build dir") flagArch = flag.String("arch", "", "comma-separated list of arches to generate (all by default)") ) type Arch struct { - target *targets.Target - sourceDir string - buildDir string - build bool - files []*File - err error - done chan bool + target *targets.Target + sourceDir string + includeDirs string + buildDir string + build bool + files []*File + err error + done chan bool } type File struct { @@ -176,11 +178,12 @@ func createArches(OS string, archArray, files []string) ([]*Arch, error) { } arch := &Arch{ - target: target, - sourceDir: *flagSourceDir, - buildDir: buildDir, - build: *flagBuild, - done: make(chan bool), + target: target, + sourceDir: *flagSourceDir, + includeDirs: *flagIncludes, + buildDir: buildDir, + build: *flagBuild, + done: make(chan bool), } for _, f := range files { arch.files = append(arch.files, &File{ diff --git a/sys/syz-extract/freebsd.go b/sys/syz-extract/freebsd.go index b72ebeb8e..3dd495408 100644 --- a/sys/syz-extract/freebsd.go +++ b/sys/syz-extract/freebsd.go @@ -50,6 +50,11 @@ func (*freebsd) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]ui for _, incdir := range info.Incdirs { args = append(args, "-I"+filepath.Join(arch.sourceDir, incdir)) } + if arch.includeDirs != "" { + for _, dir := range strings.Split(arch.includeDirs, ",") { + args = append(args, "-I"+dir) + } + } // Syscall consts on freebsd have weird prefixes sometimes, // try to extract consts with these prefixes as well. compatNames := make(map[string][]string) diff --git a/sys/syz-extract/linux.go b/sys/syz-extract/linux.go index c5786a87d..5135ccb3d 100644 --- a/sys/syz-extract/linux.go +++ b/sys/syz-extract/linux.go @@ -123,6 +123,11 @@ func (*linux) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint for _, incdir := range info.Incdirs { args = append(args, "-I"+sourceDir+"/"+incdir) } + if arch.includeDirs != "" { + for _, dir := range strings.Split(arch.includeDirs, ",") { + args = append(args, "-I"+dir) + } + } const addSource = ` #include unsigned long phys_base; diff --git a/sys/syz-extract/netbsd.go b/sys/syz-extract/netbsd.go index d0059f836..878a63584 100644 --- a/sys/syz-extract/netbsd.go +++ b/sys/syz-extract/netbsd.go @@ -67,6 +67,11 @@ func (*netbsd) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uin for _, incdir := range info.Incdirs { args = append(args, "-I"+filepath.Join(arch.sourceDir, incdir)) } + if arch.includeDirs != "" { + for _, dir := range strings.Split(arch.includeDirs, ",") { + args = append(args, "-I"+dir) + } + } // Syscall consts on netbsd have weird prefixes sometimes, // try to extract consts with these prefixes as well. compatNames := make(map[string][]string) diff --git a/sys/syz-extract/openbsd.go b/sys/syz-extract/openbsd.go index b09c31e15..c01012a23 100644 --- a/sys/syz-extract/openbsd.go +++ b/sys/syz-extract/openbsd.go @@ -52,6 +52,11 @@ func (*openbsd) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]ui for _, incdir := range info.Incdirs { args = append(args, "-I"+filepath.Join(arch.sourceDir, incdir)) } + if arch.includeDirs != "" { + for _, dir := range strings.Split(arch.includeDirs, ",") { + args = append(args, "-I"+dir) + } + } // Syscall consts on openbsd have weird prefixes sometimes, // try to extract consts with these prefixes as well. compatNames := make(map[string][]string) diff --git a/sys/syz-extract/trusty.go b/sys/syz-extract/trusty.go index 325925c14..71a38a968 100644 --- a/sys/syz-extract/trusty.go +++ b/sys/syz-extract/trusty.go @@ -6,6 +6,7 @@ package main import ( "fmt" "path/filepath" + "strings" "github.com/google/syzkaller/pkg/compiler" ) @@ -33,5 +34,10 @@ func (*trusty) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uin for _, incdir := range info.Incdirs { args = append(args, "-I"+filepath.Join(dir, incdir)) } + if arch.includeDirs != "" { + for _, dir := range strings.Split(arch.includeDirs, ",") { + args = append(args, "-I"+dir) + } + } return extract(info, "gcc", args, "", true) } -- cgit mrf-deployment